algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
177 stars 45 forks source link

GraphQLError: Syntax Error: Expected Name, found $ #87

Closed davidshq closed 4 years ago

davidshq commented 4 years ago

I have the following query:

const pageQuery = `{query($after:String){
  wpgraphql {
    posts(first: 100 after: $after) {
        pageInfo {
            hasNextPage
            endCursor
          }
        nodes {
          title
          excerpt
          date
          slug
        }
      }
    }
  }
}
`;

And then the call to execute the query:

const indexName = `Pages`
const settings = { attributesToSnippet: ['excerpt:20'] };
const queries = [
  {
    query: pageQuery,
    transformer: ({ data }) => (data.wpgraphql.posts),
    indexName,
    settings,
  },
];

module.exports = queries

When I attempt a gatsby build everything works fine until Algolia kicks in and then I get:

Algolia: 1 queries to index
Algolia: query #1: executing query
⠇ onPostBuild

  GraphQLError: Syntax Error: Expected Name, found $

  - graphql-runner.ts:112 GraphQLRunner.parse
    [gatsby-lqd]/[gatsby]/src/query/graphql-runner.ts:112:34

not finished onPostBuild - 1.180s

Any ideas on what could be causing this? I've found some similar errors but nothing that seems to be applicable: https://github.com/apollographql/graphql-tag/issues/180 https://www.reddit.com/r/graphql/comments/h9k47y/using_graphql_variables_schema_issues_syntax/

Haroenv commented 4 years ago

does this query work in the graphql playground? Did you try without the dollar, I think it might be the prefix for argument, and not part of the name itself.

davidshq commented 4 years ago

Thanks, I've ended up rewriting things.

Haroenv commented 4 years ago

Glad you got to something working, for future reference, what did you need to change?

davidshq commented 4 years ago

I abandoned the variable which wasn't defined - I was using code from an example I'd found on the web. The code I ended up with is found here: https://github.com/LiquidChurch/lqd-gatsby/blob/algolia-getting-started/src/utils/algolia-queries.js