Description
I'm trying to consume the enum from a complex query that involves inline fragments. However, I'm unable to get any of the fragments, neither the as, as mentioned in some documents. Any advice would be much appreciated 🙏.
#[derive(GraphQLQuery)] #[graphql( schema_path = "src/schemas/pluralsight_schema.graphql", query_path = "src/queries/pluralsight_queries.graphql", response_derives = "Debug, Serialize, Deserialize, PartialEq, Clone" )] struct ChannelContent;
query ChannelContent($channelId: String!) { channelContent(first: 1000, filter: { channelId: $channelId }) { nodes { id channelId index type __typename ... on Section { name description content { id index type __typename ... on ExternalLinkSection { url title contentType level durationInSeconds } } } __typename ... on ExternalLink { url title contentType level durationInSeconds } } } }
Any example or post would also do, on how to process these kind of complex queries.
Activity
tomhoule commentedon Dec 21, 2023
What is missing from
channel_content::ResponseData
? There are tests using inline fragments, e.g.graphql-client/graphql_client/tests/type_refining_fragments.rs
Line 20 in c52e89e
debanjanbasu commentedon Dec 22, 2023
Thanks for getting back quickly @tomhoule, following is my code that's parsing the responsedata:
What's missing is this:
There should be something similar to onSection / onExternalLink right? Judging by the query:
tomhoule commentedon Dec 26, 2023
I think the
on
is an enum, so you should be able tomatch node.on { ... }
, andChannelContentChannelContentNodesOn
should have a variant likeChannelContentChannelContentNodesOn::ExternalLinkSection(...)
. I haven't worked on this library in a while, my memory may be wrong.debanjanbasu commentedon Dec 31, 2023
Thanks and that does help. Probably I'm new to Rust and need a bit more of guidance on how to get the other key values from the Sections, and Section Contents 😅 🙏. Thanking in advance, and happy new year @tomhoule 🎉.
tomhoule commentedon Jan 2, 2024
It gets a bit hard to read, but from the test I linked earlier, you can see there should be a nested struct inside the enum on
on
, so something like:This library is hard to use if you don't look at the generated code (the CLI can help with that) or have a working IDE that can help you with completing type names.
Happy new year to you too :)
Christoph-AK commentedon Feb 12, 2024
Hey there! Man, this stuff is frustrating as the types are not correctly shown in vscode with rust analyzer half the time and check times get increasingly longer the more statements arer involved.
I try to make calls to shopify API with this query:
but cant figure out how to unpack the
on BulkOperation
conversion.I tried to follow the examples in the test, but get
Field 'on' not found in type query_bulk_operation::QueryBulkOperationNode
.How is this supposed to work?
Gumichocopengin8 commentedon May 30, 2024
I have the same issue @Christoph-AK has. When
on
is used, the code doesn't compile.@tomhoule how can we fix this?
This is GitHub API.
Thanks for the great library!
Christoph-AK commentedon May 30, 2024
@Gumichocopengin8 as workaround I am now serialising my 'on'-data with json. It's... not at all what this library is about, but at least that way my queries are working.
Gumichocopengin8 commentedon May 30, 2024
Thank you! I'll try that out.
Do you have a plan to fix this issue?
Gumichocopengin8 commentedon May 30, 2024
@tomhoule If I want to fix the issue, which code file should I take a look at?
Gumichocopengin8 commentedon Jun 5, 2024
@Christoph-AK Sorry for many comments.
I tried to accessing to
on
by serializing the data, but couldn't make it well. Could you please provide the code?Thank you.
tomhoule commentedon Jun 7, 2024
I'm not able to help here, sorry, it would take time to look at the generated code. If there is a bug, ideally we would have an issue with a straightforward reproduction, and someone can take a look at it. I am not able to spend time on this project at the moment.
Christoph-AK commentedon Jun 8, 2024
@Gumichocopengin8 Only just found some time to answer, sorry.
I'm not contributing, so I can't really give you pointers on how to solve this within the crate, but my solution for a Shopify gql batch call is like this:
Hope this helps!
Gumichocopengin8 commentedon Jun 8, 2024
if I can make a easy reproduction code, I'll make one as a new issue with the code.
Gumichocopengin8 commentedon Jun 8, 2024
@Christoph-AK thanks! that's really helpful.