当前位置: 首页>>代码示例>>Python>>正文


Python graphql.execute方法代码示例

本文整理汇总了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 
开发者ID:graphql-python,项目名称:gql,代码行数:20,代码来源:local_schema.py

示例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() 
开发者ID:graphql-python,项目名称:graphene-tornado,代码行数:18,代码来源:schema_utils.py

示例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) 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:15,代码来源:views.py

示例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 
开发者ID:graphql-python,项目名称:graphql-core,代码行数:7,代码来源:test_introspection_from_schema.py

示例5: execute

# 需要导入模块: import graphql [as 别名]
# 或者: from graphql import execute [as 别名]
def execute(self, *args, **kwargs):
        return execute(self.schema, *args, **kwargs) 
开发者ID:GraphQL-python-archive,项目名称:graphql-django-view,代码行数:4,代码来源:__init__.py

示例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) 
开发者ID:GraphQL-python-archive,项目名称:graphql-django-view,代码行数:39,代码来源:__init__.py

示例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) 
开发者ID:graphql-python,项目名称:graphene-tornado,代码行数:6,代码来源:tornado_graphql_handler.py


注:本文中的graphql.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。