Skip to content

Commit 3dcb53a

Browse files
committed
Merge pull request #159 from graphql-python/core-update
Core update GraphQL-core 0.5.0
2 parents 079014b + 7be5b83 commit 3dcb53a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+158
-125
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ install:
2525
if [ "$TEST_TYPE" = build ]; then
2626
pip install --download-cache $HOME/.cache/pip/ pytest pytest-cov coveralls six pytest-django django-filter sqlalchemy_utils
2727
pip install --download-cache $HOME/.cache/pip psycopg2 > /dev/null 2>&1
28+
pip install --download-cache $HOME/.cache/pip/ -e .
2829
pip install --download-cache $HOME/.cache/pip/ -e .[django]
2930
pip install --download-cache $HOME/.cache/pip/ -e .[sqlalchemy]
3031
pip install django==$DJANGO_VERSION
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from django.test import TestCase
21

32
# Create your tests here.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from django.shortcuts import render
21

32
# Create your views here.

examples/cookbook_django/cookbook/recipes/migrations/0001_initial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Generated by Django 1.9 on 2015-12-04 18:20
33
from __future__ import unicode_literals
44

5-
from django.db import migrations, models
65
import django.db.models.deletion
6+
from django.db import migrations, models
77

88

99
class Migration(migrations.Migration):
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from django.test import TestCase
21

32
# Create your tests here.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
from django.shortcuts import render
21

32
# Create your views here.

graphene/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
)
3434

3535
from graphene.utils import (
36-
resolve_only_args
36+
resolve_only_args,
37+
with_context
3738
)
3839

3940
__all__ = [
@@ -65,4 +66,5 @@
6566
'ListField',
6667
'NonNullField',
6768
'FloatField',
68-
'resolve_only_args']
69+
'resolve_only_args',
70+
'with_context']

graphene/contrib/django/debug/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def wrap_schema(self, schema_type):
7272

7373
@contextmanager
7474
def context_execution(self, executor):
75-
executor['root'] = WrappedRoot(root=executor['root'])
75+
executor['root_value'] = WrappedRoot(root=executor.get('root_value'))
7676
executor['schema'] = self.wrap_schema(executor['schema'])
77-
self.enable_instrumentation(executor['root'])
77+
self.enable_instrumentation(executor['root_value'])
7878
yield executor
7979
self.disable_instrumentation()

graphene/contrib/django/filter/filterset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
from django.utils.text import capfirst
55
from django_filters import Filter, MultipleChoiceFilter
66
from django_filters.filterset import FilterSet, FilterSetMetaclass
7-
from graphql_relay.node.node import from_global_id
87

98
from graphene.contrib.django.forms import (GlobalIDFormField,
109
GlobalIDMultipleChoiceField)
10+
from graphql_relay.node.node import from_global_id
1111

1212

1313
class GlobalIDFilter(Filter):
1414
field_class = GlobalIDFormField
1515

1616
def filter(self, qs, value):
17-
gid = from_global_id(value)
18-
return super(GlobalIDFilter, self).filter(qs, gid.id)
17+
_type, _id = from_global_id(value)
18+
return super(GlobalIDFilter, self).filter(qs, _id)
1919

2020

2121
class GlobalIDMultipleChoiceFilter(MultipleChoiceFilter):
2222
field_class = GlobalIDMultipleChoiceField
2323

2424
def filter(self, qs, value):
25-
gids = [from_global_id(v).id for v in value]
25+
gids = [from_global_id(v)[1] for v in value]
2626
return super(GlobalIDMultipleChoiceFilter, self).filter(qs, gids)
2727

2828

graphene/contrib/django/forms.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.core.exceptions import ValidationError
44
from django.forms import CharField, Field, IntegerField, MultipleChoiceField
55
from django.utils.translation import ugettext_lazy as _
6+
67
from graphql_relay import from_global_id
78

89

@@ -16,13 +17,13 @@ def clean(self, value):
1617
return None
1718

1819
try:
19-
gid = from_global_id(value)
20+
_type, _id = from_global_id(value)
2021
except (TypeError, ValueError, UnicodeDecodeError, binascii.Error):
2122
raise ValidationError(self.error_messages['invalid'])
2223

2324
try:
24-
IntegerField().clean(gid.id)
25-
CharField().clean(gid.type)
25+
IntegerField().clean(_id)
26+
CharField().clean(_type)
2627
except ValidationError:
2728
raise ValidationError(self.error_messages['invalid'])
2829

