I have a resolver to create a new draft. I have a ...
# orm-help
d
I have a resolver to create a new draft. I have a relation between User and Draft. So my resolver looks like this :
Copy code
async 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 🤔
n
what does your Prisma datamodel look like?
d
Copy code
type 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!]!
}
n
Is there an error message?
d
nope
In my schema I redefine the user type like this
Copy code
type User {
  id: ID!
  email: String!
  username: String!
  drafts: [Draft!]!
}
n
hmm that shouldn't be problem
I assume you verified that the
createDraft
resolver is indeed called?! so the console.log statement works?!
d
yep
Actually I testing the mutation directly in the playground
so I can see the server response
Copy code
{
  "data": {
    "createDraft": {
      "id": "cjn3ee0ql007f0a94xesulgbb",
      "createdAt": "2018-10-10T16:57:58.844Z",
      "updatedAt": "2018-10-10T16:57:58.844Z",
      "text": "145",
      "author": null
    }
  }
}
n
ah ok, I'm guessing that the data was actually create properly, it's just the server response that's wrong!
did you implement a resolver for the
author
field on the
Draft
type?
d
nope
n
this should fix it:
Copy code
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()
	  }
	}
}
d
Ok I understand now
💯 1
thank you
Before, using prisma binding there is no need to implement a resolver for author field