From 0ef065e5cc55a5db6ca594eaae6fbd4fd7233e7f Mon Sep 17 00:00:00 2001 From: Markus Padourek Date: Tue, 16 Aug 2016 11:21:31 +0100 Subject: [PATCH] Added breaking test to demonstrate wanted subclassing feature. --- graphene/relay/tests/test_node.py | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/graphene/relay/tests/test_node.py b/graphene/relay/tests/test_node.py index 4e6df270..df3d0285 100644 --- a/graphene/relay/tests/test_node.py +++ b/graphene/relay/tests/test_node.py @@ -7,6 +7,19 @@ from ..connection import Connection from ..node import Node +class SharedNodeFields(ObjectType): + + class Meta: + interfaces = (Node, ) + + shared = String() + something_else = String() + + @classmethod + def get_node(cls, id, *_): + return cls(shared=str(id)) + + class MyNode(ObjectType): class Meta: @@ -18,11 +31,18 @@ class MyNode(ObjectType): return MyNode(name=str(id)) +class MyOtherNode(SharedNodeFields): + extra_field = String() + + def resolve_extra_field(self, *_): + return 'extra field info.' + + class RootQuery(ObjectType): first = String() node = Node.Field() -schema = Schema(query=RootQuery, types=[MyNode]) +schema = Schema(query=RootQuery, types=[MyNode, MyOtherNode]) def test_node_no_get_node(): @@ -66,6 +86,14 @@ def test_node_query(): assert executed.data == {'node': {'name': '1'}} +def test_subclassed_node_query(): + executed = schema.execute( + '{ node(id:"%s") { ... on MyOtherNode { shared, extraField } } }' % to_global_id("MyOtherNode", 1) + ) + assert not executed.errors + assert executed.data == {'node': {'shared': '1', 'extraField': 'extra field info'}} + + def test_node_query_incorrect_id(): executed = schema.execute( '{ node(id:"%s") { ... on MyNode { name } } }' % "something:2" @@ -85,6 +113,12 @@ type MyNode implements Node { name: String } +type MyOtherNode implements Node { + shared: String + somethingElse: String + extraField: String +} + interface Node { id: ID! }