Python graphql.GraphQLSchema() Examples
The following are 9
code examples of graphql.GraphQLSchema().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
graphql
, or try the search function
.
Example #1
Source File: wsgi.py From ariadne with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #2
Source File: views.py From ariadne with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, )
Example #3
Source File: schema_utils.py From graphene-tornado with MIT License | 6 votes |
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()
Example #4
Source File: local_schema.py From gql with MIT License | 5 votes |
def __init__( self, schema: GraphQLSchema, ): """Initialize the transport with the given local schema. :param schema: Local schema as GraphQLSchema object """ self.schema = schema
Example #5
Source File: asgi.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #6
Source File: test_build_client_schema.py From graphql-core with MIT License | 5 votes |
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
Example #7
Source File: test_build_ast_schema.py From graphql-core with MIT License | 5 votes |
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
Example #8
Source File: graphql_extension.py From graphene-tornado with MIT License | 5 votes |
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
Example #9
Source File: __init__.py From graphql-server-core with MIT License | 4 votes |
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