-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow promises to be returned in a field in the resolver of connection #853
Comments
I am also getting the same Errors on multiple resolvers and I don't understand what I am doing wrong.. but the queries and mutations are working |
It depends on the situation. In my case, the property getters return promises. But the generated types don't allow promises to be returned and expect the value itself. If it's the same scenario for you, adding a I could probably get into fixing this issue later this week as well. |
Yeah, if you want to see if there’s a reasonable fix for this one, that’d be great. I remember trying to do this genetically at one point early on (making all obj properties Might try and think about this a bit more sometime soon and see if there’s a good middle ground. |
I've been facing the exact issue described in the initial comment. Trying to use the prisma fluent api results is a type error if the relation is one-to-many, meaning an array is returned instead of a single object. So for example the following works fine with no errors: export const Link = objectType({
name: "Link",
definition(t) {
t.nonNull.int("id");
t.field("postedBy", {
type: "User",
resolve(parent, args, context) {
return context.prisma.link
.findUnique({ where: { id: parent.id } })
.postedBy();
},
});
},
}); This on the other hand won't compile unless I provide the export const User = objectType({
name: "User",
definition(t) {
t.nonNull.int("id");
t.nonNull.list.nonNull.field("links", {
type: "Link",
resolve(parent, args, context) {
return context.prisma.user
.findUnique({ where: { id: parent.id } })
.links();
},
});
},
}); If I'm doing something wrong I would really appreciate being pointed in the right direction for a fix |
The below example would return a type error because the return type of the edges field is expected to be
{cursor: string, node: Bar}
andPromise<{cursor: string, node: Bar}>
is not allowed. However, a query that requests for those edges will resolve without any error.Why return a Promise in the getter of edges in the first place?
Say, we need to get a list of items from a database and parse that through a utility function that creates a cursor for that record. If we directly
await
the query to get the list of items, then we lose the ability to batch the requests using something like dataloader, or Prismas Fluent API (which uses the dataloader pattern). Instead, we can return a promise for the edges field that waits for the response from the database, parse that through our utility function to get the cursor, and resolve the promise.An alternative is to just use the
nodes()
function, but then implementing a resolver for the entire connection wouldn't be possible in this scenario.I'm sorry for the bad example, let me know if you'd like a better one 🙂
The text was updated successfully, but these errors were encountered: