graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Question: Deserialize downloaded schema into object

Open kpeters-cbsi opened this issue 4 years ago • 6 comments

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 {
   ...
}

kpeters-cbsi avatar Dec 10 '21 22:12 kpeters-cbsi

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.

tomhoule avatar Dec 13 '21 08:12 tomhoule

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

kpeters-cbsi avatar Dec 13 '21 16:12 kpeters-cbsi

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.`

tomhoule avatar Dec 13 '21 16:12 tomhoule

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 https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_graphql-2Drust_graphql-2Dclient_issues_404-23issuecomment-2D992656235&d=DwMCaQ&c=jGUuvAdBXp_VqQ6t0yah2g&r=TTXL98RIPQNjLdDSgeT8-yL45AVQu-9EyYWqGxjCNjqPZing27cmWboo1qWURfVf&m=Am2JDk_hD72fhW6i4mvubzmzUkUna2XA1hzuQxH9d34bABDVHbBvsJ3iSgxhOSJY&s=qWqd0E-Vh1yMy7uUkqNyC9278JxIGBaX6ks4-jsVGWo&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AMOAKPXS3RPC66MHCBQSOZLUQYN4RANCNFSM5J2F5QBQ&d=DwMCaQ&c=jGUuvAdBXp_VqQ6t0yah2g&r=TTXL98RIPQNjLdDSgeT8-yL45AVQu-9EyYWqGxjCNjqPZing27cmWboo1qWURfVf&m=Am2JDk_hD72fhW6i4mvubzmzUkUna2XA1hzuQxH9d34bABDVHbBvsJ3iSgxhOSJY&s=d5J3E2K7SCd9eOZhkpK5B9s_L8MIIjJKjOBMy71bd4g&e= . Triage notifications on the go with GitHub Mobile for iOS https://urldefense.proofpoint.com/v2/url?u=https-3A__apps.apple.com_app_apple-2Dstore_id1477376905-3Fct-3Dnotification-2Demail-26mt-3D8-26pt-3D524675&d=DwMCaQ&c=jGUuvAdBXp_VqQ6t0yah2g&r=TTXL98RIPQNjLdDSgeT8-yL45AVQu-9EyYWqGxjCNjqPZing27cmWboo1qWURfVf&m=Am2JDk_hD72fhW6i4mvubzmzUkUna2XA1hzuQxH9d34bABDVHbBvsJ3iSgxhOSJY&s=PdEbMT067RdHCdf5MrJyCQKBauPUsOg6XZtJp8yoMdI&e= or Android https://urldefense.proofpoint.com/v2/url?u=https-3A__play.google.com_store_apps_details-3Fid-3Dcom.github.android-26referrer-3Dutm-5Fcampaign-253Dnotification-2Demail-2526utm-5Fmedium-253Demail-2526utm-5Fsource-253Dgithub&d=DwMCaQ&c=jGUuvAdBXp_VqQ6t0yah2g&r=TTXL98RIPQNjLdDSgeT8-yL45AVQu-9EyYWqGxjCNjqPZing27cmWboo1qWURfVf&m=Am2JDk_hD72fhW6i4mvubzmzUkUna2XA1hzuQxH9d34bABDVHbBvsJ3iSgxhOSJY&s=LKowLHjvO5C3hjdOG7VETVCuzU1rxYwbi4D62U7NkWw&e=.

kpeters-cbsi avatar Dec 13 '21 16:12 kpeters-cbsi

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

kpeters-cbsi avatar Dec 13 '21 16:12 kpeters-cbsi

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

tomhoule avatar Dec 13 '21 17:12 tomhoule