gatsbyjs / gatsby-source-wordpress-experimental

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

Build failure: "Sorry, you do not have permission to view this setting." allSettings.generalSettingsEmail, generalSettings.email #139

Closed etnichols closed 4 years ago

etnichols commented 4 years ago

gatsby-source-wordpress-experimental: 1.3.6

Using WP GraphQL plugin version 0.10.3

Relevant build output:

success  gatsby-source-wordpress  MediaItem - 123.668s - fetched 105
success  gatsby-source-wordpress  creating nodes - 123.720s
success  gatsby-source-wordpress  fetching nodes - 150.355s - 291 total

 ERROR

 gatsby-source-wordpress  (undefined) location: line 9, column: 5
     Sorry, you do not have permission to view this setting.

 Error path: allSettings.generalSettingsEmail

 If you haven't already, try adding define( 'GRAPHQL_DEBUG', true ); to your wp-config.php for more detailed error messages.

 ERROR

 gatsby-source-wordpress  (undefined) location: line 34, column: 5
     Sorry, you do not have permission to view this setting.

 Error path: generalSettings.email

 If you haven't already, try adding define( 'GRAPHQL_DEBUG', true ); to your wp-config.php for more detailed error messages.

 ERROR

 gatsby-source-wordpress  Error occured while fetching non-Node root fields.

not finished source and transform nodes - 151.951s
not finished Downloading remote files - 35.117s
not finished Generating image thumbnails - 122.007s
not finished  gatsby-source-wordpress  fetch root fields - 1.397s

(sharp:69783): GLib-CRITICAL **: 16:03:27.305: g_hash_table_lookup: assertion 'hash_table != NULL' failed

Digging into this error message led me to this WP Graphql discussion: https://github.com/wp-graphql/wp-graphql/issues/373. Which was formalized into https://docs.wpgraphql.com/guides/authentication-and-authorization/. Very helpful!

The relevant part of the docs:

A public, non-authenticated request would return a null value for the field and would return an error message in the GraphQL response. However, it wouldn’t block the execution of the entire GraphQL request, just that field. So, if the request had a mix of publicly allowed fields and private fields, GraphQL would still execute the public data.

Which leads to my questions:

etnichols commented 4 years ago

@jasonbahl -- could you provide more guidance on how to actually use the wp-graphql plugin with the authentication plugins you mention in the documentation?

etnichols commented 4 years ago

Workaround:

    {
      resolve: `gatsby-source-wordpress-experimental`,
      options: {
         AllSettings: {
           excludeFieldNames: ['generalSettingsEmail'],
         },
         GeneralSettings: {
           excludeFieldNames: ['email'],
         },
       },
    },

To bypass the auth-only fields.