tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

DSL compiler for `GraphQL::Schema::ObjectType`

Open JacobyJoukema opened this issue 1 year ago • 0 comments

When using field in GraphQL object types, new methods are created in the class dynamically. In certain occasions, like in batch loading, we need to be able to refer to those methods and avoid type checking errors.

class MyType < GraphQL::Schema::Object
  field "foo", type: String

  class << self
    extend T::Sig

    sig { params(objects: T::Array[MyType]).void }
    def load_foo(objects)
      objects.each { |obj| obj.foo = "hello!" }
                              # ^ error: foo doesn't exist on MyType
    end
  end
end

JacobyJoukema avatar Jun 13 '24 13:06 JacobyJoukema