Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/graphql/schema/member/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def add_super_method(field_key, method_name)
ERR
end
default_resolve_module.module_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method_name}(**args)
# method_name can be a hash_key (see lib/graphql/schema/field.rb)
# so we need to make a raw define_method :sym call to avoid crashing
# on hash keys like :'some key with/weird-chars'
define_method #{method_name.inspect} do |**args|
field_inst = self.class.fields[#{field_key}] || raise(%|Failed to find field #{field_key} for \#{self.class} among \#{self.class.fields.keys}|)
field_inst.resolve_field_method(self, args, context)
end
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/schema/member/has_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def int
field :string3, SubSubObjectWithStringField, null: false, method: :object
field :float1, ObjectWithFloatField, null: false, method: :object
field :float2, ObjectWithSubFloatField, null: false, method: :object
field :hash_key1, String, null: false, hash_key: :'foo bar/fizz-buzz'
end

class Schema < GraphQL::Schema
Expand Down