birkir / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
137 stars 75 forks source link

StaticQuery is not working #232

Open gforro opened 4 years ago

gforro commented 4 years ago

The static queries stop to work, when the gatsby-source-prismic-graphql plugin is configured to be used. The problem is that the query is stucked for some reasons and the Loading (StaticQuery) message is shown in a page, where a component with a simple static query is used. It is enough to use the static-query example from this repositories to reproduce the problem. Steps to reproduce the problem:

  1. Add the following to the package.json (to fix the issue in gatsby-source-graphql-universal - Error: Cannot find module './third-party/gatsby-node): Add to the scripts part:
    "preinstall": "npx npm-force-resolutions",

    Add to the root part:

    "resolutions": {
      "gatsby-source-graphql-universal": "3.3.0"
    }
  2. Add the following to the gatsby-node.js to fix the issue with the cache (problem when gatsby cache is cleaned):

    let fs = require("fs")
    let dir = "./.cache/caches/gatsby-source-prismic-graphql"
    
    exports.onPreBootstrap = () => {
      if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir)
      }
    }
  3. Uncomment the <Layout> part in the index.js page.

Now You will get the problem!

gforro commented 4 years ago

The problem is caused by a change in the gatsby's babel-plugin-remove-graphql-queries which is shadowed in the implementation of gatsby-source-graphql-universal.

Change in the gatsbyjs: https://github.com/gatsbyjs/gatsby/commit/752f5ff29008cd175b9a6608304b4f1da73c488c#diff-a46d7772b3756095c8e95b889d9b1df1

gforro commented 4 years ago

Pull request has been created for the fix in the gatsby-source-graphql-universal: https://github.com/birkir/gatsby-source-graphql-universal/pull/25

MarcMcIntosh commented 4 years ago

Hi @gforro can you make the PR here and we'll merge it into an upstream package? https://github.com/prismicio/gatsby-source-graphql-universal

natedonato commented 3 years ago

If anyone is having the same issue with staticquery, or an issue with a broken dependency in the gatsby-source-prismic-graphql, I fixed mine by switching from this branch to the @prismicio branch mentioned by @MarcMcIntosh that has more fixes applied.

For NPM newbies like me that need more specific instructions:

The easiest way I found to seamlessly switch to the prismic fork was to remove the old package, and then install the prismic version as an alias npm i gatsby-source-prismic-graphql@npm:@prismicio/gatsby-source-prismic-graphql

Can also be done by adding this to your package.json dependencies "gatsby-source-prismic-graphql": "npm:@prismicio/gatsby-source-prismic-graphql@^3.6.10",