Apollo-client: (Reopen) Uncaught (in promise) Error: Must contain a query definition. #1536

Created on 4 Apr 2017  路  7Comments  路  Source: apollographql/apollo-client

As a continuation to #1536, the suggested change to the code was made,

client.mutate

but now throws an Uncaught TypeError: Cannot read property 'kind' of undefined error, as shown in the attached image.

error

Most helpful comment

@greduan Thank you. But first allow me to, 'ahhhhhhhhh!!!'. Ok, I feel better now.

So. data.updatePosts. likes throws an Cannot read property 'likes' of undefined on handleSubmitSuccess. Any ideas?

  mutation: gql`
        mutation incrementPostLikes ($id: ID!, $count: Int) {
          updatePosts (id: $id, likes: $count) {
            id
            likes
          }
        }
      `,
      variables: {
        "id": idVal,
        "count": incVal
       },
      // forceFetch: true,
    })
    .then(this.handleSubmitSuccess)
    .catch(this.handleSubmitError);
  },
  handleSubmitError(err) {
    console.error(err.message);
  },
  handleSubmitSuccess(data) {
    console.log(data.updatePosts.likes);
  } 

All 7 comments

I'm sorry @TheoMer, but I can't help any further without a reproduction. Could you please provide one with react-apollo-error-template?

@helfer You can find my fork of the error-template here

Yarn install away

Can confirm I also get this error.
screenshot from 2017-04-05 08-48-23

This error is caused because apollo.mutate expects mutation to exist as a property of its first argument, rather than query.

I suggest adding a simple if to check if mutate has mutation defined and query has query defined, throw a clear error otherwise.

@greduan Thank you. But first allow me to, 'ahhhhhhhhh!!!'. Ok, I feel better now.

So. data.updatePosts. likes throws an Cannot read property 'likes' of undefined on handleSubmitSuccess. Any ideas?

  mutation: gql`
        mutation incrementPostLikes ($id: ID!, $count: Int) {
          updatePosts (id: $id, likes: $count) {
            id
            likes
          }
        }
      `,
      variables: {
        "id": idVal,
        "count": incVal
       },
      // forceFetch: true,
    })
    .then(this.handleSubmitSuccess)
    .catch(this.handleSubmitError);
  },
  handleSubmitError(err) {
    console.error(err.message);
  },
  handleSubmitSuccess(data) {
    console.log(data.updatePosts.likes);
  } 

Wouldn't it be res.data to access it or { data } as argument to handleSubmitSuccess?

So:

function handleSubmitSuccess({ data }) { data }

or

function handleSubmitSuccess(res) { res.data }

relaymutationerror

The auth.js code where the error hits
createUser = (authFields) => { return new Promise( (resolve, reject) => { Relay.Store.commitUpdate( new CreateUser({ email: authFields.email, idToken: authFields.idToken }), { onSuccess: (response) => { this.signinUser(authFields) resolve(response) }, onFailure: (response) => { console.log('CreateUser error', response) response.getError().source reject(response) } } ) }) }

I am getting this error while creating user once it gets authenticated. I am using Auth0 to authenticate which works fine only when using relay and GraphQL API to insert/fetch the user details this error comes up as uncaught in promise. I did set the GraphQL endpoint for relay.

I am just getting started with these frameworks, please provide any pointers in direction to debug this.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings