本文整理匯總了Python中graphql.execute方法的典型用法代碼示例。如果您正苦於以下問題:Python graphql.execute方法的具體用法?Python graphql.execute怎麽用?Python graphql.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graphql
的用法示例。
在下文中一共展示了graphql.execute方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: execute
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def execute(
self, document: DocumentNode, *args, **kwargs,
) -> ExecutionResult:
"""Execute the provided document AST for on a local GraphQL Schema.
"""
result_or_awaitable = execute(self.schema, document, *args, **kwargs)
execution_result: ExecutionResult
if isawaitable(result_or_awaitable):
result_or_awaitable = cast(Awaitable[ExecutionResult], result_or_awaitable)
execution_result = await result_or_awaitable
else:
result_or_awaitable = cast(ExecutionResult, result_or_awaitable)
execution_result = result_or_awaitable
return execution_result
示例2: generate_schema_hash
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def generate_schema_hash(schema: GraphQLSchema) -> str:
"""
Generates a stable hash of the current schema using an introspection query.
"""
ast = parse(introspection_query)
result = cast(ExecutionResult, execute(schema, ast))
if result and not result.data:
raise GraphQLError("Unable to generate server introspection document")
schema = result.data["__schema"]
# It's important that we perform a deterministic stringification here
# since, depending on changes in the underlying `graphql-core` execution
# layer, varying orders of the properties in the introspection
stringified_schema = stringify(schema).encode("utf-8")
return hashlib.sha512(stringified_schema).hexdigest()
示例3: execute
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def execute(self, *args, **kwargs):
operation_ast = get_operation_ast(args[0])
if operation_ast and operation_ast.operation == "subscription":
result = subscribe(self.schema, *args, **kwargs)
if isinstance(result, Observable):
a = []
result.subscribe(lambda x: a.append(x))
if len(a) > 0:
result = a[-1]
return result
return execute(self.schema, *args, **kwargs)
示例4: test_execute_introspection_query
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def test_execute_introspection_query(benchmark, big_schema_sdl): # noqa: F811
schema = build_schema(big_schema_sdl, assume_valid=True)
document = parse(get_introspection_query())
result = benchmark(lambda: execute(schema=schema, document=document))
assert result.errors is None
示例5: execute
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def execute(self, *args, **kwargs):
return execute(self.schema, *args, **kwargs)
示例6: execute_graphql_request
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def execute_graphql_request(self, request):
query, variables, operation_name = self.get_graphql_params(request, self.parse_body(request))
if not query:
raise HttpError(HttpResponseBadRequest('Must provide query string.'))
source = Source(query, name='GraphQL request')
try:
document_ast = parse(source)
validation_errors = validate(self.schema, document_ast)
if validation_errors:
return ExecutionResult(
errors=validation_errors,
invalid=True,
)
except Exception as e:
return ExecutionResult(errors=[e], invalid=True)
if request.method.lower() == 'get':
operation_ast = get_operation_ast(document_ast, operation_name)
if operation_ast and operation_ast.operation != 'query':
raise HttpError(HttpResponseNotAllowed(
['POST'], 'Can only perform a {} operation from a POST request.'.format(operation_ast.operation)
))
try:
return self.execute(
document_ast,
root_value=self.get_root_value(request),
variable_values=variables,
operation_name=operation_name,
context_value=self.get_context(request),
executor=self.executor,
)
except Exception as e:
return ExecutionResult(errors=[e], invalid=True)
示例7: execute
# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import execute [as 別名]
def execute(
self, *args, **kwargs
) -> Union[Awaitable[ExecutionResult], ExecutionResult]:
return execute(self.schema.graphql_schema, *args, **kwargs)