diff --git a/graphene/relay/tests/test_connection.py b/graphene/relay/tests/test_connection.py index 01680bf6..2f1441ac 100644 --- a/graphene/relay/tests/test_connection.py +++ b/graphene/relay/tests/test_connection.py @@ -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 diff --git a/graphene/relay/tests/test_mutation.py b/graphene/relay/tests/test_mutation.py index fab91f98..f8502df0 100644 --- a/graphene/relay/tests/test_mutation.py +++ b/graphene/relay/tests/test_mutation.py @@ -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'}}}}