question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gatsby-source-graphql no longer working with context variables

See original GitHub issue

Description

After upgrading to gatsby-source-graphql@2.1.29, I’m seeing this error with a GraphQL source that uses a variable:

ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

unexpected variables in variableValues: id

This must be related to #20042. I’ve tested with the previous version, gatsby-source-graphql@2.1.28, and I get no errors.

Here’s a rough sample of my code:

// gastby-node.js
export const createPages = async ({ graphql, actions }) => {
  const { createPage } = actions;
  const postTemplate = path.resolve(`src/templates/Post.tsx`);

  posts.forEach((post) => {
    createPage({
      path: `/posts/${post.slug}`,
      component: postTemplate,
      context: {
        id: post.id,
      },
    });
  });
}

// src/templates/Post.tsx
export const query = graphql`
  query PostQuery($id: String!) {
    blogApi {
      post(id: $id) {
        name
      }
    }
  }
`;

interface Props {
  data: PostQuery;
}

const Post: React.FC<Props> = ({
  data: {
    blogApi: { post },
  },
}) => {

  return (
    <MainLayout>
      <PageMeta title={post.name} />
      <h1>{post.name}</h1>
    </MainLayout>
  );
};

export default Post;

Expected result

Context variables should work with GraphQL queries.

Actual result

I receive the error above.

Environment

  System:
    OS: macOS Mojave 10.14
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.13.1
    Yarn: 1.19.2
    npm: 6.12.1
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 79.0.3945.88
  npmPackages:
    gatsby: 2.18.17 => 2.18.17 
    gatsby-image: ^2.2.34 => 2.2.37 
    gatsby-plugin-codegen: ^1.0.9 => 1.0.10 
    gatsby-plugin-create-client-paths: ^2.1.20 => 2.1.20 
    gatsby-plugin-eslint: ^2.0.8 => 2.0.8 
    gatsby-plugin-manifest: ^2.2.30 => 2.2.34 
    gatsby-plugin-offline: ^3.0.24 => 3.0.30 
    gatsby-plugin-sharp: ^2.3.4 => 2.3.10 
    gatsby-plugin-typescript: ^2.1.20 => 2.1.23 
    gatsby-source-filesystem: ^2.1.39 => 2.1.43 
    gatsby-source-graphql: 2.1.29 => 2.1.29
    gatsby-transformer-sharp: ^2.3.6 => 2.3.9 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
goynangcommented, Jan 2, 2020

I’m seeing this error as well. Using Hasura to provide a GraphQL data source from a Postgres Database. Using the example code from the Gatsby docs I get the same error “unexpected variables in variableValues” when trying to load content into my template for CreatePage.

I’m also using 2.1.29 of gatsby-source-graphql.

Much thanks for a fix release.

0reactions
fourjuaneightcommented, Jan 6, 2020

@vladar Working great. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Common Errors - Gatsby
comes up when a GraphQL query is trying to query a field for subfields, but none exist. This generally happens when plugins that...
Read more >
How to access context variable within the template component ...
Within a react component in a Gatsby app, I understand how to use a context variable within the graphql queries, e.g:
Read more >
Using New Gatsby Source WordPress Plugin - CSS-Tricks
At the bottom section of the file, a GraphQL query is added and calls a specific post based on the post slug variable...
Read more >
gatsby-source-graphql - npm
This plugin has known limitations, specifically in that it does not support Incremental Builds, CMS Preview, image optimizations, and lack of ...
Read more >
Gatsby Tutorial: Sourcing Data and Content - Ibaslogic
You will see how this works in a moment. Gatsby, unlike other site generators, allows us to source data not only from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found