doums
10/10/2018, 4:49 PMasync createDraft(parent, { text }, ctx) {
const userId = getUserId(ctx)
console.log(userId) //userId is OK
return ctx.prisma.createDraft({
text,
author: {
connect: { id: userId }
}
})
}
but this create a new draft with a null author. I fail to understand why 🤔nikolasburk
doums
10/10/2018, 4:54 PMtype Draft {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
text: String!
author: User
}
type User {
id: ID! @unique
email: String! @unique
password: String!
username: String! @unique
posts: [Draft!]!
}nikolasburk
doums
10/10/2018, 4:55 PMdoums
10/10/2018, 4:56 PMdoums
10/10/2018, 4:56 PMtype User {
id: ID!
email: String!
username: String!
drafts: [Draft!]!
}nikolasburk
nikolasburk
createDraft resolver is indeed called?! so the console.log statement works?!doums
10/10/2018, 4:58 PMdoums
10/10/2018, 4:58 PMdoums
10/10/2018, 4:58 PMdoums
10/10/2018, 4:59 PM{
"data": {
"createDraft": {
"id": "cjn3ee0ql007f0a94xesulgbb",
"createdAt": "2018-10-10T16:57:58.844Z",
"updatedAt": "2018-10-10T16:57:58.844Z",
"text": "145",
"author": null
}
}
}nikolasburk
nikolasburk
author field on the Draft type?nikolasburk
doums
10/10/2018, 5:03 PMnikolasburk
const resolvers = {
Query: {
// ...
},
Mutation: {
// ...
},
Draft: {
author(parent, args, ctx) {
return ctx.prisma.draft({id: parent.id}).author()
}
},
User: {
posts(parent, args, ctx) {
return ctx.prisma.user({id: parent.id}).posts()
}
}
}doums
10/10/2018, 5:04 PMdoums
10/10/2018, 5:05 PMdoums
10/10/2018, 5:07 PM