Skip to content

Commit 0148401

Browse files
committed
Removed executor and middleware from the Schema.
1 parent 227d942 commit 0148401

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

UPGRADE-v1.0.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ We have done our best to provide backwards compatibility with deprecated APIs.
7575

7676
Schemas in graphene `1.0` are `Immutable`, that means that once you create a `graphene.Schema` any
7777
change in their attributes will not have any effect.
78-
Also the `name` argument is removed from the Schema.
78+
The `name` argument is removed from the Schema.
79+
80+
The arguments `executor` and `middlewares` are also removed from the `Schema` definition.
81+
You can still use them, but by calling explicitly in the `execute` method in `graphql`.
82+
7983

8084
```python
8185
# Old way

examples/starwars/tests/test_query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_fetch_some_id_query():
163163
'name': 'Luke Skywalker',
164164
}
165165
}
166-
result = schema.execute(query, None, params)
166+
result = schema.execute(query, None, variable_values=params)
167167
assert not result.errors
168168
assert result.data == expected
169169

@@ -184,7 +184,7 @@ def test_fetch_some_id_query2():
184184
'name': 'Han Solo',
185185
}
186186
}
187-
result = schema.execute(query, None, params)
187+
result = schema.execute(query, None, variable_values=params)
188188
assert not result.errors
189189
assert result.data == expected
190190

@@ -203,7 +203,7 @@ def test_invalid_id_query():
203203
expected = {
204204
'human': None
205205
}
206-
result = schema.execute(query, None, params)
206+
result = schema.execute(query, None, variable_values=params)
207207
assert not result.errors
208208
assert result.data == expected
209209

graphene/types/schema.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from graphql import GraphQLSchema, MiddlewareManager, graphql, is_type
2+
from graphql import GraphQLSchema, graphql, is_type
33
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
44
GraphQLSkipDirective)
55
from graphql.type.introspection import IntrospectionSchema
@@ -14,18 +14,15 @@ class Schema(GraphQLSchema):
1414
Schema Definition
1515
1616
A Schema is created by supplying the root types of each type of operation,
17-
query and mutation (optional). A schema definition is then supplied to the
18-
validator and executor.
17+
query and mutation (optional).
1918
'''
2019

2120
def __init__(self, query=None, mutation=None, subscription=None,
22-
directives=None, types=None, executor=None, middlewares=None,
23-
auto_camelcase=True):
21+
directives=None, types=None, auto_camelcase=True):
2422
self._query = query
2523
self._mutation = mutation
2624
self._subscription = subscription
2725
self.types = types
28-
self._executor = executor
2926
self.auto_camelcase = auto_camelcase
3027
if directives is None:
3128
directives = [
@@ -37,10 +34,6 @@ def __init__(self, query=None, mutation=None, subscription=None,
3734
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
3835
directives
3936
)
40-
if middlewares:
41-
self.middlewares = MiddlewareManager(*middlewares)
42-
else:
43-
self.middlewares = None
4437
self._directives = directives
4538
self.build_typemap()
4639

@@ -65,18 +58,8 @@ def get_graphql_type(self, _type):
6558
return graphql_type
6659
raise Exception("{} is not a valid GraphQL type.".format(_type))
6760

68-
def execute(self, request_string='', root_value=None, variable_values=None,
69-
context_value=None, operation_name=None, executor=None):
70-
return graphql(
71-
schema=self,
72-
request_string=request_string,
73-
root_value=root_value,
74-
context_value=context_value,
75-
variable_values=variable_values,
76-
operation_name=operation_name,
77-
executor=executor or self._executor,
78-
middlewares=self.middlewares
79-
)
61+
def execute(self, *args, **kwargs):
62+
return graphql(self, *args, **kwargs)
8063

8164
def register(self, object_type):
8265
self.types.append(object_type)

graphene/types/tests/test_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def reversed_middleware(next, *args, **kwargs):
102102
p = next(*args, **kwargs)
103103
return p.then(lambda x: x[::-1])
104104

105-
hello_schema = Schema(Query, middlewares=[reversed_middleware])
105+
hello_schema = Schema(Query)
106106

107-
executed = hello_schema.execute('{ hello, other }')
107+
executed = hello_schema.execute('{ hello, other }', middleware=[reversed_middleware])
108108
assert not executed.errors
109109
assert executed.data == {'hello': 'dlroW', 'other': 'rehto'}
110110

0 commit comments

Comments
 (0)