Ishan Chhabra
07/21/2022, 6:26 AM{include: true}
a relation in prisma only when that field is asked in GraphQL query?
Say I have a Book table and an Author table. Book and Author are related.
I have a GQL Query
books {
name
author {
name
}
}
This resolves with const books = await prisma.book.findMany({include: {author: true}})
. What if I did not ask for the author? Although Graphql wont send it to client, I would like to avoid that unnecessary join on orm level.
I can use the info param of resolver function to see if that field was asked and conditionally use include in prisma but that is not scalable and kills the dx.
I thought if resolver chains could help. But am not sure how to go about it. Any help is much appreciated. Thank you!Jared Fraser
07/21/2022, 6:56 AMauthor
separately from the book.
const resolvers = {
Query: {
books() { return prisma.book.findMany()
}
Book: {
author(parent, args, context, info) {
return prisma.authors.findOne({ id: parent.author_id})
}
}
}
Ishan Chhabra
07/21/2022, 7:00 AMIshan Chhabra
07/21/2022, 7:06 AMJared Fraser
07/21/2022, 7:15 AMJared Fraser
07/21/2022, 7:16 AMIshan Chhabra
07/21/2022, 7:21 AMJared Fraser
07/21/2022, 7:31 AMIshan Chhabra
07/21/2022, 7:46 AMnikolasburk
PrismaSelect
for this š
https://paljs.com/plugins/select/Ishan Chhabra
07/21/2022, 7:59 AMJared Fraser
07/21/2022, 8:04 AM