From 0148401c0694893ef57d6b52a40adae272e6ebd5 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 20 Sep 2016 00:01:12 -0700 Subject: [PATCH] Removed executor and middleware from the Schema. --- UPGRADE-v1.0.md | 6 +++++- examples/starwars/tests/test_query.py | 6 +++--- graphene/types/schema.py | 27 +++++---------------------- graphene/types/tests/test_query.py | 4 ++-- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/UPGRADE-v1.0.md b/UPGRADE-v1.0.md index 0ed058a7..e0f3c4de 100644 --- a/UPGRADE-v1.0.md +++ b/UPGRADE-v1.0.md @@ -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 diff --git a/examples/starwars/tests/test_query.py b/examples/starwars/tests/test_query.py index b9887bc4..ac57c664 100644 --- a/examples/starwars/tests/test_query.py +++ b/examples/starwars/tests/test_query.py @@ -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 diff --git a/graphene/types/schema.py b/graphene/types/schema.py index 8a3a6e31..a57e6c37 100644 --- a/graphene/types/schema.py +++ b/graphene/types/schema.py @@ -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) diff --git a/graphene/types/tests/test_query.py b/graphene/types/tests/test_query.py index b31aa046..3059776a 100644 --- a/graphene/types/tests/test_query.py +++ b/graphene/types/tests/test_query.py @@ -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'}