-
-
Notifications
You must be signed in to change notification settings - Fork 138
How to update info.field_nodes[0].selection_set
?
#135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You just need to dig one level deeper, like |
Thank @Cito you saved my day :) By the way is there a simple way to loop down Field Nodes in python, to avoid hard coding indexes such cities {
name
district {
name
}
state {
name
country {
name
continent {
name
}
}
}
} |
Sure, you could do something like this to get to the allLibrary.results in the first example: node = next(n for n in info.field_nodes if n.name.value == 'allLibrary')
nodes = node.selection_set.selections
node = next(n for n in nodes if n.name.value == 'results')
nodes = node.selection_set.selections The "next" function is the Pythonic way to find the first field with the specified name. The function metioned in #136 might be also interesting to you. Btw, for "normal usage" you don't need to inspect the AST of the query. Maybe you're overcomplicating things? |
Context
I work with graphql in python (graphql-core-3), and I have a GraphQL query that looks like this.
When I investigate
info
objectinfo.field_nodes[0].selection_set.selections
I got selection set ofFieldNodes
that looks like that:Problem
In my second query set I added
results
field to wrap my data.Unfortunately, this causes a problem because query set is resolved from level of
allLibrary
notlibrary
as in the first example. The consequences of this structure is thatinfo.field_nodes[0].selection_set.selections
resolves fields incorrectly. Skiping, all the fields that I have interest in (name
,book
,__typename
).Question
How I can fix my
info.field_nodes[0].selection_set
so it fetches theFieldNode
correctly ?The text was updated successfully, but these errors were encountered: