ezeikel
03/07/2019, 1:19 AM// datamodel.prisma
type User {
id: ID! @id
firstName: String!
lastName: String!
username: String @unique
email: String! @unique
password: String!
posts: [Post!]! @relation(link: INLINE)
following: [User!]! @relation(name: "Following", link: INLINE)
followers: [User!]! @relation(name: "Followers", link: INLINE)
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type Post {
id: ID! @id
caption: String
image: String
published: Boolean @default(value: false)
author: User
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
My user
resolver looks like this:
user (_, { id }, ctx, info) {
return ctx.prisma.user({ id }, info);
},
If i try to query for a userโs posts:
{
user(id: "5c7c04e824aa9a0007495114") {
firstName
posts {
id
}
}
}
I get Cannot return null for non-nullable field User.posts.
and not sure why? I can see the data is there in the Posts
collection via Mongo Compass but dont seem to be able to query it.bkstorm
03/07/2019, 6:08 AM@relation(link: INLINE)
after author: User
๐. Actually, you don't have to use @relation
in this situation, but if you use it, you have to declare it at both User
and Post
bkstorm
03/07/2019, 6:15 AMezeikel
03/07/2019, 9:55 AMezeikel
03/07/2019, 9:55 AM@relation(link: INLINE)
to author: User
doesn't work either. Only one side must have the relation apparentlyezeikel
03/07/2019, 10:58 AMHarshit
03/07/2019, 4:11 PMHarshit
03/07/2019, 4:11 PMezeikel
03/07/2019, 4:11 PMezeikel
03/07/2019, 4:12 PMHarshit
03/07/2019, 4:12 PMezeikel
03/07/2019, 4:12 PMresolvers: {
Mutation,
Query,
User: {
posts(parent) {
return prisma.user({ id: parent.id }).posts()
}
},
Post: {
author(parent) {
return <http://prisma.post|prisma.post>({ id: parent.id }).author()
}
}
}
Harshit
03/07/2019, 4:13 PMezeikel
03/07/2019, 4:13 PM