當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。