gatsby-source-graphql no longer working with context variables
See original GitHub issueDescription
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:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@vladar Working great. Thanks!