I get an error on a fresh install of this package in my plugin. I never used to, the only thing I've done is upgraded WP GraphQL to 1.2.5. In GraphiQL, I get:
{
"code": "internal_server_error",
"message": "<p>There has been a critical error on this website.</p><p><a href=\"https://wordpress.org/support/article/debugging-in-wordpress/\">Learn more about debugging in WordPress.</a></p>",
"data": {
"status": 500
},
"additional_errors": []
}
Inspecting the debug log, I see:
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Notice: Undefined property: WP_Post_Type::$graphql_single_name in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 203
[08-Mar-2021 15:00:46 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to register_graphql_field() must be of the type string, null given, called in /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php on line 47 and defined in /var/www/html/wpgraphql_crb_test/wp-content/plugins/wp-graphql/access-functions.php:269
Stack trace:
#0 /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php(47): register_graphql_field()
#1 /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php(63): WpGraphQLCrb\Container->registerField()
#2 /var/www/html/wpgraphql_crb_test/wp-content/plugins/graphql-carbon-test/vendor/matepaiva/wp-graphql-crb/src/Container.php(57): WpGraphQLCrb\Container->registerFields()
#3 /var/www/html/wpgraphql_crb_test/wp-includes/class-wp-hook.php(287): WpGraphQLCrb\Container->graphqlRegisterTypes()
#4 /var/www/html/wpgraphql_crb_test/wp-inclu in /var/www/html/wpgraphql_crb_test/wp-content/plugins/wp-graphql/access-functions.php on line 269
And digging deeper, I find that for the WpGraphQLCrb\Container instance, the getGraphQLRoot()
method is returning:
Array
(
[0] => post
[1] => page
[2] => mediaItem
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
This array is mapped from Carbon_Fields\REST_API\Decorator::get_post_meta_container_settings()
using the map function $type
-> getGraphQLPostTypeRoot($type)
. The array provided from that mapping is:
Array
(
[0] => post
[1] => page
[2] => attachment
[3] => revision
[4] => nav_menu_item
[5] => custom_css
[6] => customize_changeset
[7] => oembed_cache
[8] => user_request
[9] => wp_block
)
So it seems that Container->getGraphQLPostTypeRoot($type)
is failing for revision
, nav_menu_item
, custom_css
... etc, as those post type objects don't have a graphql_single_name
.
My composer json:
{
"require": {
"htmlburger/carbon-fields": "^3.2",
"matepaiva/wp-graphql-crb": "dev-master"
},
"minimum-stability": "dev",
"prefer-stable": true
}
Installed plugins: WP GraphQL (Version 1.2.5)
My code:
<?php
/*
Plugin Name: WPGraphQL Carbon Fields Test
Version: 1.0
*/
namespace GraphQLCarbonTest;
use WpGraphQLCrb\Container as WpGraphQLCrbContainer;
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action( 'carbon_fields_register_fields', 'GraphQLCarbonTest\crb_attach_theme_options' );
function crb_attach_theme_options() {
WpGraphQLCrbContainer::register(
Container::make( 'post_meta', __( 'Test Post Meta Container' ) )
->add_fields( array(
Field::make( 'text', 'crb_text', 'Text Field' ),
// Field::make( 'icon', 'sm_download_icon', __( 'Icon', 'crb' ) ),
) )
);
}
add_action( 'after_setup_theme', 'GraphQLCarbonTest\crb_load' );
function crb_load() {
require_once( 'vendor/autoload.php' );
\Carbon_Fields\Carbon_Fields::boot();
}
I'm thinking that removing these types from the $roots
whose post type objects don't have a graphql_single_name
would solve the issue, but I'm not confident that it wouldn't break anything else. What do you think?