Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-source-graphql no longer working with context variables #20280

Closed
mutewinter opened this issue Dec 23, 2019 · 7 comments
Closed

gatsby-source-graphql no longer working with context variables #20280

mutewinter opened this issue Dec 23, 2019 · 7 comments

Comments

@mutewinter
Copy link

mutewinter commented Dec 23, 2019

Description

After upgrading to [email protected], 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, [email protected], 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 
@vladar
Copy link
Contributor

vladar commented Dec 24, 2019

CC @yaacovCR

@yaacovCR
Copy link
Contributor

Likely related to yaacovCR/graphql-tools-fork@a8f2785

Even vanilla schema stitching uses new generated variables to support serializing custom scalars.

I don't believe upstream graphql-tools or the fork ever filters the variables so the unused variable is still sent. This has not caused errors in my testing, but does waste bandwidth.

Curious if anyone knows details of whether this error is from the external GraphQL service and which one it is, surprised more people not getting this.

@yaacovCR
Copy link
Contributor

Should be able to turn out fix by tomorrow.

yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 25, 2019
yaacovCR added a commit to yaacovCR/gatsby that referenced this issue Dec 25, 2019
Updates graphql-tools-fork to v8.0.1 which addresses gatsbyjs#20280.
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 25, 2019
gatsbybot pushed a commit that referenced this issue Dec 25, 2019
Updates graphql-tools-fork to v8.0.1 which addresses #20280.
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
@fourjuaneight
Copy link

fourjuaneight commented Dec 31, 2019

@vladar This seems like it's resolved with the latest graphql-tools-fork. Could it get a version update so fix can published?

@goynang
Copy link

goynang commented 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.

@vladar
Copy link
Contributor

vladar commented Jan 6, 2020

Please try [email protected]. Feel free to re-open if it is still not fixed (or mention me to re-open with more details).

@vladar vladar closed this as completed Jan 6, 2020
@fourjuaneight
Copy link

@vladar Working great. Thanks!

yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 8, 2020
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 21, 2020
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Feb 27, 2020
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
yaacovCR added a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants