Skip to content

Commit d7efc5b

Browse files
authored
Allow request string to be passed in as the ast
This allows for parsing the ast beforehand doing some work specific to the query and then just passing that in to the normal `graphql` call rather than having to stitch everything together manually.
1 parent da3c06f commit d7efc5b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

graphql/graphql.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .execution import ExecutionResult, execute
22
from .language.parser import parse
33
from .language.source import Source
4+
from .language.ast import Document
45
from .validation import validate
56

67

@@ -30,8 +31,11 @@ def graphql(schema, request_string='', root_value=None, context_value=None,
3031
variable_values=None, operation_name=None, executor=None,
3132
return_promise=False):
3233
try:
33-
source = Source(request_string, 'GraphQL request')
34-
ast = parse(source)
34+
if isinstance(request_string, Document):
35+
ast = request_string
36+
else:
37+
source = Source(request_string, 'GraphQL request')
38+
ast = parse(source)
3539
validation_errors = validate(schema, ast)
3640
if validation_errors:
3741
return ExecutionResult(

0 commit comments

Comments
 (0)