当前位置: 首页>>代码示例>>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;未经允许,请勿转载。