Skip to content

Commit

Permalink
Fixed ClientIDMutation GraphQL type name. Fixed #148
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Jun 1, 2016
1 parent de424f7 commit b9695c8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions graphene/relay/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 2 additions & 0 deletions graphene/relay/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def construct(cls, *args, **kwargs):
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):
Expand Down

0 comments on commit b9695c8

Please sign in to comment.