Skip to content

Commit 0a97dea

Browse files
committed
Improved relay coverage
1 parent 7e901f8 commit 0a97dea

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

graphene/relay/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
String, Union)
1010
from ..types.field import Field
1111
from ..types.objecttype import ObjectType, ObjectTypeOptions
12-
from ..utils.deprecated import warn_deprecation
1312
from .node import is_node
1413

1514

@@ -101,7 +100,7 @@ def type(self):
101100
type = super(IterableConnectionField, self).type
102101
connection_type = type
103102
if is_node(type):
104-
warn_deprecation(
103+
raise Exception(
105104
"ConnectionField's now need a explicit ConnectionType for Nodes.\n"
106105
"Read more: https://github.com/graphql-python/graphene/blob/2.0/UPGRADE-v2.0.md#node-connections"
107106
)

graphene/relay/mutation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ class Meta:
1414

1515
@classmethod
1616
def __init_subclass_with_meta__(cls, output=None, input_fields=None,
17-
arguments=None, name=None, abstract=False, **options):
18-
if abstract:
19-
return
20-
17+
arguments=None, name=None, **options):
2118
input_class = getattr(cls, 'Input', None)
2219
base_name = re.sub('Payload$', '', name or cls.__name__)
2320

graphene/relay/tests/test_connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12

23
from ...types import Argument, Field, Int, List, NonNull, ObjectType, String
34
from ..connection import Connection, ConnectionField, PageInfo
@@ -117,6 +118,13 @@ class Meta:
117118
}
118119

119120

121+
def test_connectionfield_node_deprecated():
122+
field = ConnectionField(MyObject)
123+
with pytest.raises(Exception) as exc_info:
124+
field.type
125+
126+
assert "ConnectionField's now need a explicit ConnectionType for Nodes." in str(exc_info.value)
127+
120128
def test_connectionfield_custom_args():
121129
class MyObjectConnection(Connection):
122130

graphene/relay/tests/test_mutation.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ def mutate_and_get_payload(self, info, what, client_mutation_id=None):
3131
return SaySomething(phrase=str(what))
3232

3333

34+
class FixedSaySomething(object):
35+
__slots__ = 'phrase',
36+
37+
def __init__(self, phrase):
38+
self.phrase = phrase
39+
40+
41+
class SaySomethingFixed(ClientIDMutation):
42+
43+
class Input:
44+
what = String()
45+
46+
phrase = String()
47+
48+
@staticmethod
49+
def mutate_and_get_payload(self, info, what, client_mutation_id=None):
50+
return FixedSaySomething(phrase=str(what))
51+
52+
3453
class SaySomethingPromise(ClientIDMutation):
3554

3655
class Input:
@@ -71,6 +90,7 @@ class RootQuery(ObjectType):
7190

7291
class Mutation(ObjectType):
7392
say = SaySomething.Field()
93+
say_fixed = SaySomethingFixed.Field()
7494
say_promise = SaySomethingPromise.Field()
7595
other = OtherMutation.Field()
7696

@@ -152,7 +172,14 @@ def test_node_query():
152172
assert executed.data == {'say': {'phrase': 'hello'}}
153173

154174

155-
def test_node_query():
175+
def test_node_query_fixed():
176+
executed = schema.execute(
177+
'mutation a { sayFixed(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
178+
)
179+
assert "Cannot set client_mutation_id in the payload object" in str(executed.errors[0])
180+
181+
182+
def test_node_query_promise():
156183
executed = schema.execute(
157184
'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
158185
)

graphene/relay/tests/test_node.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from graphql_relay import to_global_id
44

55
from ...types import ObjectType, Schema, String
6-
from ..node import Node
6+
from ..node import Node, is_node
77

88

99
class SharedNodeFields(object):
@@ -46,11 +46,14 @@ class RootQuery(ObjectType):
4646
only_node = Node.Field(MyNode)
4747
only_node_lazy = Node.Field(lambda: MyNode)
4848

49+
4950
schema = Schema(query=RootQuery, types=[MyNode, MyOtherNode])
5051

5152

5253
def test_node_good():
5354
assert 'id' in MyNode._meta.fields
55+
assert is_node(MyNode)
56+
assert not is_node(object)
5457

5558

5659
def test_node_query():
@@ -70,6 +73,15 @@ def test_subclassed_node_query():
7073
[('shared', '1'), ('extraField', 'extra field info.'), ('somethingElse', '----')])})
7174

7275

76+
def test_node_requesting_non_node():
77+
executed = schema.execute(
78+
'{ node(id:"%s") { __typename } } ' % Node.to_global_id("RootQuery", 1)
79+
)
80+
assert executed.data == {
81+
'node': None
82+
}
83+
84+
7385
def test_node_query_incorrect_id():
7486
executed = schema.execute(
7587
'{ node(id:"%s") { ... on MyNode { name } } }' % "something:2"

0 commit comments

Comments
 (0)