From b9695c877abaf8a22d78ccb06f4c5be86de1f38d Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 31 May 2016 20:55:01 -0700 Subject: [PATCH] Fixed ClientIDMutation GraphQL type name. Fixed #148 --- graphene/relay/tests/test_types.py | 34 ++++++++++++++++++++++++++++++ graphene/relay/types.py | 2 ++ 2 files changed, 36 insertions(+) diff --git a/graphene/relay/tests/test_types.py b/graphene/relay/tests/test_types.py index ff510cab..5b1dc6f7 100644 --- a/graphene/relay/tests/test_types.py +++ b/graphene/relay/tests/test_types.py @@ -66,3 +66,37 @@ def test_node_connection_should_have_edge(): edges_type = connection_fields['edges'].type assert isinstance(edges_type, GraphQLList) assert edges_type.of_type == schema.T(edge) + + +def test_client_mutation_id(): + class RemoveWidget(relay.ClientIDMutation): + + class Input: + id = graphene.String(required=True) + + deletedWidgetID = graphene.String() + + @classmethod + def mutate_and_get_payload(cls, input, info): + pass + + graphql_type = schema.T(RemoveWidget) + assert graphql_type.name == 'RemoveWidgetPayload' + + +def test_client_mutation_id_with_name(): + class RemoveWidget(relay.ClientIDMutation): + class Meta: + type_name = 'RemoveWidgetCustomPayload' + + class Input: + id = graphene.String(required=True) + + deletedWidgetID = graphene.String() + + @classmethod + def mutate_and_get_payload(cls, input, info): + pass + + graphql_type = schema.T(RemoveWidget) + assert graphql_type.name == 'RemoveWidgetCustomPayload' diff --git a/graphene/relay/types.py b/graphene/relay/types.py index 2e0391ed..3ab55770 100644 --- a/graphene/relay/types.py +++ b/graphene/relay/types.py @@ -176,6 +176,8 @@ class RelayMutationMeta(MutationMeta): if not cls._meta.abstract: assert hasattr( cls, 'mutate_and_get_payload'), 'You have to implement mutate_and_get_payload' + if 'type_name' not in cls._meta.original_attrs: + cls._meta.type_name = '{}Payload'.format(cls.__name__) return cls def construct_arguments(cls, items):