graphene/contrib/django/tests/test_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLObjectType
1+
from graphql.type import GraphQLObjectType
22
from mock import patch
33

44
from graphene import Schema

graphene/contrib/django/views.py

-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ def __init__(self, schema, **kwargs):
1111
executor=schema.executor,
1212
**kwargs
1313
)
14-
15-
def execute(self, *args, **kwargs):
16-
return self.graphene_schema.execute(*args, **kwargs)

graphene/contrib/sqlalchemy/tests/test_query.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from graphene.contrib.sqlalchemy import (SQLAlchemyConnectionField,
88
SQLAlchemyNode, SQLAlchemyObjectType)
99

10-
from .models import Article, Base, Reporter, Editor
10+
from .models import Article, Base, Editor, Reporter
1111

1212
db = create_engine('sqlite:///test_sqlalchemy.sqlite3')
1313

graphene/contrib/sqlalchemy/tests/test_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLObjectType
1+
from graphql.type import GraphQLObjectType
22
from pytest import raises
33

44
from graphene import Schema

graphene/core/classtypes/enum.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import six
2-
from graphql.core.type import GraphQLEnumType, GraphQLEnumValue
2+
from graphql.type import GraphQLEnumType, GraphQLEnumValue
33

4-
from .base import ClassTypeMeta, ClassType
5-
from ..types.base import MountedType
64
from ...utils.enum import Enum as PyEnum
5+
from ..types.base import MountedType
6+
from .base import ClassType, ClassTypeMeta
77

88

99
class EnumMeta(ClassTypeMeta):

graphene/core/classtypes/inputobjecttype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from functools import partial
22

3-
from graphql.core.type import GraphQLInputObjectType
3+
from graphql.type import GraphQLInputObjectType
44

55
from .base import FieldsClassType
66

graphene/core/classtypes/interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22

33
import six
4-
from graphql.core.type import GraphQLInterfaceType
4+
from graphql.type import GraphQLInterfaceType
55

66
from .base import FieldsClassTypeMeta
77
from .objecttype import ObjectType, ObjectTypeMeta

graphene/core/classtypes/objecttype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22

33
import six
4-
from graphql.core.type import GraphQLObjectType
4+
from graphql.type import GraphQLObjectType
55

66
from graphene import signals
77

graphene/core/classtypes/scalar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLScalarType
1+
from graphql.type import GraphQLScalarType
22

33
from ..types.base import MountedType
44
from .base import ClassType

graphene/core/classtypes/tests/test_enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLEnumType
1+
from graphql.type import GraphQLEnumType
22

33
from graphene.core.schema import Schema
44

graphene/core/classtypes/tests/test_inputobjecttype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from graphql.core.type import GraphQLInputObjectType
2+
from graphql.type import GraphQLInputObjectType
33

44
from graphene.core.schema import Schema
55
from graphene.core.types import String

graphene/core/classtypes/tests/test_interface.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType
1+
from graphql.type import GraphQLInterfaceType, GraphQLObjectType
22
from py.test import raises
33

44
from graphene.core.schema import Schema

graphene/core/classtypes/tests/test_mutation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from graphql.core.type import GraphQLObjectType
2+
from graphql.type import GraphQLObjectType
33

44
from graphene.core.schema import Schema
55
from graphene.core.types import String

graphene/core/classtypes/tests/test_objecttype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLObjectType
1+
from graphql.type import GraphQLObjectType
22
from py.test import raises
33

44
from graphene.core.schema import Schema

graphene/core/classtypes/tests/test_scalar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from graphql.core.type import GraphQLScalarType
1+
from graphql.type import GraphQLScalarType
22

33
from ...schema import Schema
44
from ..scalar import Scalar
55

66

77
def test_custom_scalar():
88
import datetime
9-
from graphql.core.language import ast
9+
from graphql.language import ast
1010

1111
class DateTimeScalar(Scalar):
1212
'''DateTimeScalar Documentation'''

graphene/core/classtypes/tests/test_uniontype.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from graphql.core.type import GraphQLUnionType
1+
from graphql.type import GraphQLUnionType
22

33
from graphene.core.schema import Schema
44
from graphene.core.types import String
@@ -25,4 +25,4 @@ class Meta:
2525
assert isinstance(object_type, GraphQLUnionType)
2626
assert Thing._meta.type_name == 'Thing'
2727
assert object_type.description == 'Thing union description'
28-
assert object_type.get_possible_types() == [schema.T(Human), schema.T(Pet)]
28+
assert object_type.get_types() == [schema.T(Human), schema.T(Pet)]

