Dataloader plugin resolve info #291
-
I was wondering if it makes sense or is possible to add graphql resolve info as like a 3rd parameter on the dataloader load function. Something like this... const User = builder.loadableObject('User', {
load: (ids: string[], context: ContextType, info: GraphQLResolveInfo) => context.loadUsersById(ids, getSelectedFieldsFromInfo(info)),
fields: (t) => ({
id: t.exposeID('id', {}),
username: t.exposeString('username', {}),
}),
}); The use case here being avoiding over fetching from the underlying datasource by knowing which fields have been selected in this graphql query. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
No, I omitting info is intentional. The info object is specific to a field, while loading an entity through a data-loader is designed may be loading that entity for multiple fields concurrently, or the result may be re-used for another field in the future. This means that any info object provided here would apply to once instance/use of the field, but would not necissarily apply to every field that loader/id combination may apply to. Not sure if my explanation makes sense. |
Beta Was this translation helpful? Give feedback.
-
@ericjohney, How did you tackle this? reservoirCollection: t.loadable({
type: ReservoirCollection,
resolve: (parent) => {
return parent.address;
},
load: async (addresses: string[]) => {
// How to get chainId which is argument of the grand parent query?
const data = await reservoirClient.getNftsCollectionDetails(chainId, {
contract: addresses,
});
return data.collections;
},
}), Is there any existing feature that I missed? @hayes |
Beta Was this translation helpful? Give feedback.
No, I omitting info is intentional. The info object is specific to a field, while loading an entity through a data-loader is designed may be loading that entity for multiple fields concurrently, or the result may be re-used for another field in the future. This means that any info object provided here would apply to once instance/use of the field, but would not necissarily apply to every field that loader/id combination may apply to.
Not sure if my explanation makes sense.