Skip to content

Commit b9695c8

Browse files
committed
Fixed ClientIDMutation GraphQL type name. Fixed #148
1 parent de424f7 commit b9695c8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

graphene/relay/tests/test_types.py

+34
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,37 @@ def test_node_connection_should_have_edge():
6666
edges_type = connection_fields['edges'].type
6767
assert isinstance(edges_type, GraphQLList)
6868
assert edges_type.of_type == schema.T(edge)
69+
70+
71+
def test_client_mutation_id():
72+
class RemoveWidget(relay.ClientIDMutation):
73+
74+
class Input:
75+
id = graphene.String(required=True)
76+
77+
deletedWidgetID = graphene.String()
78+
79+
@classmethod
80+
def mutate_and_get_payload(cls, input, info):
81+
pass
82+
83+
graphql_type = schema.T(RemoveWidget)
84+
assert graphql_type.name == 'RemoveWidgetPayload'
85+
86+
87+
def test_client_mutation_id_with_name():
88+
class RemoveWidget(relay.ClientIDMutation):
89+
class Meta:
90+
type_name = 'RemoveWidgetCustomPayload'
91+
92+
class Input:
93+
id = graphene.String(required=True)
94+
95+
deletedWidgetID = graphene.String()
96+
97+
@classmethod
98+
def mutate_and_get_payload(cls, input, info):
99+
pass
100+
101+
graphql_type = schema.T(RemoveWidget)
102+
assert graphql_type.name == 'RemoveWidgetCustomPayload'

graphene/relay/types.py

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ def construct(cls, *args, **kwargs):
176176
if not cls._meta.abstract:
177177
assert hasattr(
178178
cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload'
179+
if 'type_name' not in cls._meta.original_attrs:
180+
cls._meta.type_name = '{}Payload'.format(cls.__name__)
179181
return cls
180182

181183
def construct_arguments(cls, items):

0 commit comments

Comments
 (0)