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
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.