Graphql-tag: [question] syntax error or bug? Perhaps you need to wrap the query string in a "gql" tag?

Created on 9 Jan 2018  路  2Comments  路  Source: apollographql/graphql-tag

I'm getting this error from some example code and I have no clue why.
example LinkList.vue
It seems to be related to the 'NEWS_LINKS_SUBSCRIPTION' query
Any hints?

Correct signature during iteration: doc.definitions[], doc.kind
img2661

This signature during iteration causes the error: doc[0]
img2662

browser error:

vue.esm.js?efeb:1717 Error: Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag? http://docs.apollostack.com/apollo-client/core.html#gql
    at checkDocument (getFromAST.js?6c61:16)
https://github.com/howtographql/vue-apollo/blob/master/src/components/LinkList.vue

LinkList.vue

apollo: {
    allLinks: {
      query: ALL_LINKS_QUERY
    },
    subscribeToMore: [
      {
        document: NEW_LINKS_SUBSCRIPTION,
        updateQuery: (previous, { subscriptionData }) => {
          console.log('updateQuery', previous, subscriptionData)
          const newAllLinks = [
            subscriptionData.data.Link.node,
            ...previous.allLinks
          ]
          const result = {
            ...previous,
            allLinks: newAllLinks.slice(0, 5)
          }
          return result
        }
      }
    ]
  },

graphql.js // collection of clientside queries

export const NEW_LINKS_SUBSCRIPTION = gql`
  subscription {
    Link(filter: { mutation_in: [CREATED] }) {
      node {
        id
        url
        description
        createdAt
        postedBy {
          id
          name
        }
        votes {
          id
          user {
            id
          }
        }
      }
    }
  }
`

package.json

"dependencies": {
    "apollo-cache-inmemory": "^1.1.5",
    "apollo-cache-persist": "^0.1.1",
    "apollo-client": "^2.2.0",
    "apollo-link": "^1.0.7",
    "apollo-link-context": "^1.0.3",
    "apollo-link-http": "^1.3.2",
    "apollo-link-ws": "^1.0.4",
    "apollo-utilities": "^1.0.4",
    "graphql": "^0.12.3",
    "graphql-tag": "^2.6.1",
    "subscriptions-transport-ws": "^0.9.4",
    "vue": "^2.5.3",
    "vue-apollo": "^3.0.0-alpha.3",
    "vue-router": "^3.0.1",
    "vuetify": "^1.0.0-beta.2"
  },

Most helpful comment

never mind.. syntax error.
should be:

apollo: {
    allLinks: {
      query: ALL_LINKS_QUERY,
      subscribeToMore: [
        {
          document: NEW_LINKS_SUBSCRIPTION,

instead of:

apollo: {
    allLinks: {
      query: ALL_LINKS_QUERY
    },
    subscribeToMore: [
      {
        document: NEW_LINKS_SUBSCRIPTION,

All 2 comments

never mind.. syntax error.
should be:

apollo: {
    allLinks: {
      query: ALL_LINKS_QUERY,
      subscribeToMore: [
        {
          document: NEW_LINKS_SUBSCRIPTION,

instead of:

apollo: {
    allLinks: {
      query: ALL_LINKS_QUERY
    },
    subscribeToMore: [
      {
        document: NEW_LINKS_SUBSCRIPTION,

this problem took me a day to find.. thanks for the solution.. terrible lib API design (i was seeing another error as well as this)

Was this page helpful?
0 / 5 - 0 ratings