mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Merge pull request #285 from Globegitter/edge-for-type
Added test for node connection edge.
This commit is contained in:
commit
8e320da051
|
@ -92,6 +92,16 @@ def test_edge_with_bases():
|
||||||
assert edge_fields['other'].type == String
|
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():
|
def test_pageinfo():
|
||||||
assert PageInfo._meta.name == 'PageInfo'
|
assert PageInfo._meta.name == 'PageInfo'
|
||||||
fields = PageInfo._meta.fields
|
fields = PageInfo._meta.fields
|
||||||
|
|
|
@ -1,15 +1,26 @@
|
||||||
|
from collections import OrderedDict
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
|
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
|
||||||
Schema, AbstractType, NonNull)
|
Schema, AbstractType, NonNull)
|
||||||
from ...types.scalars import String
|
from ...types.scalars import String
|
||||||
|
from ..connection import Connection
|
||||||
from ..mutation import ClientIDMutation
|
from ..mutation import ClientIDMutation
|
||||||
|
from ..node import Node
|
||||||
|
|
||||||
|
|
||||||
class SharedFields(AbstractType):
|
class SharedFields(AbstractType):
|
||||||
shared = String()
|
shared = String()
|
||||||
|
|
||||||
|
|
||||||
|
class MyNode(ObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
interfaces = (Node, )
|
||||||
|
|
||||||
|
name = String()
|
||||||
|
|
||||||
|
|
||||||
class SaySomething(ClientIDMutation):
|
class SaySomething(ClientIDMutation):
|
||||||
|
|
||||||
class Input:
|
class Input:
|
||||||
|
@ -28,12 +39,16 @@ class OtherMutation(ClientIDMutation):
|
||||||
additional_field = String()
|
additional_field = String()
|
||||||
|
|
||||||
name = String()
|
name = String()
|
||||||
|
my_node_edge = Field(MyNode.Connection.Edge)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, args, context, info):
|
def mutate_and_get_payload(cls, args, context, info):
|
||||||
shared = args.get('shared', '')
|
shared = args.get('shared', '')
|
||||||
additionalField = args.get('additionalField', '')
|
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):
|
class RootQuery(ObjectType):
|
||||||
|
@ -81,7 +96,7 @@ def test_mutation_input():
|
||||||
|
|
||||||
def test_subclassed_mutation():
|
def test_subclassed_mutation():
|
||||||
fields = OtherMutation._meta.fields
|
fields = OtherMutation._meta.fields
|
||||||
assert list(fields.keys()) == ['name']
|
assert list(fields.keys()) == ['name', 'my_node_edge']
|
||||||
assert isinstance(fields['name'], Field)
|
assert isinstance(fields['name'], Field)
|
||||||
field = OtherMutation.Field()
|
field = OtherMutation.Field()
|
||||||
assert field.type == OtherMutation
|
assert field.type == OtherMutation
|
||||||
|
@ -110,3 +125,10 @@ def test_subclassed_mutation_input():
|
||||||
# )
|
# )
|
||||||
# assert not executed.errors
|
# assert not executed.errors
|
||||||
# assert executed.data == {'say': {'phrase': 'hello'}}
|
# 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'}}}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user