gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

After cleaning cache ""gatsby-node.js" threw an error while running the createPagesStatefully lifecycle" #22963

Closed mmazurowski closed 4 years ago

mmazurowski commented 4 years ago

Description

Hey,

Just today my gatsby installation stopped working (I've cleaned cache). I get the following error: Enum type WPGraphQL_LanguageCodeEnum must define one or more values.

Steps to reproduce

Clear steps describing how to reproduce the issue. Please please please link to a demo project if possible, this makes your issue much easier to diagnose (seriously).

My gatsby-node.js:

` const createPages = require("./create/createPages")

exports.createPagesStatefully = async ({ graphql, actions, reporter }, options) => { await createPages({ actions, graphql, reporter }, options) } `

And createPages: ` const pageTemplate = require.resolve("../src/templates/page.js")

const GET_PAGES = ` query GET_PAGES($first:Int $after:String) { wpgraphql { pages( first: $first after: $after

This will make sure to only get the parent nodes and no children

            where: {
                parent: null
            }
        ) {
            pageInfo {
                hasNextPage
                endCursor
            }
            nodes {                
                id
                title
                pageId
                uri
                isFrontPage
            }
        }
    }
}

`

const allPages = [] let pageNumber = 0 const itemsPerPage = 10

/**

2 hours ago everything worked properly, any idea what could have happend?

Expected result

Gatsby develop and build commands will work properly.

Actual result

Nothing to add than description above, sorry.

Environment

System: OS: macOS 10.15.4 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Shell: 5.7.1 - /bin/zsh Binaries: Node: 13.10.1 - /usr/local/bin/node npm: 6.14.4 - /usr/local/bin/npm Languages: Python: 2.7.16 - /usr/bin/python Browsers: Chrome: 80.0.3987.163 Firefox: 70.0.1 Safari: 13.1 npmPackages: gatsby: ^2.20.12 => 2.20.12 gatsby-image: ^2.3.1 => 2.3.1 gatsby-plugin-manifest: ^2.3.3 => 2.3.3 gatsby-plugin-offline: ^3.1.2 => 3.1.2 gatsby-plugin-react-helmet: ^3.2.1 => 3.2.1 gatsby-plugin-sharp: ^2.5.3 => 2.5.3 gatsby-source-graphql: ^2.1.25 => 2.3.2 gatsby-transformer-sharp: ^2.4.3 => 2.4.3 npmGlobalPackages: gatsby-cli: 2.11.5

pieh commented 4 years ago

Do you get similar errors if you query your wordpress / wp-graphql instance outside of Gatsby? You can try this through https://github.com/wp-graphql/wp-graphiql (adding graphiql "ide" to your wordpress admin panel).

There are few possibilities I can see:

Other question - you mentioned cleaning cache - does it mean just deleting .cache directory? Or did you update packages as well? (there might be regression that happened somewhere)

mmazurowski commented 4 years ago

Using 3rd party query "ide" works properly, I can query and get proper results. I've deleted .cache directory, node modules and package.lock file, I've also downgraded gatsby-source-graphqpl from 2.3.2 to 2.1.25 as this was suggested in other issue.

For now, no improvements.

jasonbahl commented 4 years ago

@ktw-studio the LanguageCodeEnum isn't from core WPGraphQL, but is from the WPGraphQL for PolyLang plugin.

Quick win:

I believe you should be able to configure the PolyLang plugin with some languages and this error will go away?

More Info:

From what I can tell, it looks like the enum doesn't have any values set if Polylang hasn't been configured with any languages.

I've opened an issue on the WPGraphQL for Polylang repo here: https://github.com/valu-digital/wp-graphql-polylang/issues/20

I've also opened a PR (https://github.com/valu-digital/wp-graphql-polylang/pull/21) to address this and ensure there's a default value (the site's locale) in case no languages are set up yet. I believe the PR should address this, but @esamattis (creator of WPGraphQL for Polylang) should probably weigh in and make sure the PR makes sense.

jasonbahl commented 4 years ago

@ktw-studio So, I setup WP PolyLang locally along with WPGraphQL for Polylang, and I've confirmed this is indeed the issue.

If you setup some languages under the PolyLang Languages page (/wp-admin/admin.php?page=mlang) the error will go away.

Here, we can see no languages setup in Polylang:

Screen Shot 2020-04-09 at 9 18 43 AM

And if I query the Enum using GraphQL introspection in WPGraphiQL, we can see there are no values:

Screen Shot 2020-04-09 at 9 20 06 AM

This is where Gatsby is getting tripped up.

If I add a language to PolyLang:

Screen Shot 2020-04-09 at 9 20 58 AM

And Query the Enum again, there are values:

Screen Shot 2020-04-09 at 9 21 35 AM


The PR also addresses this by adding a default language. This will allow users that have installed PolyLang and WPGraphQL for Polylang to not run into issues before going through the Polylang setup.

Here, I have no languages again:

Screen Shot 2020-04-09 at 9 18 43 AM

And with the code changed in my PR, I can query the Schema and we will see a default value from the locale of the site:

Screen Shot 2020-04-09 at 9 23 38 AM

jasonbahl commented 4 years ago

@ktw-studio I'm going to close this issue in favor of the issue/PR I've opened on the WPGraphQL for Polylang repo:

mmazurowski commented 4 years ago

@jasonbahl You were absolutely right, seems this issue was not directly caused by gatsby itself. Thank you all for your help and sorry for the trouble! Be safe, be in health, keep on being awesome!

:)