當前位置: 首頁>>代碼示例>>Python>>正文


Python graphql.GraphQLSchema方法代碼示例

本文整理匯總了Python中graphql.GraphQLSchema方法的典型用法代碼示例。如果您正苦於以下問題:Python graphql.GraphQLSchema方法的具體用法?Python graphql.GraphQLSchema怎麽用?Python graphql.GraphQLSchema使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphql的用法示例。


在下文中一共展示了graphql.GraphQLSchema方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def __init__(
        self,
        schema: GraphQLSchema,
        *,
        context_value: Optional[ContextValue] = None,
        root_value: Optional[RootValue] = None,
        validation_rules: Optional[ValidationRules] = None,
        debug: bool = False,
        introspection: bool = True,
        logger: Optional[str] = None,
        error_formatter: ErrorFormatter = format_error,
        extensions: Optional[Extensions] = None,
        middleware: Optional[Middlewares] = None,
    ) -> None:
        self.context_value = context_value
        self.root_value = root_value
        self.validation_rules = validation_rules
        self.debug = debug
        self.introspection = introspection
        self.logger = logger
        self.error_formatter = error_formatter
        self.extensions = extensions
        self.middleware = middleware
        self.schema = schema 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:26,代碼來源:wsgi.py

示例2: execute_query

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def execute_query(self, request: HttpRequest, data: dict) -> GraphQLResult:
        context_value = self.get_context_for_request(request)
        extensions = self.get_extensions_for_request(request, context_value)

        return graphql_sync(
            cast(GraphQLSchema, self.schema),
            data,
            context_value=context_value,
            root_value=self.root_value,
            validation_rules=self.validation_rules,
            debug=settings.DEBUG,
            introspection=self.introspection,
            logger=self.logger,
            error_formatter=self.error_formatter or format_error,
            extensions=extensions,
            middleware=self.middleware,
        ) 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:19,代碼來源:views.py

示例3: generate_schema_hash

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [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

示例4: __init__

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def __init__(
        self, schema: GraphQLSchema,
    ):
        """Initialize the transport with the given local schema.

        :param schema: Local schema as GraphQLSchema object
        """
        self.schema = schema 
開發者ID:graphql-python,項目名稱:gql,代碼行數:10,代碼來源:local_schema.py

示例5: __init__

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def __init__(
        self,
        schema: GraphQLSchema,
        *,
        context_value: Optional[ContextValue] = None,
        root_value: Optional[RootValue] = None,
        validation_rules: Optional[ValidationRules] = None,
        debug: bool = False,
        introspection: bool = True,
        logger: Optional[str] = None,
        error_formatter: ErrorFormatter = format_error,
        extensions: Optional[Extensions] = None,
        middleware: Optional[Middlewares] = None,
        keepalive: float = None,
    ):
        self.context_value = context_value
        self.root_value = root_value
        self.validation_rules = validation_rules
        self.debug = debug
        self.introspection = introspection
        self.logger = logger
        self.error_formatter = error_formatter
        self.extensions = extensions
        self.middleware = middleware
        self.keepalive = keepalive
        self.schema = schema 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:28,代碼來源:asgi.py

示例6: test_build_schema_from_introspection

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def test_build_schema_from_introspection(
    benchmark, big_schema_introspection_result  # noqa: F811
):
    schema: GraphQLSchema = benchmark(
        lambda: build_client_schema(
            big_schema_introspection_result["data"], assume_valid=True
        )
    )
    assert schema.query_type is not None 
開發者ID:graphql-python,項目名稱:graphql-core,代碼行數:11,代碼來源:test_build_client_schema.py

示例7: test_build_schema_from_ast

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def test_build_schema_from_ast(benchmark, big_schema_sdl):  # noqa: F811
    schema_ast = parse(big_schema_sdl)
    schema: GraphQLSchema = benchmark(
        lambda: build_ast_schema(schema_ast, assume_valid=True)
    )
    assert schema.query_type is not None 
開發者ID:graphql-python,項目名稱:graphql-core,代碼行數:8,代碼來源:test_build_ast_schema.py

示例8: execution_started

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def execution_started(
        self,
        schema: GraphQLSchema,
        document: DocumentNode,
        root: Any,
        context: Optional[Any],
        variables: Optional[Any],
        operation_name: Optional[str],
        request_context: Dict[Any, Any],
    ) -> EndHandler:
        pass 
開發者ID:graphql-python,項目名稱:graphene-tornado,代碼行數:13,代碼來源:graphql_extension.py

示例9: get_response

# 需要導入模塊: import graphql [as 別名]
# 或者: from graphql import GraphQLSchema [as 別名]
def get_response(
    schema: GraphQLSchema,
    params: GraphQLParams,
    catch_exc: Type[BaseException],
    allow_only_query: bool = False,
    run_sync: bool = True,
    **kwargs,
) -> Optional[AwaitableOrValue[ExecutionResult]]:
    """Get an individual execution result as response, with option to catch errors.

    This does the same as graphql_impl() except that you can either
    throw an error on the ExecutionResult if allow_only_query is set to True
    or catch errors that belong to an exception class that you need to pass
    as a parameter.
    """

    # noinspection PyBroadException
    try:
        if not params.query:
            raise HttpQueryError(400, "Must provide query string.")

        # Parse document to trigger a new HttpQueryError if allow_only_query is True
        try:
            document = parse(params.query)
        except GraphQLError as e:
            return ExecutionResult(data=None, errors=[e])
        except Exception as e:
            e = GraphQLError(str(e), original_error=e)
            return ExecutionResult(data=None, errors=[e])

        if allow_only_query:
            operation_ast = get_operation_ast(document, params.operation_name)
            if operation_ast:
                operation = operation_ast.operation.value
                if operation != OperationType.QUERY.value:
                    raise HttpQueryError(
                        405,
                        f"Can only perform a {operation} operation from a POST request.",  # noqa
                        headers={"Allow": "POST"},
                    )

        if run_sync:
            execution_result = graphql_sync(
                schema=schema,
                source=params.query,
                variable_values=params.variables,
                operation_name=params.operation_name,
                **kwargs,
            )
        else:
            execution_result = graphql(  # type: ignore
                schema=schema,
                source=params.query,
                variable_values=params.variables,
                operation_name=params.operation_name,
                **kwargs,
            )
    except catch_exc:
        return None

    return execution_result 
開發者ID:graphql-python,項目名稱:graphql-server-core,代碼行數:63,代碼來源:__init__.py


注:本文中的graphql.GraphQLSchema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。