Dependency variable

The dependency description for a GraphQL object type — an alias for GraphQLDependency.create(), and the intended way to reach every method on this package's API.

Signature:

Dependency: typeof GraphQLDependency.create

Remarks

Reads as a static constructor at the call site, but it is a lookup: the description is created on first use and the same one is returned afterwards. That is what allows Dependency(SomeType) to appear in as many modules as is convenient — a loader beside the type, requirements beside the relation, a load() in the resolver — and still describe one type once.

Example

Dependency(UserType).require(CompanyType, () => ({
    as: UserType.getFields().company,
    filter: {
        // the key belongs to CompanyType's loader filter, the value is the
        // field on UserType whose values fill it
        [CompanyType.getFields().id.name]:
            UserType.getFields().companyId,
    },
}));

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.