-
Thanks for the useful library. This is part of my code. I tried to separate the resolver as a separate function, but could not do so because the types of query, root, args, etc., and the return type were unknown. Sorry if this is a duplicate of these issues. builder.prismaNode('Article', {
id: { field: 'databaseId' },
fields: (t) => ({
databaseId: t.exposeInt('databaseId'),
title: t.exposeString('title', { nullable: true }),
text: t.exposeString('text', { nullable: true }),
createdAt: t.expose('createdAt', { type: 'DateTime' }),
isLiked: t.field({
type: 'Boolean',
resolve: (root, args, ctx) =>
prisma.article
.findUnique({
where: {
databaseId: root.databaseId,
},
})
.articleLikes()
.then((likes) => {
if (likes === null) return false;
return likes.length > 0;
}),
}),
creator: t.prismaField({
type: 'Creator',
nullable: true,
resolve: (query, root, args, ctx, info) => {
if (root.creatorId === null) {
return null;
}
return prisma.creator.findUnique({
...query,
where: {
databaseId: root.creatorId,
},
});
},
}),
attachments: t.prismaField({
type: ['ArticleAttachment'],
resolve: (query, root, args) =>
prisma.article
.findUnique({
where: {
databaseId: root.databaseId,
},
})
.articleAttachments({ ...query })
.then((attachments) => attachments || []),
}),
comments: t.prismaConnection({
type: 'Comment',
cursor: 'databaseId',
resolve: (query, parent, args, context, info) =>
prisma.article
.findUnique({
where: { databaseId: parent.databaseId },
})
.comments({ ...query })
.then((comments) => comments || []),
}),
}),
}); |
Beta Was this translation helpful? Give feedback.
Answered by
hayes
May 3, 2023
Replies: 1 comment 1 reply
-
You can use Eg: const Article = builder.prismaNode('Article', {
...
});
builder.prismaObjectFields(Article, (t) => ({
title: t.exposeString('title', { nullable: true }),
}))
builder.prismaObjectField(Article, 'title', (t) => t.exposeString('title', { nullable: true })) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
touyu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
builder.prismaObjectField(s)
to add more fields to an existing type.Eg: