graphql-ruby icon indicating copy to clipboard operation
graphql-ruby copied to clipboard

Redefined function arguments do not apply changes when subclassing

Open tylerjohnst opened this issue 8 years ago • 3 comments

When you subclass a custom function, the arguments function seems to merge in the incorrect direction which causes overridden arguments to be ignored. https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/function.rb#L73

require 'graphql'

TestInput = GraphQL::InputObjectType.define do
  name 'Test'
  argument :id, !types.ID
end

RedefinedTestInput = TestInput.redefine do
  name 'RedefinedTest'
  argument :name, !types.String
end

class TestFunc < GraphQL::Function
  argument :thing, !TestInput
end

class SubclassedTestFunc < TestFunc
  argument :thing, !RedefinedTestInput
end

puts TestFunc.arguments["thing"].inspect #=> Test!
puts SubclassedTestFunc.arguments["thing"].inspect #=> Test!
puts SubclassedTestFunc.send(:own_arguments)["thing"].inspect #=> RedefinedTest!

Is this the intended behavior?

tylerjohnst avatar Mar 08 '18 13:03 tylerjohnst

No, this isn't the intended behavior! Looks like a mess-up on my part and a lack of test coverage 😖

rmosolgo avatar Mar 09 '18 01:03 rmosolgo

Thanks for the great write-up, by the way.

rmosolgo avatar Mar 09 '18 01:03 rmosolgo

Sorry for the hangup here, I think GraphQL::Schema::Resolver will work for this.

rmosolgo avatar Aug 01 '18 20:08 rmosolgo