Skip to content

Commit 87eeaae

Browse files
authored
Merge pull request #3965 from rmosolgo/mutation-type-fix
Fix mutation type(...) config
2 parents e63ee22 + 250d76d commit 87eeaae

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/graphql/schema/resolver/has_payload_type.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ def payload_type(new_payload_type = nil)
2020
@payload_type ||= generate_payload_type
2121
end
2222

23-
# alias :type :payload_type
23+
def type(new_type = nil, null: nil)
24+
if new_type
25+
payload_type(new_type)
26+
if !null.nil?
27+
self.null(null)
28+
end
29+
else
30+
super()
31+
end
32+
end
33+
2434
alias :type_expr :payload_type
2535

2636
def field_class(new_class = nil)

spec/graphql/schema/mutation_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,15 @@ class Mutation < GraphQL::Schema::Object
215215
result = InterfaceMutationSchema.execute("mutation { signIn(login: \"abc\", password: \"abc\") { success } }")
216216
assert_equal true, result["data"]["signIn"]["success"]
217217
end
218+
219+
it "returns manually-configured return types" do
220+
mutation = Class.new(GraphQL::Schema::Mutation) do
221+
graphql_name "DoStuff"
222+
type(String)
223+
end
224+
225+
field = GraphQL::Schema::Field.new(name: "f", owner: nil, resolver_class: mutation)
226+
assert_equal "String", field.type.graphql_name
227+
assert_equal GraphQL::Types::String, field.type
228+
end
218229
end

0 commit comments

Comments
 (0)