Removed executor and middleware from the Schema.

This commit is contained in:
Syrus Akbary 2016-09-20 00:01:12 -07:00
parent 227d9422ff
commit 0148401c06
4 changed files with 15 additions and 28 deletions

View File

@ -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
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
# Old way

View File

@ -163,7 +163,7 @@ def test_fetch_some_id_query():
'name': 'Luke Skywalker',
}
}
result = schema.execute(query, None, params)
result = schema.execute(query, None, variable_values=params)
assert not result.errors
assert result.data == expected
@ -184,7 +184,7 @@ def test_fetch_some_id_query2():
'name': 'Han Solo',
}
}
result = schema.execute(query, None, params)
result = schema.execute(query, None, variable_values=params)
assert not result.errors
assert result.data == expected
@ -203,7 +203,7 @@ def test_invalid_id_query():
expected = {
'human': None
}
result = schema.execute(query, None, params)
result = schema.execute(query, None, variable_values=params)
assert not result.errors
assert result.data == expected

View File

@ -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,
GraphQLSkipDirective)
from graphql.type.introspection import IntrospectionSchema
@ -14,18 +14,15 @@ class Schema(GraphQLSchema):
Schema Definition
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
validator and executor.
query and mutation (optional).
'''
def __init__(self, query=None, mutation=None, subscription=None,
directives=None, types=None, executor=None, middlewares=None,
auto_camelcase=True):
directives=None, types=None, auto_camelcase=True):
self._query = query
self._mutation = mutation
self._subscription = subscription
self.types = types
self._executor = executor
self.auto_camelcase = auto_camelcase
if directives is None:
directives = [
@ -37,10 +34,6 @@ class Schema(GraphQLSchema):
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
directives
)
if middlewares:
self.middlewares = MiddlewareManager(*middlewares)
else:
self.middlewares = None
self._directives = directives
self.build_typemap()
@ -65,18 +58,8 @@ class Schema(GraphQLSchema):
return graphql_type
raise Exception("{} is not a valid GraphQL type.".format(_type))
def execute(self, request_string='', root_value=None, variable_values=None,
context_value=None, operation_name=None, executor=None):
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 execute(self, *args, **kwargs):
return graphql(self, *args, **kwargs)
def register(self, object_type):
self.types.append(object_type)

View File

@ -102,9 +102,9 @@ def test_query_middlewares():
p = next(*args, **kwargs)
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 executed.data == {'hello': 'dlroW', 'other': 'rehto'}