Comments (4)
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.
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.
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.
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 await
ed 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)
- GraphQlResponse Clonable? HOT 4
- cynic-introspection SDL is missing directives
- Fix default root handling in cynic-codegen HOT 1
- Object in array in arguments attribute fails to compile
- Catch unintentionally recursive structs at compile time HOT 8
- Fully fledged example for working with Large APIs HOT 2
- Macro with generator.cynic-rs.dev functionality HOT 7
- Vec<String> variables or arguments not being passed correctly in when I upgrade from v1.0 to cynic v3.4.3 HOT 3
- Update reqwest to 0.12 HOT 5
- reinstate cli builds as part of releases
- Deprecate & remove pre 2.0.0 argument syntax
- Put spans on things somehow HOT 1
- admonishments in the book are broken
- Dependency Dashboard
- Action Required: Fix Renovate Configuration
- How exactly to build wrapper libraries? HOT 2
- Optionally include GraphQL Query / Mutation in `querygen` output
- invalid type: integer ..., expected a string HOT 7
- Generator fails to handle a fragment
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cynic.