Gomah/nuxt-graphql-request

Returned Data is Inside Errors

devotoare opened this issue · 1 comments

I'm trying to handle errors on a mutation with variables and this is what I have:

async fetchSomething() {
  const mutation = gql`
    mutation AdminLogin($email: String!, $password: String!) {
      al(input: { email: $email, password: $password }) {
        token
        firstName
        lastName
        email
      }
    }
  `

  const variables = { email: this.form.email, password: this.form.password }

  try {
    const data = await this.$graphql.default.request(mutation, variables)
    // eslint-disable-next-line no-console
    console.log(JSON.stringify(data))
  } catch (error) {
    // eslint-disable-next-line no-console
    console.error(JSON.stringify(error))
  }
},

What's interesting is the mutation goes through fine and returns the data, except the data is inside of error so it always fails the try catch... It also has a status inside of error with the code being 200. Not sure what's happening to get my data inside of error but the same endpoint works with nuxt/apollo.

Example Response:

{"response":{"error":"{\"data\":{\"al\":{\"token\":\"REDACTED\",\"firstName\":\"REDACTED\",\"lastName\":\"REDACTED\",\"email\":\"REDACTED\"}}}","status":200},"request":{"query":"mutation AdminLogin($email: String!, $password: String!) {\n  al(input: {email: $email, password: $password}) {\n    token\n    firstName\n    lastName\n    email\n  }\n}\n","variables":{"email":"REDACTED","password":"REDACTED"}}}