lawjolla
09/11/2018, 6:09 PM{ id users { id ...} }
string. Am I understanding it??schickling
09/11/2018, 6:23 PMprisma generate
3) You had to drop back to raw GraphQL to query related data. -> Now you can use the relational fluent API
Does this make it clearer?lawjolla
09/11/2018, 6:50 PMschickling
09/11/2018, 7:16 PM$delegate
support to the client, so it’s easy to migrate if you’d want.
Would love to hear your feedback once you’ve tried it though!lawjolla
09/11/2018, 9:14 PMUser
with likes..
type User {
id: ID!
email: String
name: String!
posts: [Post!]!
likes: [Like!]!
}
With bindings, you could still use the postsByUser
resolver with info
and get likes
returned...
postsByUser(root, args, context, info) {
return context.prisma.query.user({ where: {
id: args.userId
}}, info)
}
But the new Prisma Client, that doesn't seem possible. I'd need to make type resolvers for practically everything. What am I missing?Mike
09/11/2018, 9:18 PMposts: forwardTo('db')
?Mike
09/11/2018, 9:33 PMpostsByUser(root, args, context, info) {
return context.prisma.delegate.query.user({ where: {
id: args.userId
}}, info)
}
Basically, prisma.delegate
is the old prisma-bindings APIlawjolla
09/11/2018, 9:39 PMlawjolla
09/11/2018, 9:43 PMlawjolla
09/11/2018, 9:44 PMMike
09/11/2018, 9:54 PMlawjolla
09/11/2018, 10:15 PMMike
09/11/2018, 10:26 PMUser.posts
and Posts.author
, right? I think those can be skipped just by doing this. Just like before.
return context.prisma.$delegate.user({
where: id: args.userId,
}, info);
The only reason they’re adding all those boilerplate resolvers is because the new fluent API only returns scalar fields by default, just like prisma-binding does when you don’t pass anything for the info
prop. So because the root resolver returns an incomplete object, you need the secondary resolver to clean up its mess. All that nonsense can be avoided if you just stick to the old way of doing things with $delegate.lawjolla
09/11/2018, 10:26 PMMike
09/11/2018, 10:27 PMinfo
prop. Because then I have to create a custom string to pass as info with something like this:
const chatRooms = await prisma.query.chatRooms({
where: {
city: { users_some: usersInput },
messages_some: {
createdAt_gte: cutoffTime,
sender: usersInput,
},
},
}, `{
id
earliestMessage: messages(where: {
sender: { id_in: ${JSON.stringify(cluster)} }
}, orderBy: createdAt_ASC, first: 1) {
createdAt
}
}`);
lawjolla
09/11/2018, 10:28 PMMike
09/11/2018, 10:28 PMlawjolla
09/11/2018, 10:28 PM$delegate
because it feels like that’s just a bridge / escape hatchlawjolla
09/11/2018, 10:29 PM$delegate
for the beginner example?Mike
09/11/2018, 10:29 PMlawjolla
09/11/2018, 10:31 PM$delegate
is the default and the “Client” (sans $delegate) is the exception for most CRUD appsMike
09/11/2018, 10:32 PMlawjolla
09/11/2018, 10:33 PMMike
09/11/2018, 10:34 PMcontext.db
. That way I don’t have to change any existing code and I can add context.prisma
for the new cases where I need that.lawjolla
09/11/2018, 10:35 PMlawjolla
09/11/2018, 10:35 PMlawjolla
09/11/2018, 10:57 PM