Replies: 1 comment
-
The basic problem here is that when you return values in this resolver: builder.objectType('Route', {
description: '',
fields: (t) => ({
node: t.field({
type: Node,
nullable: true,
resolve: async (parent, args, ctx, info) => ({}),
}),
}),
}); GraphQL (and Pothos) only knows that the returned values are Nodes, but not what kind of nodes. I see you tried to implement your own builder.interfaceType(Node, {
name: 'NodeClass',
fields: (t) => ({
id: t.field({
type: 'ID',
nullable: true,
resolve: (parent) => parent.id,
}),
}),
resolveType: (value) => {
if (value instanceof Node) {
return 'Node';
}
return null;
},
}); that adds a resolveType method. This method would get each object returned from the resolver mentioned above, and should be determining if the node is a I'm also not sure if the relay plugin currently handle just defining your own node interface like that (There is still an easy way to set the resolveType method for the interface). Instead of trying to write a
This means that if you add an What you can do instead is "brand" the objects after you load them. This isn't documented in the plugin docs yet, but prismaRefs have a method that makes this easy: const Page = builder.prismaNode('Page', {...});
const Post = builder.prismaNode('Post {...});
builder.objectType('Route', {
description: '',
fields: (t) => ({
node: t.field({
type: Node,
nullable: true,
resolve: async (parent, args, ctx, info) => {
const pages = await prisma.page.findMany({where: { ... } });
const posts = await prisma.post.findMany({where: { ... } });
return [...Page.addBrand(pages), ...Post.addBrand(posts)];
},
}),
}),
}); Branding the objects like this will allow the default |
Beta Was this translation helpful? Give feedback.
-
i have a problem with prismaNode and interfaces who can help me?
Beta Was this translation helpful? Give feedback.
All reactions