graphene/core/classtypes/uniontype.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import partial
22

33
import six
4-
from graphql.core.type import GraphQLUnionType
4+
from graphql.type import GraphQLUnionType
55

66
from .base import FieldsClassType, FieldsClassTypeMeta, FieldsOptions
77

graphene/core/schema.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import inspect
2-
from collections import OrderedDict
32

4-
from graphql.core.execution.executor import Executor
5-
from graphql.core.execution.middlewares.sync import \
6-
SynchronousExecutionMiddleware
7-
from graphql.core.type import GraphQLSchema as _GraphQLSchema
8-
from graphql.core.utils.introspection_query import introspection_query
9-
from graphql.core.utils.schema_printer import print_schema
3+
from graphql import graphql
4+
from graphql.type import GraphQLSchema as _GraphQLSchema
5+
from graphql.utils.introspection_query import introspection_query
6+
from graphql.utils.schema_printer import print_schema
107

118
from graphene import signals
129

@@ -68,9 +65,6 @@ def T(self, _type):
6865

6966
@property
7067
def executor(self):
71-
if not self._executor:
72-
self._executor = Executor(
73-
[SynchronousExecutionMiddleware()], map_type=OrderedDict)
7468
return self._executor
7569

7670
@executor.setter
@@ -121,10 +115,19 @@ def get_type(self, type_name):
121115
def types(self):
122116
return self._types_names
123117

124-
def execute(self, request='', root=None, args=None, **kwargs):
125-
kwargs = dict(kwargs, request=request, root=root, args=args, schema=self.schema)
118+
def execute(self, request_string='', root_value=None, variable_values=None,
119+
context_value=None, operation_name=None, executor=None):
120+
kwargs = dict(
121+
schema=self.schema,
122+
request_string=request_string,
123+
root_value=root_value,
124+
context_value=context_value,
125+
variable_values=variable_values,
126+
operation_name=operation_name,
127+
executor=executor or self._executor
128+
)
126129
with self.plugins.context_execution(**kwargs) as execute_kwargs:
127-
return self.executor.execute(**execute_kwargs)
130+
return graphql(**execute_kwargs)
128131

129132
def introspect(self):
130-
return self.execute(introspection_query).data
133+
return graphql(self.schema, introspection_query).data

graphene/core/tests/test_mutations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ def test_execute_mutations():
5858
'result': '5',
5959
}
6060
}
61-
result = schema.execute(query, root=object())
61+
result = schema.execute(query, root_value=object())
6262
assert not result.errors
6363
assert result.data == expected

graphene/core/tests/test_old_fields.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from graphql.core.type import (GraphQLBoolean, GraphQLField, GraphQLFloat,
2-
GraphQLID, GraphQLInt, GraphQLNonNull,
3-
GraphQLString)
1+
from graphql.type import (GraphQLBoolean, GraphQLField, GraphQLFloat,
2+
GraphQLID, GraphQLInt, GraphQLNonNull, GraphQLString)
43
from py.test import raises
54

65
from graphene.core.fields import (BooleanField, Field, FloatField, IDField,
@@ -94,7 +93,7 @@ def test_field_resolve():
9493
f = StringField(required=True, resolve=lambda *args: 'RESOLVED').as_field()
9594
f.contribute_to_class(MyOt, 'field_name')
9695
field_type = schema.T(f)
97-
assert 'RESOLVED' == field_type.resolver(MyOt, None, None)
96+
assert 'RESOLVED' == field_type.resolver(MyOt, None, None, None)
9897

9998

10099
def test_field_resolve_type_custom():

graphene/core/tests/test_query.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

3-
from graphql.core import graphql
4-
from graphql.core.type import GraphQLSchema
3+
from graphql import graphql
4+
from graphql.type import GraphQLSchema
55

66
from graphene.core.fields import Field
77
from graphene.core.schema import Schema
@@ -40,7 +40,7 @@ def resolve_pet(self, *args):
4040

4141
def test_type():
4242
assert Human._meta.fields_map['name'].resolver(
43-
Human(object()), {}, None) == 'Peter'
43+
Human(object()), {}, None, None) == 'Peter'
4444

4545

4646
def test_query():
@@ -59,6 +59,6 @@ def test_query():
5959
'type': 'Dog'
6060
}
6161
}
62-
result = graphql(schema, query, root=Human(object()))
62+
result = graphql(schema, query, root_value=Human(object()))
6363
assert not result.errors
6464
assert result.data == expected

0 commit comments

Comments
 (0)