-
Hello there, I am trying to setup the federation plugin, and when trying to define the first entity type, I ran into an issue where I'm not able to resolve the resource. In our app we use a pattern where we add different data loaders to the context, which we then access in the resolvers. Please see the example below ⬇️ const MyType = builder.objectRef<MyType>('MyType').implement({
fields: (t) => ({
id: t.exposeID("id"),
randomField: t.field({
resolve: async (parent, _args, context) => {
const randomField =
await context.dataLoaders.randomFieldsSource.load(
parent.randomFieldId
);
return randomField;
},
nullable: true,
type: "MyTypeRandomField",
}),
}),
}); When setting up this type as an entity, I would like to be able to access that context and get the data from data loaders, something like this ⬇️ builder.asEntity(MyType, {
key: builder.selection<{ id: string }>('id'),
resolveReference: (parent, _, context) => context.dataLoaders.myTypeSource.load(parent.id),
}); Currently, the argument I can access for the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yep, this should definitely be added. I think this might not have been possible when I first wrote this plugin, but just checked, and federation definitely passes context now. There won't be an args option, but the args should be ( |
Beta Was this translation helpful? Give feedback.
Yep, this should definitely be added. I think this might not have been possible when I first wrote this plugin, but just checked, and federation definitely passes context now. There won't be an args option, but the args should be (
parent
,context
,info
). I'll update the types, but the args should already be passed to your resolve method, just not in the type definitions yet.