Skip to content

Commit 37a6c01

Browse files
authored
Merge pull request #855 from cherls/default-mutation-field-description
Default mutation field description
2 parents 80066e5 + 8e53672 commit 37a6c01

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

graphene/types/mutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def Field(
8585
args=cls._meta.arguments,
8686
resolver=cls._meta.resolver,
8787
name=name,
88-
description=description,
88+
description=description or cls._meta.description,
8989
deprecation_reason=deprecation_reason,
9090
required=required,
9191
)

graphene/types/tests/test_mutation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,41 @@ def mutate(self, info, name):
139139

140140
class MyMutation(ObjectType):
141141
create_user = CreateUser.Field(
142+
name="createUser",
142143
description="Create a user",
143144
deprecation_reason="Is deprecated",
144145
required=True,
145146
)
146147

147148
field = MyMutation._meta.fields["create_user"]
149+
assert field.name == "createUser"
148150
assert field.description == "Create a user"
149151
assert field.deprecation_reason == "Is deprecated"
150152
assert field.type == NonNull(CreateUser)
151153

152154

155+
def test_mutation_default_args_output():
156+
class CreateUser(Mutation):
157+
"""Description."""
158+
159+
class Arguments:
160+
name = String()
161+
162+
name = String()
163+
164+
def mutate(self, info, name):
165+
return CreateUser(name=name)
166+
167+
class MyMutation(ObjectType):
168+
create_user = CreateUser.Field()
169+
170+
field = MyMutation._meta.fields["create_user"]
171+
assert field.name is None
172+
assert field.description == "Description."
173+
assert field.deprecation_reason is None
174+
assert field.type == CreateUser
175+
176+
153177
def test_mutation_as_subclass():
154178
class BaseCreateUser(Mutation):
155179
class Arguments:

0 commit comments

Comments
 (0)