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

Error: The result of this StaticQuery could not be fetched. #21156

Closed
julietrubin opened this issue Feb 3, 2020 · 3 comments
Closed

Error: The result of this StaticQuery could not be fetched. #21156

julietrubin opened this issue Feb 3, 2020 · 3 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@julietrubin
Copy link

julietrubin commented Feb 3, 2020

Description

I am working off of the gatsby-portfolio-dev repo. This repo uses graphQL to query github projects to display on the portfolio. I'm not sure if this is a bug or I'm just missing something. The apiCall to github is returning an error.

I added my github token as described and I'm getting

Error: The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
useStaticQuery
/Users/julietrubin/Documents/code/portfolio/.cache/gatsby-browser-entry.js:63
 60 | if (context[query] && context[query].data) {
 61 |   return context[query].data
 62 | } else {
> 63 |   throw new Error(
 64 |     `The result of this StaticQuery could not be fetched.\n\n` +
 65 |       `This is likely a bug in Gatsby and if refreshing the page does not fix it, ` +
 66 |       `please open an issue in https://github.com/gatsbyjs/gatsby/issues`
 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

context is not defined

   1 | query usersjulietrubinDocumentscodeportfoliosrccomponentslandingProjectsindexJsx3032228125 {
   2 |   github {
>  3 |     viewer {
     |     ^
   4 |       id
   5 |       repositories(first: 8, orderBy: {field: STARGAZERS, direction: DESC}) {
   6 |         edges {
   7 |           node {
   8 |             id
   9 |             name
  10 |             url
  11 |             description
  12 |             stargazers {
  13 |               totalCount

Steps to reproduce

gatsby new gatsby-portfolio-dev https://github.com/smakosh/gatsby-portfolio-dev
yarn build
yarn start

Expected result

Have the github api request be success.

Actual result

Getting an error message

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 11.15.0 - ~/.nvm/versions/node/v11.15.0/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.15.0/bin/npm
  Languages:
    Python: 3.6.5 - /usr/local/bin/python
  Browsers:
    Chrome: 79.0.3945.130
    Safari: 12.1.2
  npmPackages:
    gatsby: ^2.17.7 => 2.19.12
    gatsby-image: ^2.2.30 => 2.2.40
    gatsby-plugin-canonical-urls: ^2.0.8 => 2.1.20
    gatsby-plugin-favicon: ^3.1.6 => 3.1.6
    gatsby-plugin-google-analytics: ^2.0.8 => 2.1.35
    gatsby-plugin-mailchimp: ^5.1.2 => 5.1.2
    gatsby-plugin-manifest: 2.2.6 => 2.2.6
    gatsby-plugin-nprogress: ^2.0.7 => 2.1.19
    gatsby-plugin-offline: 3.0.14 => 3.0.14
    gatsby-plugin-react-helmet: ^3.0.2 => 3.1.22
    gatsby-plugin-sharp: 2.2.13 => 2.2.13
    gatsby-plugin-sitemap: ^2.0.3 => 2.2.27
    gatsby-plugin-styled-components: ^3.0.4 => 3.1.19
    gatsby-source-filesystem: ^2.1.35 => 2.1.48
    gatsby-source-graphql: ^2.1.33 => 2.1.33
    gatsby-transformer-sharp: 2.2.7 => 2.2.7
@crock
Copy link
Contributor

crock commented Feb 3, 2020

@julietrubin Can you show us your gatsby-node.js?

It says "context" is not defined and that refers to the page context that you setup in gatsby-node, which runs at build time.

You will have an inital GraphQL query in Gatsby Node just to fetch the ID or some other unique identifier in the response and pass that as the context, which will be used in your page query to fetch the correct response.

Here's an example:

const path = require('path')
const slash = require('slash')
const _ = require('lodash')

exports.createPages = async ({ graphql, actions, reporter }) => {
  const { createPage } = actions
  const result = await graphql(`
    {
      allWordpressPost(filter: { status: { eq: "publish" } }) {
        edges {
          node {
            slug
          }
        }
      }
  }
 `)

  // Handle errors
  if (result.errors) {
    console.error(result.errors)
    reporter.panicOnBuild(`Error while running GraphQL query.`)
    return
  }
  // Blog Posts
  const postTemplate = path.resolve(`./src/templates/blog-post.js`)
  _.each(result.data.allWordpressPost.edges, edge => {
    const { node } = edge
    const post = node
    createPage({
      path: `/blog/${post.slug}`,
      component: slash(postTemplate),
      context: {
        slug: post.slug,
      },
    })
  })
}

@crock crock added the type: question or discussion Issue discussing or asking a question about Gatsby label Feb 3, 2020
@julietrubin
Copy link
Author

@crock Thanks for the response. I am working directly off of https://github.com/smakosh/gatsby-portfolio-dev. The only change I made was to add my GITHUB_TOKEN as described. I also verified process.env.GITHUB_TOKEN contains my token with a console log.

https://github.com/smakosh/gatsby-portfolio-dev/blob/master/gatsby-node.js
https://github.com/smakosh/gatsby-portfolio-dev/blob/master/src/components/landing/Projects/index.jsx

Maybe I should open a ticket on that repo.

@vladar
Copy link
Contributor

vladar commented Feb 5, 2020

Sounds similar to #21170. Should be already fixed upstream but you may have to update your dependencies (namely graphql-tools-fork)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants