-
I'm considering the following structure. I want to make a call to another function in resolve, but I don't know the type of query or args. If the contents of queries and args are simple and few, I think it is enough to take out the contents and define them as arguments, but if there are many of them, it is difficult to enumerate them as arguments. Is there a better way? builder.queryFields((t) => ({
articles: t.prismaConnection({
type: 'Article',
cursor: 'databaseId',
args: {
where: t.arg({
type: ArticleWhere,
}),
orderBy: t.arg({
type: ArticleOrderBy,
defaultValue: {
createdAt: 'desc',
},
}),
},
resolve: (query, parent, args, ctx, info) => {
return articleService.getAll(query, args);
},
}),
}));
---
class ArticleService {
getAll(query: ?, args: ?) {
return prisma.article.findMany({
...query,
where: {
deletedAt: null,
...args.where,
},
orderBy: args.orderBy ?? undefined,
});
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There isn't a a perfect solution here, but there are a few options. I personally tend to use the singular builder.qyeryField when I want to isolate the resolver for one field. This is the easiest option, but doesn't always work. If you want to create something reusable that takes just some of the args, you can use utils like: #735 This allows you to get the types of input objects without redefining everything. Just a heads up here, the generic type signature of refs will change slightly in 4.0 If you want the full args types, you probably need to hoist your args out of the field definitions. You can use |
Beta Was this translation helpful? Give feedback.
There isn't a a perfect solution here, but there are a few options.
I personally tend to use the singular builder.qyeryField when I want to isolate the resolver for one field. This is the easiest option, but doesn't always work.
If you want to create something reusable that takes just some of the args, you can use utils like: #735
This allows you to get the types of input objects without redefining everything. Just a heads up here, the generic type signature of refs will change slightly in 4.0
If you want the full args types, you probably need to hoist your args out of the field definitions. You can use
const YourArgs = builder.args(t => ({argName: t.string() }))
to build an args object a…