Repository navigation
Prisma filtering list of relations not working ( logging correct return value inside log on server but appollo explorer & postman getting incorrect values) #24340
Replies: 1 comment
|
If In GraphQL, if your schema defines a field resolver for that relation (e.g., To verify, check your resolver map for that model. If you already loaded the filtered relation in the parent query, your child field resolver should just return the parent property: User: {
posts: (parent) => parent.posts, // reuse preloaded filtered data
}If you don't define custom child resolvers, ensure Apollo Server's cache or DataLoader isn't re-fetching by ID. If this points you right to the culprit in your resolvers, toss an answer mark on it. |
Uh oh!
There was an error while loading. Please reload this page.
Bug description
I noticed this in my main project so downloaded the prisma example graphql-subscriptions from the github to see if I can reproduce and it appears to be happening their aswell. I'm trying to get the users and include only their posts which have published set to true. I've followed the steps outlined here - https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries#filter-a-list-of-relations: https://www.prisma.io/docs/orm/prisma-client/queries/relation-queries#filter-a-list-of-relations and setup this query:
The result through postman and appollo explorer includes the posts with published true but weirdly when I console.log what the value should be inside of my server I get the correct response which has the filtered out published false posts.
I tried doing it other methods like this:
How to reproduce
.nonNull.list.nonNull.field('allUsers2', {
type: 'User',
resolve: (_parent, _args, context: Context) => {
return context.prisma.user.findMany({
include: {
posts: {
where: {
published: true
}
}
}
});
},
});
allUsers2 {
id
posts {
id
published
}
name
}
}
posts with published true are returned when they shouldn't be.
Add a console.log for theresults inside the project and notice how the correct values are returned.
Expected behavior
Should be giving filtered results without posts that are published false
Prisma information
Environment & setup
Prisma Version
All reactions