Comments (2)
You'll need to analyze the AST for that. You'll get the AST after parsing using parse(document)
. Variables are always passed to arguments or children of arguments, so it's best to have a look at all ArgumentNode
s using BFS/DFS:
graphql-core/src/graphql/language/ast.py
Lines 520 to 524 in 0c93b84
The possible inputs to ArgumentNodes are the subclasses of ValueNode
. If you just want to look for Variables, not constants, do another DFS search inside each ArgumentNode
, expanding all the ListValueNode
s and ObjectValueNode
s.
You can also write a custom visitor to save the effort of manually performing the search and call it using the visit function: https://github.com/graphql-python/graphql-core/blob/main/src/graphql/language/visitor.py
Hope that helps, LMK if you have any questions. Am curious about the use case so please feel free to share more (maybe not in this issue though, so we don't add too much noise)🙂
from graphql-core.
Since I parse every operation down to field level I added an argument evaluator that will map
variable uses to field definition, looks like this:
def _evaluate_variable_uses(
type_info: OperationTypeInfo,
field: QtGqlFieldDefinition,
arguments: tuple[gql_lang.ArgumentNode, ...],
) -> list[QtGqlVariableUse]:
ret: list[QtGqlVariableUse] = []
for arg in arguments:
index = field.index_for_argument(arg.name.value)
var_name = arg.value.name.value # type: ignore[attr-defined]
for variable in type_info.variables:
if var_name == variable.name:
ret.append(
QtGqlVariableUse(argument=(index, field.arguments[index]), variable=variable),
)
assert len(ret) == len(arguments), "could not find all variable uses"
return ret
def _evaluate_variable_node_type(
type_info: SchemaTypeInfo,
node: graphql.TypeNode,
) -> QtGqlTypeABC:
if nonnull := is_nonnull_node(node):
return evaluate_graphql_type(
type_info,
graphql.type.GraphQLNonNull(
type_info.schema_definition.get_type(nonnull.type.name.value), # type: ignore
),
)
if named_type := is_named_type_node(node):
gql_concrete = type_info.schema_definition.get_type(named_type.name.value)
assert gql_concrete
return evaluate_graphql_type(type_info, gql_concrete)
raise NotImplementedError(node, "Type is not supported as a variable ATM")
Then fields that has arguments are stored in a map that is that looks like this
std::map<std::tuple<(argument types)>, (value)>
And when an operation is deserialized the value is set on that field based on the operation argument that
I already determined what they should be.
from graphql-core.
Related Issues (20)
- Can you inject fields to an operation with a Visitor? HOT 2
- Use type guards for `language.predicates` HOT 1
- Trying to inject `id` field on every `selection_set` HOT 1
- Can default values form cycles? HOT 2
- Include name in representation of named nodes HOT 1
- performance issues due to breadth first execution of grapqhl queries in case of async resolvers during calls burst HOT 4
- A
- subscribe breaking change in graphql version 3.3.0a3 HOT 1
- Using Relays in Graphql-core raises a TypeError HOT 4
- `out_name` is not respected for input objects used as default argument value
- Segfault during schema parsing HOT 3
- Segfault during schema parsing
- `graphql.utilities.print_schema` module contents are hidden behind `utilities` package
- `deepcopy` fails if the schema has a directive with an enum argument
- Both `typing.ByteString` and `typing.Text` are deprecated and slated for removal in Python 3.14 HOT 3
- Add the ability to specify `GraphQLResolveInfo.context` type HOT 1
- I use middleware for that right now HOT 1
- construction fails for depth around > 200 / resource exhaustion? HOT 9
- Cancel resolver tasks if execution of an operation is terminated HOT 7
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 graphql-core.