Vue-apollo: gql template literal can't find variables

Created on 23 Aug 2017  路  2Comments  路  Source: vuejs/vue-apollo

I'm trying to make a simple mutation to log in to a GraphQL api and I get this error:

ApolloError.js?d743:34 Uncaught (in promise) Error: GraphQL error: Variable '$email' is not defined. (line 2, column 29):
signinUser(email: {email: $email, password: $password}) {
^
(line 1, column 1):
mutation {
^
GraphQL error: Variable '$password' is not defined. (line 2, column 47):
signinUser(email: {email: $email, password: $password}) {
^
(line 1, column 1):
mutation {
^
at new ApolloError (ApolloError.js?d743:34)
at eval (QueryManager.js?2cbe:129)
at

Queries without template literal variables works fine.
I'm using:

  • apollo-client 1.9.1
  • vue-apollo-beta.21
  • vue 2.3.3

This is my Vue component that is calling the mutation:
```

I'm using the Vue webpack template and this is my main.js config file:

// The Vue build version to load with the import command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// Apollo
import { ApolloClient, createBatchingNetworkInterface } from 'apollo-client'
import VueApollo from 'vue-apollo'

const apolloClient = new ApolloClient({
networkInterface: createBatchingNetworkInterface({
uri: 'https://api.graph.cool/simple/v1/cj6nldc9p1icq0178n1pyow9i'
}),
connectToDevTools: true
})

Vue.use(VueApollo)

const apolloProvider = new VueApollo({
defaultClient: apolloClient
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
el: '#app',
router,
apolloProvider,
template: '',
components: { App }
})
```

Most helpful comment

You need to declare the variables inside the graphql document:

          gql`mutation login($email:String!, $password:String!) {
            signinUser(email: { email: $email, password: $password }) {
              token
            }
          }`

All 2 comments

You need to declare the variables inside the graphql document:

          gql`mutation login($email:String!, $password:String!) {
            signinUser(email: { email: $email, password: $password }) {
              token
            }
          }`

Thanks and sorry about that! I can't believe I missed that. It's right there in the documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanaye picture seanaye  路  3Comments

alsofronie picture alsofronie  路  3Comments

mathe42 picture mathe42  路  4Comments

Akryum picture Akryum  路  3Comments

igaloly picture igaloly  路  3Comments