I have an extremely simple mutation that works in ...
# orm-help
s
I have an extremely simple mutation that works in the Playground but not in my Apollo Client. 😢
r
How are you calling mutation from apollo client?
s
This is in
Vue-Apollo
.
Copy code
submitPost () {
      const body = <http://this.post|this.post>
      this.$apollo.mutate({
        mutation: api.posts.mutations.addPost,
        variables: {
          body,
          parentId: null
        }
      }).then(response => {
        console.log(response)
      }).catch(error => {
        console.log(error)
      }).finally(() => {
        <http://this.post|this.post> = ''
      })
    }
Copy code
const addPost = gql`
  mutation AddPost ($body: String!, $parentId: String) {
    addPost (
      body: $body
      parentId: $parentId
    ) {
      id
      body
      parentId
    }
  }
`
r
Code looks good to me. Did you verify if call is being made correctly in network tab?
s
Yep. Header is there and the query is there just as its written above.
It works in Playground and I have other mutations that work with no issue.
n
what means "it doesn't work"?
s
I receive a 400 error when attempting this mutation from inside Vue-Apollo. The mutation works when sent through Playground.
n
do you get the error from your GraphQL Server directly without it being passed to Prisma?
also, try removing fields until it works. I'd start with parentId, that looks suspicious 🙂
s
Re: error, I’ll have to double check tomorrow. And do you mean because parentId was
null
in that above example? I’ve tried omitting that field completely to no avail, but omitting / passing
null
also works in Playground.
n
yes.
s
After digging through the server response a bit, I figured out the errors. I was defining
$parentId
as a
String
when it was supposed to be an
ID
.
n
hmm ok!
I still don't fully understand what's going on. In any case, could you please share a minimal setup to reproduce this problem here: https://github.com/prismagraphql/prisma-binding? We should definitely provide a better error message in this case 🙂
s
The problem was with Apollo, not Prisma. The query worked on Playground because I was doing a direct mutation, not one with arguments. If you'd still like, I could put something together.
Their errors were helpful, just buried pretty deep in the network error object.
n
but the server did end up returning 400, right? I think documenting this error on Github (or SO, for that matter) will be super helpful for others running into the same issue
s
Yeah I can do that. Basically it boiled down to me forgetting my query types 😅
n
yea right. that's probably quite common 😄