Uncaught (in promise) GraphQLError: Syntax Error: Unexpected character: “.” using GraphQl in Vue

Uncaught (in promise) GraphQLError: Syntax Error: Unexpected character: “.” using GraphQl in Vue


-1

I’m using graphql in Vue and I came up with this problem!
This is my code for calling graphql in store:

async fetchBookContent({ commit }, data) {
    let token = data.token
    let bookId = data.bookId
    const ALL_BOOKS_QUERIES = gql`
      query {
        book(args:{token:${token},bookId:${bookId}}){
          information{
            name
          }
        }
      }
    `
    const { result } = useQuery(ALL_BOOKS_QUERIES)
    console.log(result)
    commit('content', result)
  },

I need to pass token and bookId I guess, but it keeps giving me syntax error 🙁
does anyone know the problem?

query($token: String, $bookId: String!){
  book(args:{token: $token, bookId: $bookId}){
    information{
      name
    }
    contents{
      name
      stats{
        mcQuiz
      }
    }
  }
}

BTW, this is the query I must write the code for

1

  • Consult the Apollo documentation which goes over how to use variables with graphql (they get added as a second parameter of useQuery).

    – yoduh

    51 mins ago


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *