Giter Site home page Giter Site logo

Comments (4)

obmarg avatar obmarg commented on September 17, 2024 1

Thanks for the report @bengsparks.

This is a tricky one to solve nicely - I could add another generic param to run_graphql but forcing everyone to deal with that for this relatively niche use case isn't ideal. A separate function for users who want this would also be possible but doesn't seem great either...

I'll have a think - in the mean time I would recommend just using your own reqwest etc. integration.

from cynic.

bengsparks avatar bengsparks commented on September 17, 2024

One suggestion I have is to implement a form of delayed evaluation with a builder-esque structure?
Something that would allow for

let response = client
    // Prepare to send HTTP request to already running GraphQL server
    .get(format!("http://{}/graphql", graphql.host_with_port()))
    // Send request with `run_graphql`, WHICH DOES NOT DESERIALIZE YET!
    // Instead, store the response as e.g. `reqwest::Error<reqwest::Response>` inside of a 
    // DelayedResponse<ResponseData>, which is inferrable from the provided arguments.
    .run_graphql(FieldWithString::build(FieldWithStringVariables {
        input: "InputGoesHere",
    }))
    // Perform JSON deserialisation here upon `DelayedResponse<ResponseData>::retain_extensions<Extensions>`,
    // which contains sufficient type information to deserialise via 
    // `serde_json::from_str::<GraphQlResponse<ResponseData, Extensions>>`
    .retain_extensions::<Extension>();

But ultimately all it does it plug the fact that the *Ext::run_graphql trait methods have a hole in their APIs :/.
Nonetheless, thought I should pass this small idea on, maybe it can be used for something better.

from cynic.

obmarg avatar obmarg commented on September 17, 2024

Ooh, actually that is exactly the right answer, good thinking.

run_graphql should return a builder as you suggest, and then it can impl IntoFuture so that users can still just do run_graphql(...).await if they don't need to call retain_extensions.

I don't going to have time to implement this immediately but that sounds like the way to go.

from cynic.

bengsparks avatar bengsparks commented on September 17, 2024

Glad to hear my suggestion could be of use!

The only reason I was hesitant to propose this is because of blocking reqwest, which is likely used in non-async environments, and therefore cannot be awaited upon.

But perhaps there is a cool solution here too. Or maybe it will have to be the odd one out and require explicit usage. I imagine the majority of cynic's usages are called from async contexts anyhow :)

from cynic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.