1717)
1818
1919if TYPE_CHECKING :
20- from collections .abc import AsyncIterable , Awaitable , Callable
20+ from collections .abc import AsyncIterable , Awaitable , Callable , Collection
2121 from typing import TypeGuard
2222
2323 from .pyutils import AbortSignal , AwaitableOrValue
24+ from .validation import ASTValidationRule
2425
2526__all__ = ["graphql" , "graphql_sync" ]
2627
2728
28- async def graphql (
29+ async def graphql ( # noqa: PLR0913
2930 schema : GraphQLSchema ,
3031 source : str | Source ,
3132 root_value : Any = None ,
@@ -40,6 +41,11 @@ async def graphql(
4041 is_async_iterable : Callable [[Any ], TypeGuard [AsyncIterable ]] | None = None ,
4142 hide_suggestions : bool = False ,
4243 abort_signal : AbortSignal | None = None ,
44+ no_location : bool = False ,
45+ max_tokens : int | None = None ,
46+ experimental_fragment_arguments : bool = False ,
47+ rules : Collection [type [ASTValidationRule ]] | None = None ,
48+ max_errors : int | None = None ,
4349) -> ExecutionResult :
4450 """Execute a GraphQL operation asynchronously.
4551
@@ -92,6 +98,17 @@ async def graphql(
9298 :arg abort_signal:
9399 A signal object that can be used to cancel execution, e.g. the signal of an
94100 :class:`~graphql.AbortController`
101+ :arg no_location:
102+ Parse option: do not include location information in the parsed document.
103+ :arg max_tokens:
104+ Parse option: the maximum number of tokens the document may contain.
105+ :arg experimental_fragment_arguments:
106+ Parse option: enable experimental support for fragment arguments.
107+ :arg rules:
108+ The validation rules to use when validating the query.
109+ If not provided, the specified rules are used.
110+ :arg max_errors:
111+ The maximum number of validation errors to report before stopping.
95112 """
96113 # Always return asynchronously for a consistent API.
97114 result = graphql_impl (
@@ -109,6 +126,11 @@ async def graphql(
109126 is_async_iterable ,
110127 hide_suggestions ,
111128 abort_signal ,
129+ no_location ,
130+ max_tokens ,
131+ experimental_fragment_arguments ,
132+ rules ,
133+ max_errors ,
112134 )
113135
114136 if default_is_awaitable (result ):
@@ -127,7 +149,7 @@ def assume_not_async_iterable(_value: Any) -> TypeGuard[AsyncIterable]:
127149 return False
128150
129151
130- def graphql_sync (
152+ def graphql_sync ( # noqa: PLR0913
131153 schema : GraphQLSchema ,
132154 source : str | Source ,
133155 root_value : Any = None ,
@@ -141,6 +163,11 @@ def graphql_sync(
141163 check_sync : bool = False ,
142164 hide_suggestions : bool = False ,
143165 abort_signal : AbortSignal | None = None ,
166+ no_location : bool = False ,
167+ max_tokens : int | None = None ,
168+ experimental_fragment_arguments : bool = False ,
169+ rules : Collection [type [ASTValidationRule ]] | None = None ,
170+ max_errors : int | None = None ,
144171) -> ExecutionResult :
145172 """Execute a GraphQL operation synchronously.
146173
@@ -172,6 +199,11 @@ def graphql_sync(
172199 is_async_iterable ,
173200 hide_suggestions ,
174201 abort_signal ,
202+ no_location ,
203+ max_tokens ,
204+ experimental_fragment_arguments ,
205+ rules ,
206+ max_errors ,
175207 )
176208
177209 # Assert that the execution was synchronous.
@@ -183,7 +215,7 @@ def graphql_sync(
183215 return cast ("ExecutionResult" , result )
184216
185217
186- def graphql_impl (
218+ def graphql_impl ( # noqa: PLR0913
187219 schema : GraphQLSchema ,
188220 source : str | Source ,
189221 root_value : Any ,
@@ -198,6 +230,11 @@ def graphql_impl(
198230 is_async_iterable : Callable [[Any ], TypeGuard [AsyncIterable ]] | None = None ,
199231 hide_suggestions : bool = False ,
200232 abort_signal : AbortSignal | None = None ,
233+ no_location : bool = False ,
234+ max_tokens : int | None = None ,
235+ experimental_fragment_arguments : bool = False ,
236+ rules : Collection [type [ASTValidationRule ]] | None = None ,
237+ max_errors : int | None = None ,
201238) -> AwaitableOrValue [ExecutionResult ]:
202239 """Execute a query, return asynchronously only if necessary."""
203240 # Validate Schema
@@ -206,15 +243,20 @@ def graphql_impl(
206243
207244 # Parse
208245 try :
209- document = parse (source )
246+ document = parse (
247+ source ,
248+ no_location = no_location ,
249+ max_tokens = max_tokens ,
250+ experimental_fragment_arguments = experimental_fragment_arguments ,
251+ )
210252 except GraphQLError as error :
211253 return ExecutionResult (data = None , errors = [error ])
212254
213255 # Validate
214256 from .validation import validate
215257
216258 if validation_errors := validate (
217- schema , document , hide_suggestions = hide_suggestions
259+ schema , document , rules , max_errors , hide_suggestions = hide_suggestions
218260 ):
219261 return ExecutionResult (data = None , errors = validation_errors )
220262
0 commit comments