Merge branch 'master' of github.com:graphql-python/graphene

This commit is contained in:
Syrus Akbary 2016-09-13 20:47:14 -07:00
commit a2b6d3dd05
9 changed files with 62 additions and 9 deletions

View File

@ -25,7 +25,7 @@ def resolve_xxx(self, args, context, info):
# ...
```
* `ObjectType and `Interface` no longer accept the `abstract` option in the `Meta`.
* `ObjectType` and `Interface` no longer accept the `abstract` option in the `Meta`.
Inheriting fields should be now achieved using `AbstractType` inheritance.
Before:

View File

@ -30,11 +30,13 @@ if not __SETUP__:
List, NonNull,
Enum,
Argument,
Dynamic
Dynamic,
Union,
)
from .relay import (
Node,
is_node,
GlobalID,
ClientIDMutation,
Connection,
ConnectionField,
@ -62,9 +64,11 @@ if not __SETUP__:
'NonNull',
'Argument',
'Dynamic',
'Union',
'resolve_only_args',
'Node',
'is_node',
'GlobalID',
'ClientIDMutation',
'Connection',
'ConnectionField',

View File

@ -1,10 +1,11 @@
from .node import Node, is_node
from .node import Node, is_node, GlobalID
from .mutation import ClientIDMutation
from .connection import Connection, ConnectionField, PageInfo
__all__ = [
'Node',
'is_node',
'GlobalID',
'ClientIDMutation',
'Connection',
'ConnectionField',

View File

@ -92,6 +92,16 @@ def test_edge_with_bases():
assert edge_fields['other'].type == String
def test_edge_on_node():
Edge = MyObject.Connection.Edge
assert Edge._meta.name == 'MyObjectEdge'
edge_fields = Edge._meta.fields
assert list(edge_fields.keys()) == ['node', 'cursor']
assert isinstance(edge_fields['node'], Field)
assert edge_fields['node'].type == MyObject
def test_pageinfo():
assert PageInfo._meta.name == 'PageInfo'
fields = PageInfo._meta.fields

View File

@ -1,15 +1,26 @@
from collections import OrderedDict
import pytest
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
Schema, AbstractType, NonNull)
from ...types.scalars import String
from ..connection import Connection
from ..mutation import ClientIDMutation
from ..node import Node
class SharedFields(AbstractType):
shared = String()
class MyNode(ObjectType):
class Meta:
interfaces = (Node, )
name = String()
class SaySomething(ClientIDMutation):
class Input:
@ -28,12 +39,16 @@ class OtherMutation(ClientIDMutation):
additional_field = String()
name = String()
my_node_edge = Field(MyNode.Connection.Edge)
@classmethod
def mutate_and_get_payload(cls, args, context, info):
shared = args.get('shared', '')
additionalField = args.get('additionalField', '')
return SaySomething(name=shared + additionalField)
edge_type = MyNode.Connection.Edge
return OtherMutation(name=shared + additionalField,
my_node_edge=edge_type(
cursor='1', node=MyNode(name='name')))
class RootQuery(ObjectType):
@ -81,7 +96,7 @@ def test_mutation_input():
def test_subclassed_mutation():
fields = OtherMutation._meta.fields
assert list(fields.keys()) == ['name']
assert list(fields.keys()) == ['name', 'my_node_edge']
assert isinstance(fields['name'], Field)
field = OtherMutation.Field()
assert field.type == OtherMutation
@ -110,3 +125,10 @@ def test_subclassed_mutation_input():
# )
# assert not executed.errors
# assert executed.data == {'say': {'phrase': 'hello'}}
def test_edge_query():
executed = schema.execute(
'mutation a { other(input: {clientMutationId:"1"}) { myNodeEdge { cursor node { name }} } }'
)
assert not executed.errors
assert dict(executed.data) == {'other': {'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}

View File

@ -13,6 +13,7 @@ from .inputfield import InputField
from .argument import Argument
from .inputobjecttype import InputObjectType
from .dynamic import Dynamic
from .union import Union
__all__ = [
@ -33,5 +34,6 @@ __all__ = [
'Boolean',
'List',
'NonNull',
'Argument'
'Dynamic']
'Argument',
'Dynamic',
]

View File

@ -32,7 +32,7 @@ def to_arguments(args, extra_args):
raise ValueError('Unknown argument "{}".'.format(default_name))
arg_name = default_name or arg.name
assert arg_name not in arguments, 'More than one Argument have same name "{}".'.format(arg.name)
assert arg_name not in arguments, 'More than one Argument have same name "{}".'.format(arg_name)
arguments[arg_name] = arg
return arguments

View File

@ -95,7 +95,7 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta)):
if kwargs:
for prop in list(kwargs):
try:
if isinstance(getattr(self.__class__, prop), property):
if isinstance(getattr(self.__class__, prop), property) or prop.startswith('_'):
setattr(self, prop, kwargs.pop(prop))
except AttributeError:
pass

View File

@ -64,6 +64,20 @@ def test_generate_objecttype_with_fields():
assert 'field' in MyObjectType._meta.fields
def test_generate_objecttype_with_private_attributes():
class MyObjectType(ObjectType):
_private_state = None
assert '_private_state' not in MyObjectType._meta.fields
assert hasattr(MyObjectType, '_private_state')
m = MyObjectType(_private_state='custom')
assert m._private_state == 'custom'
with pytest.raises(TypeError):
MyObjectType(_other_private_state='Wrong')
def test_ordered_fields_in_objecttype():
class MyObjectType(ObjectType):
b = Field(MyType)