mirror of
https://github.com/graphql-python/graphene.git
synced 2025-06-20 13:33:10 +03:00
Added clientMutationId field to relay.ClientIDMutation. Fixed #300
This commit is contained in:
parent
8128292b02
commit
6bd03d59d7
|
@ -25,6 +25,7 @@ input IntroduceShipInput {
|
||||||
type IntroduceShipPayload {
|
type IntroduceShipPayload {
|
||||||
ship: Ship
|
ship: Ship
|
||||||
faction: Faction
|
faction: Faction
|
||||||
|
clientMutationId: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
|
|
|
@ -21,6 +21,8 @@ class ClientIDMutationMeta(ObjectTypeMeta):
|
||||||
|
|
||||||
input_class = attrs.pop('Input', None)
|
input_class = attrs.pop('Input', None)
|
||||||
base_name = re.sub('Payload$', '', name)
|
base_name = re.sub('Payload$', '', name)
|
||||||
|
if 'client_mutation_id' not in attrs:
|
||||||
|
attrs['client_mutation_id'] = String(name='clientMutationId')
|
||||||
cls = ObjectTypeMeta.__new__(cls, '{}Payload'.format(base_name), bases, attrs)
|
cls = ObjectTypeMeta.__new__(cls, '{}Payload'.format(base_name), bases, attrs)
|
||||||
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
|
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
|
||||||
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
|
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
|
||||||
|
|
|
@ -71,7 +71,7 @@ def test_no_mutate_and_get_payload():
|
||||||
|
|
||||||
def test_mutation():
|
def test_mutation():
|
||||||
fields = SaySomething._meta.fields
|
fields = SaySomething._meta.fields
|
||||||
assert list(fields.keys()) == ['phrase']
|
assert list(fields.keys()) == ['phrase', 'client_mutation_id']
|
||||||
assert isinstance(fields['phrase'], Field)
|
assert isinstance(fields['phrase'], Field)
|
||||||
field = SaySomething.Field()
|
field = SaySomething.Field()
|
||||||
assert field.type == SaySomething
|
assert field.type == SaySomething
|
||||||
|
@ -79,6 +79,9 @@ def test_mutation():
|
||||||
assert isinstance(field.args['input'], Argument)
|
assert isinstance(field.args['input'], Argument)
|
||||||
assert isinstance(field.args['input'].type, NonNull)
|
assert isinstance(field.args['input'].type, NonNull)
|
||||||
assert field.args['input'].type.of_type == SaySomething.Input
|
assert field.args['input'].type.of_type == SaySomething.Input
|
||||||
|
assert isinstance(fields['client_mutation_id'], Field)
|
||||||
|
assert fields['client_mutation_id'].name == 'clientMutationId'
|
||||||
|
assert fields['client_mutation_id'].type == String
|
||||||
|
|
||||||
|
|
||||||
def test_mutation_input():
|
def test_mutation_input():
|
||||||
|
@ -94,7 +97,7 @@ def test_mutation_input():
|
||||||
|
|
||||||
def test_subclassed_mutation():
|
def test_subclassed_mutation():
|
||||||
fields = OtherMutation._meta.fields
|
fields = OtherMutation._meta.fields
|
||||||
assert list(fields.keys()) == ['name', 'my_node_edge']
|
assert list(fields.keys()) == ['name', 'my_node_edge', 'client_mutation_id']
|
||||||
assert isinstance(fields['name'], Field)
|
assert isinstance(fields['name'], Field)
|
||||||
field = OtherMutation.Field()
|
field = OtherMutation.Field()
|
||||||
assert field.type == OtherMutation
|
assert field.type == OtherMutation
|
||||||
|
@ -126,7 +129,7 @@ def test_subclassed_mutation_input():
|
||||||
|
|
||||||
def test_edge_query():
|
def test_edge_query():
|
||||||
executed = schema.execute(
|
executed = schema.execute(
|
||||||
'mutation a { other(input: {clientMutationId:"1"}) { myNodeEdge { cursor node { name }} } }'
|
'mutation a { other(input: {clientMutationId:"1"}) { clientMutationId, myNodeEdge { cursor node { name }} } }'
|
||||||
)
|
)
|
||||||
assert not executed.errors
|
assert not executed.errors
|
||||||
assert dict(executed.data) == {'other': {'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}
|
assert dict(executed.data) == {'other': {'clientMutationId': '1', 'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user