idLengthfields to both of the object types. The
ObjectReftype is what is returned when creating an object (or when calling
builder.objectRef). It takes 2 generic parameters: The first is the shape a resolver is expected to resolve to for that type, and the second is the shape of the parent arg when defining a field on that type. These 2 are generally the same, but can differ for some special cases (like with
loadableObjectfrom the dataloader plugin, which allows resolvers to resolve to an
IDrather than the actual object). In this case, we only care about the second parameter since we are defining fields.
InterfaceRefinstead. If your helper accepts both, you can differentiate the refs by using
ref.kindwhich will be either
SchemaTypesare the types that will be provided to the builder when it is created. Internally GiraphQL extends these with some default types. This extened set of types is what gets passed around in many of GiraphQLs internal types. To correctly type our helper function, we need to create a version of
SchemaTypeswith the same defaults GiraphQL adds in (
TypesWithDefaults). Once we have
TypesWithDefaultswe can define a helper function that accepts an arg builder (
ArgBuilder<TypesWithDefaults>) and creates a set of arguments.
t.arg(the arg builder), and spread the returned args into the args object for the current field.