Manualy merged in master.

This commit is contained in:
Markus Padourek 2016-09-12 17:25:10 +01:00
commit 9cd780ebdf
8 changed files with 50 additions and 9 deletions

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,4 +1,3 @@
from collections import OrderedDict
import pytest
from graphql_relay import to_global_id
@ -42,12 +41,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):
@ -96,7 +99,7 @@ def test_mutation_input():
def test_subclassed_mutation():
fields = OtherMutation._meta.fields
assert list(fields.keys()) == ['name', 'client_mutation_id']
assert list(fields.keys()) == ['name', 'client_mutation_id' 'my_node_edge']
assert isinstance(fields['name'], Field)
field = OtherMutation.Field()
assert field.type == OtherMutation
@ -125,3 +128,10 @@ def test_node_query():
)
assert not executed.errors
assert dict(executed.data) == {'say': {'myNodeId': to_global_id('MyNode', '1'), 'clientMutationId': '1', '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)