Is it possible to have an indirect relations as connections in both directions/node? #1085
-
I was wondering if it's possible to have an indirect relations as connections in both directions/node. Following the example in the docs https://pothos-graphql.dev/docs/plugins/prisma#indirect-relations-as-connections would it be possible to have connection within Doing something that looks somewhat like this: // media.ts
import { Post } from './post.js'
import { builder } from './builder.js'
const postConnectionHelpers = prismaConnectionHelpers(
builder,
"PostMedia",
{
cursor: "id",
select: (nodeSelection) => ({
media: nodeSelection({
select: {
id: true,
posts: true,
},
}),
}),
resolveNode: (postMedia) => postMedia.posts,
}
);
const Media = builder.prismaObject("Media", {
select: {
id: true,
},
fields: (t) => ({
url: t.exposeString("url"),
post: t.connection({
type: Post,
select: (args, ctx, nestedSelection) => ({
posts: postConnectionHelpers.getQuery(args, ctx, nestedSelection),
}),
resolve: (media, args, ctx) =>
postConnectionHelpers.resolve(media.posts, args, ctx),
}),
}),
});
// post.ts
import { Media } from "./media.js";
import { builder } from "./builder.js";
const mediaConnectionHelpers = prismaConnectionHelpers(
builder,
"PostMedia", // this should be the the join table
{
cursor: "id",
select: (nodeSelection) => ({
media: nodeSelection({
select: {
id: true,
media: true,
},
}),
}),
resolveNode: (postMedia) => postMedia.media,
}
);
const Post = builder.prismaObject("Post", {
select: {
id: true,
},
fields: (t) => ({
content: t.exposeString("content"),
post: t.connection({
type: Media,
select: (args, ctx, nestedSelection) => ({
media: mediaConnectionHelpers.getQuery(args, ctx, nestedSelection),
}),
resolve: (post, args, ctx) =>
mediaConnectionHelpers.resolve(post.media, args, ctx),
}),
}),
}); As soon as I set the 'reverse' connection both of the # Media
'Media' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)
# Post
'Post' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Try adding the connection via builder.prismaObjectField |
Beta Was this translation helpful? Give feedback.
Try adding the connection via builder.prismaObjectField