Ionut Achim
03/09/2019, 10:53 PMconst newUserWithLinks = await prisma
.createUser({
name: "Alice",
email: "<mailto:alice@prisma.io|alice@prisma.io>",
password: "IlikeTurtles",
links: {
create: [{
description: "My first link",
url: "<https://www.prisma.io>"
}, {
description: "My second link",
url: "<https://www.howtographql.com>"
}]
},
})
After checking the created documents, with the mongo shell, I can see the user document has a links
property which is an array containing the two newly created link IDs. All good, but when I check the links
documents I don't see any postedBy
property nor any other property that points back to the user.
My question is - how does Prisma resolve the postedBy
field?Wendell Misiedjan
03/09/2019, 11:47 PMWendell Misiedjan
03/09/2019, 11:47 PMIonut Achim
03/10/2019, 7:47 AMtype Link {
id: ID! @id
description: String!
url: String!
postedBy: User!
votes: [Vote!]! @relation(link: INLINE)
}
type User {
id: ID! @id
name: String!
email: String! @unique
password: String!
links: [Link!]! @relation(link: INLINE)
votes: [Vote!]! @relation(link: INLINE)
}
type Vote {
id: ID! @id
link: Link!
user: User!
}
Ionut Achim
03/10/2019, 7:49 AM@relation
directive to the other end, it will save the reference there - so links will have a postedBy
property pointing to the user but the user won't have the links
property anymoreIonut Achim
03/10/2019, 7:50 AMprisma.links().postedBy()
I get back the user.Ionut Achim
03/10/2019, 7:55 AMdo4gr
User
and will do a lookup query if you’re trying to traverse the relation coming from the other side Vote
. Something like find all Users
who have the id of Vote
in their votes
field. The votes
field is then also indexed for better performance. This is why the side you have the link:INLINE
on can be important for performance.Ionut Achim
03/12/2019, 9:12 PM