Shopify / tapioca

The swiss army knife of RBI generation
MIT License
728 stars 121 forks source link

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

Open JacobyJoukema opened 3 months ago

JacobyJoukema commented 3 months ago

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