mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Added breaking test to demonstrate wanted subclassing feature.
This commit is contained in:
parent
018811036b
commit
0ef065e5cc
|
@ -7,6 +7,19 @@ from ..connection import Connection
|
||||||
from ..node import Node
|
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 MyNode(ObjectType):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -18,11 +31,18 @@ class MyNode(ObjectType):
|
||||||
return MyNode(name=str(id))
|
return MyNode(name=str(id))
|
||||||
|
|
||||||
|
|
||||||
|
class MyOtherNode(SharedNodeFields):
|
||||||
|
extra_field = String()
|
||||||
|
|
||||||
|
def resolve_extra_field(self, *_):
|
||||||
|
return 'extra field info.'
|
||||||
|
|
||||||
|
|
||||||
class RootQuery(ObjectType):
|
class RootQuery(ObjectType):
|
||||||
first = String()
|
first = String()
|
||||||
node = Node.Field()
|
node = Node.Field()
|
||||||
|
|
||||||
schema = Schema(query=RootQuery, types=[MyNode])
|
schema = Schema(query=RootQuery, types=[MyNode, MyOtherNode])
|
||||||
|
|
||||||
|
|
||||||
def test_node_no_get_node():
|
def test_node_no_get_node():
|
||||||
|
@ -66,6 +86,14 @@ def test_node_query():
|
||||||
assert executed.data == {'node': {'name': '1'}}
|
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():
|
def test_node_query_incorrect_id():
|
||||||
executed = schema.execute(
|
executed = schema.execute(
|
||||||
'{ node(id:"%s") { ... on MyNode { name } } }' % "something:2"
|
'{ node(id:"%s") { ... on MyNode { name } } }' % "something:2"
|
||||||
|
@ -85,6 +113,12 @@ type MyNode implements Node {
|
||||||
name: String
|
name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MyOtherNode implements Node {
|
||||||
|
shared: String
|
||||||
|
somethingElse: String
|
||||||
|
extraField: String
|
||||||
|
}
|
||||||
|
|
||||||
interface Node {
|
interface Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user