mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +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
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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'}}}}
|
||||
|
|
Loading…
Reference in New Issue
Block a user