Skip to content

Commit 50b9ef8

Browse files
committed
Fix InputObjectType input_fields options
Both `Mutation` and `InputObjectType` input_fields already use `Define::AssignArgument`, which should be the only way to create `Argument`s. But when a `Mutation` builds its `InputObjectType`, it recreates `Argument`s (`input_field`s) using properties from the `Mutation`'s own `Argument`s. It needs to explicitly copy all the options from one argument to another, which caused rmosolgo#650. This PR gets rid of this recreation process and just merges the `Mutation`'s `input_fields` into the new `InputObjectType`'s `input_fields`. This change should prevent any divergence between fields and mutation arguments/input_fields.
1 parent 756373a commit 50b9ef8

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

lib/graphql/input_object_type.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def kind
5555
GraphQL::TypeKinds::INPUT_OBJECT
5656
end
5757

58+
def merge_input_fields!(input_fields)
59+
@arguments.merge!(input_fields)
60+
end
61+
5862
def validate_non_null_input(input, warden)
5963
result = GraphQL::Query::InputValidationResult.new
6064

lib/graphql/relay/mutation.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,15 @@ def return_type
163163
def input_type
164164
@input_type ||= begin
165165
relay_mutation = self
166-
GraphQL::InputObjectType.define do
166+
input_object_type = GraphQL::InputObjectType.define do
167167
name("#{relay_mutation.name}Input")
168168
description("Autogenerated input type of #{relay_mutation.name}")
169169
input_field :clientMutationId, types.String, "A unique identifier for the client performing the mutation."
170-
relay_mutation.arguments.each do |input_field_name, field_obj|
171-
kwargs = {}
172-
kwargs[:default_value] = field_obj.default_value if field_obj.default_value?
173-
kwargs[:as] = field_obj.as
174-
input_field(input_field_name, field_obj.type, field_obj.description, **kwargs)
175-
end
176170
mutation(relay_mutation)
177171
end
172+
input_object_type.merge_input_fields!(input_fields)
173+
174+
input_object_type
178175
end
179176
end
180177

spec/graphql/schema/printer_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,11 @@
403403
404404
# Autogenerated input type of CreatePost
405405
input CreatePostInput {
406-
# A unique identifier for the client performing the mutation.
407-
clientMutationId: String
408406
title: String!
409407
body: String!
408+
409+
# A unique identifier for the client performing the mutation.
410+
clientMutationId: String
410411
}
411412
412413
# Autogenerated return type of CreatePost
@@ -537,10 +538,11 @@
537538
538539
# Autogenerated input type of CreatePost
539540
input CreatePostInput {
540-
# A unique identifier for the client performing the mutation.
541-
clientMutationId: String
542541
title: String!
543542
body: String!
543+
544+
# A unique identifier for the client performing the mutation.
545+
clientMutationId: String
544546
}
545547
546548
# Autogenerated return type of CreatePost

0 commit comments

Comments
 (0)