dataloaderpackage and the giraphql dataloader plugin:
loadin an order that exactly matches the order of the requested IDs. The order is used to map results to their IDs, and if the results are returned in a different order, your GraphQL requests will end up with the wrong data. Correctly sorting results returned from a database or other data source can be tricky, so there this plugin has a
sortoption (described below) to simplify the sorting process. For more details on how the load function works, see the dataloader docs.
Users, you will now be able to return either a
string(based in ids param of
load), or a User object (type based on the return type of
bigint(typescript will constrain the allowed types to whatever is expected by the load function). If a resolver returns an object instead, GiraphQL knows it can skip the dataloader for that object.
t.loadablemethod for defining fields with their own dataloaders.
(Type | Error). Your
loadfunction may also return results in that format if your loader can have parital failures. GraphQL does not have special handling for Error objects. Instead GiraphQL will map these results to something like
(Type | Promise<Type>)where Errors are replaced with promises that will be rejected. This allows the normal graphql resolver flow to correctly handle these errors.
loadManymethod from a dataloader manually, you can apply the same mapping using the
loadableNodethat gets added to the builder. You can use this method to create
nodeobjects that work like other loadeble objects.
cacheResolvedoption takes a function that converts the loaded object into it's cache Key:
loadfunction must return results in the same order as the provided array of IDs. Doing this correctly can be a little complicated, so this plugin includes an alternative. For any type or field that creates a dataloader, you can also provide a
sortoption which will correctly map your results into the correct order based on their ids. To do this, you will need to provide a function that accepts a result object, and returns its id.
sortoption should NOT be used for cases where the result list is expected to contain errors.
sortyou can use a