mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Removed executor and middleware from the Schema.
This commit is contained in:
parent
227d9422ff
commit
0148401c06
|
@ -75,7 +75,11 @@ We have done our best to provide backwards compatibility with deprecated APIs.
|
||||||
|
|
||||||
Schemas in graphene `1.0` are `Immutable`, that means that once you create a `graphene.Schema` any
|
Schemas in graphene `1.0` are `Immutable`, that means that once you create a `graphene.Schema` any
|
||||||
change in their attributes will not have any effect.
|
change in their attributes will not have any effect.
|
||||||
Also the `name` argument is removed from the Schema.
|
The `name` argument is removed from the Schema.
|
||||||
|
|
||||||
|
The arguments `executor` and `middlewares` are also removed from the `Schema` definition.
|
||||||
|
You can still use them, but by calling explicitly in the `execute` method in `graphql`.
|
||||||
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Old way
|
# Old way
|
||||||
|
|
|
@ -163,7 +163,7 @@ def test_fetch_some_id_query():
|
||||||
'name': 'Luke Skywalker',
|
'name': 'Luke Skywalker',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = schema.execute(query, None, params)
|
result = schema.execute(query, None, variable_values=params)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ def test_fetch_some_id_query2():
|
||||||
'name': 'Han Solo',
|
'name': 'Han Solo',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = schema.execute(query, None, params)
|
result = schema.execute(query, None, variable_values=params)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ def test_invalid_id_query():
|
||||||
expected = {
|
expected = {
|
||||||
'human': None
|
'human': None
|
||||||
}
|
}
|
||||||
result = schema.execute(query, None, params)
|
result = schema.execute(query, None, variable_values=params)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
from graphql import GraphQLSchema, MiddlewareManager, graphql, is_type
|
from graphql import GraphQLSchema, graphql, is_type
|
||||||
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
|
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
|
||||||
GraphQLSkipDirective)
|
GraphQLSkipDirective)
|
||||||
from graphql.type.introspection import IntrospectionSchema
|
from graphql.type.introspection import IntrospectionSchema
|
||||||
|
@ -14,18 +14,15 @@ class Schema(GraphQLSchema):
|
||||||
Schema Definition
|
Schema Definition
|
||||||
|
|
||||||
A Schema is created by supplying the root types of each type of operation,
|
A Schema is created by supplying the root types of each type of operation,
|
||||||
query and mutation (optional). A schema definition is then supplied to the
|
query and mutation (optional).
|
||||||
validator and executor.
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, query=None, mutation=None, subscription=None,
|
def __init__(self, query=None, mutation=None, subscription=None,
|
||||||
directives=None, types=None, executor=None, middlewares=None,
|
directives=None, types=None, auto_camelcase=True):
|
||||||
auto_camelcase=True):
|
|
||||||
self._query = query
|
self._query = query
|
||||||
self._mutation = mutation
|
self._mutation = mutation
|
||||||
self._subscription = subscription
|
self._subscription = subscription
|
||||||
self.types = types
|
self.types = types
|
||||||
self._executor = executor
|
|
||||||
self.auto_camelcase = auto_camelcase
|
self.auto_camelcase = auto_camelcase
|
||||||
if directives is None:
|
if directives is None:
|
||||||
directives = [
|
directives = [
|
||||||
|
@ -37,10 +34,6 @@ class Schema(GraphQLSchema):
|
||||||
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
|
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
|
||||||
directives
|
directives
|
||||||
)
|
)
|
||||||
if middlewares:
|
|
||||||
self.middlewares = MiddlewareManager(*middlewares)
|
|
||||||
else:
|
|
||||||
self.middlewares = None
|
|
||||||
self._directives = directives
|
self._directives = directives
|
||||||
self.build_typemap()
|
self.build_typemap()
|
||||||
|
|
||||||
|
@ -65,18 +58,8 @@ class Schema(GraphQLSchema):
|
||||||
return graphql_type
|
return graphql_type
|
||||||
raise Exception("{} is not a valid GraphQL type.".format(_type))
|
raise Exception("{} is not a valid GraphQL type.".format(_type))
|
||||||
|
|
||||||
def execute(self, request_string='', root_value=None, variable_values=None,
|
def execute(self, *args, **kwargs):
|
||||||
context_value=None, operation_name=None, executor=None):
|
return graphql(self, *args, **kwargs)
|
||||||
return graphql(
|
|
||||||
schema=self,
|
|
||||||
request_string=request_string,
|
|
||||||
root_value=root_value,
|
|
||||||
context_value=context_value,
|
|
||||||
variable_values=variable_values,
|
|
||||||
operation_name=operation_name,
|
|
||||||
executor=executor or self._executor,
|
|
||||||
middlewares=self.middlewares
|
|
||||||
)
|
|
||||||
|
|
||||||
def register(self, object_type):
|
def register(self, object_type):
|
||||||
self.types.append(object_type)
|
self.types.append(object_type)
|
||||||
|
|
|
@ -102,9 +102,9 @@ def test_query_middlewares():
|
||||||
p = next(*args, **kwargs)
|
p = next(*args, **kwargs)
|
||||||
return p.then(lambda x: x[::-1])
|
return p.then(lambda x: x[::-1])
|
||||||
|
|
||||||
hello_schema = Schema(Query, middlewares=[reversed_middleware])
|
hello_schema = Schema(Query)
|
||||||
|
|
||||||
executed = hello_schema.execute('{ hello, other }')
|
executed = hello_schema.execute('{ hello, other }', middleware=[reversed_middleware])
|
||||||
assert not executed.errors
|
assert not executed.errors
|
||||||
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
|
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user