Skip to content

Commit 6bd03d5

Browse files
committed
Added clientMutationId field to relay.ClientIDMutation. Fixed #300
1 parent 8128292 commit 6bd03d5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

examples/starwars_relay/tests/test_objectidentification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_str_schema():
2525
type IntroduceShipPayload {
2626
ship: Ship
2727
faction: Faction
28+
clientMutationId: String
2829
}
2930
3031
type Mutation {

graphene/relay/mutation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def __new__(cls, name, bases, attrs):
2121

2222
input_class = attrs.pop('Input', None)
2323
base_name = re.sub('Payload$', '', name)
24+
if 'client_mutation_id' not in attrs:
25+
attrs['client_mutation_id'] = String(name='clientMutationId')
2426
cls = ObjectTypeMeta.__new__(cls, '{}Payload'.format(base_name), bases, attrs)
2527
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
2628
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:

graphene/relay/tests/test_mutation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ class MyMutation(ClientIDMutation):
7171

7272
def test_mutation():
7373
fields = SaySomething._meta.fields
74-
assert list(fields.keys()) == ['phrase']
74+
assert list(fields.keys()) == ['phrase', 'client_mutation_id']
7575
assert isinstance(fields['phrase'], Field)
7676
field = SaySomething.Field()
7777
assert field.type == SaySomething
7878
assert list(field.args.keys()) == ['input']
7979
assert isinstance(field.args['input'], Argument)
8080
assert isinstance(field.args['input'].type, NonNull)
8181
assert field.args['input'].type.of_type == SaySomething.Input
82+
assert isinstance(fields['client_mutation_id'], Field)
83+
assert fields['client_mutation_id'].name == 'clientMutationId'
84+
assert fields['client_mutation_id'].type == String
8285

8386

8487
def test_mutation_input():
@@ -94,7 +97,7 @@ def test_mutation_input():
9497

9598
def test_subclassed_mutation():
9699
fields = OtherMutation._meta.fields
97-
assert list(fields.keys()) == ['name', 'my_node_edge']
100+
assert list(fields.keys()) == ['name', 'my_node_edge', 'client_mutation_id']
98101
assert isinstance(fields['name'], Field)
99102
field = OtherMutation.Field()
100103
assert field.type == OtherMutation
@@ -126,7 +129,7 @@ def test_subclassed_mutation_input():
126129

127130
def test_edge_query():
128131
executed = schema.execute(
129-
'mutation a { other(input: {clientMutationId:"1"}) { myNodeEdge { cursor node { name }} } }'
132+
'mutation a { other(input: {clientMutationId:"1"}) { clientMutationId, myNodeEdge { cursor node { name }} } }'
130133
)
131134
assert not executed.errors
132-
assert dict(executed.data) == {'other': {'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}
135+
assert dict(executed.data) == {'other': {'clientMutationId': '1', 'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}

0 commit comments

Comments
 (0)