graphql-rust / graphql-client

Typed, correct GraphQL requests and responses in Rust
Apache License 2.0
1.14k stars 155 forks source link

Question: Deserialize downloaded schema into object #404

Open kpeters-cbsi opened 2 years ago

kpeters-cbsi commented 2 years ago

I'm working on a project that will break down a single GraphQL query into a number of smaller requests suitable for caching. As part of that, I'd like to be able to work with the schema as an object, but I'm not sure how to do that. I have the introspection schema from the tests and a downloaded schema JSON, but I don't know how to marry the two.

The idea is that I would be able to do something like:

let schema = Schema("path/to/schema.json");
for type in schema.types {
   ...
}
tomhoule commented 2 years ago

Hi! I'm not sure I understand your use case completely, but it sounds more like a job for graphql-introspection-query, where you would just parse the JSON response and iterate over that. Admittedly, it's pretty low level, but it's what the JSON contains.

kpeters-cbsi commented 2 years ago

Thanks. I saw graphql-introspection-query, but I'm not clear on how to use it. Can you give me an example?

tomhoule commented 2 years ago

I'm in a meeting so I can't test to confirm this right now, but since it's Deserialize, I think something like let schema: IntrospectionResponse = serde_json::from_str(schema_json_string)? should work.`

kpeters-cbsi commented 2 years ago

OK, great. I'll try that.

On Mon, Dec 13, 2021 at 10:33 AM Tom Houlé @.***> wrote:

I'm in a meeting so I can't test to confirm this right now, but since it's Deserialize, I think something like let schema: IntrospectionResponse = serde_json::from_str(schema_json_string)? should work.` — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub , or unsubscribe . Triage notifications on the go with GitHub Mobile for iOS or Android .
kpeters-cbsi commented 2 years ago

One more question - how do I import the graphql-introspection-query crate?

tomhoule commented 2 years ago

graphql-introspection-query = "*" in your Cargo.toml dependencies, then use graphql_introspection_query::*; in your code should work.