gatsbyjs / gatsby-source-wordpress-experimental

The upcoming v4 of gatsby-source-wordpress, currently in beta
MIT License
385 stars 100 forks source link

'gatsby develop' fails when wordpress site language is set to Russian: Missing onError handler for invocation 'building-schema' #427

Closed kivils closed 3 years ago

kivils commented 3 years ago

Hi! I'm facing an error: gatsby develop fails when site language is set to Russian id wordpress admin panel. If I switch site language to English (UK) - gatsby develop doesn't fail and static site is generated as expected.

Not sure if this error relates to gatsby-source-wordpress-experimental or WP Gatsby/WP GraphQL.

Environment:

Error message

ERROR

Missing onError handler for invocation 'building-schema', error was 'Names must
match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "WpTemplate_Шаблон обложки" does not.'.
Stacktrace was 'GraphQLError: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but
"WpTemplate_Шаблон обложки" does not.
    at isValidNameError
(C:\projects\artelx\node_modules\graphql\utilities\assertValidName.js:42:12)
    at assertValidName
(C:\projects\artelx\node_modules\graphql\utilities\assertValidName.js:21:15)
    at checkIsAllowedTypeName
(C:\projects\artelx\node_modules\gatsby\src\schema\schema.js:578:3)
    at forEach
(C:\projects\artelx\node_modules\gatsby\src\schema\schema.js:284:9)
    at Array.forEach (<anonymous>)
    at addTypes
(C:\projects\artelx\node_modules\gatsby\src\schema\schema.js:246:9)
    at updateSchemaComposer
(C:\projects\artelx\node_modules\gatsby\src\schema\schema.js:135:9)
    at buildSchema
(C:\projects\artelx\node_modules\gatsby\src\schema\schema.js:62:9)
    at build (C:\projects\artelx\node_modules\gatsby\src\schema\index.js:105:24)
    at buildSchema
(C:\projects\artelx\node_modules\gatsby\src\services\build-schema.ts:19:3)'
karen-sarkisyan commented 3 years ago

Hi,

I suppose "WpTemplate_Шаблон обложки" is a page template that you use, and it uses Cyrillic characters. I've reproduced your issue, and it does not seem to depend on a site language, and I'm not sure how it fixes it in your case (doesn't in mine).

The problem is, WPGraphQL creates a type for each page template, and a GraphQL type can only be alphanumeric. WPGraphQL changes type names to make them safe, but for some reason it doesn't work with Cyrillic names at all. That's likely a bug, and it's on WPGraphQL's side.

So when graphql on Gatsby's side validates schema and finds this field, it crashes.

A workaround (only one I can come up with now) I can suggest just renaming the template (change it within the template file, without changing the file name itself). After assigning it an alphanumeric name, it works.

kivils commented 3 years ago

Thanks for the reply and investigation! "WpTemplate_Шаблон обложки" - is a default name in twenty-twenty theme in Russian, didn't change it. When site language is English, it works. Most likely WPGraphQL uses msgstr for page template, and it's in Cyrilic (in case of Russian). Will check WPGraphQL for similar issue or create a new one.

For further information: It worked fine with this configuration:

TylerBarnes commented 3 years ago

Ahh, yep good investigation and this is indeed an upstream issue. It might also be worth asking about this on the Gatsby repo - WPGraphQL seems to be fine with Cyrilic characters in type names but Gatsby does not. The only thing is I'm not sure if this is coming from graphql-js or Gatsby itself :thinking:

In any case I'm going to close this because there's nothing that can be done in this plugin to fix it and either fix will be upstream. Thanks for opening this issue!