New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[gatsby-source-wordpress] Cannot destructure property 'typeInfo' of 'queryInfo' as it is undefined. #35460
Comments
Hi there 👋 what you're attempting wont work for a few reasons even beyond that error. I opened a PR and released a canary allowing you to exclude MediaItem nodes. You can try it with this version |
This will go out in the next oss release (next week) |
thanks so much @TylerBarnes for the fast response and fix 🚀🚀 |
@TylerBarnes I'm getting this error again using It doesn't happen during a clean build or a cached build with no wordpress updates...only during a cached build with updates to fetch during the
|
Can you try removing the caret? Also I believe this may have been released on the latest stable release as well |
@TylerBarnes I am still getting the error without the caret. I updated package, did a clean rebuild, updated a wordpress page and then attempted to build and it failed on
NPM still shows 6.13.0 as the current version, was it pushed into that or should I be looking for 6.14.0? |
@TylerBarnes just FYI, this is reproducing both locally and on gatsby cloud as well |
@tsdexter did you remove the code you originally added to your WP instance? add_filter( 'graphql_RootQuery_fields', function( $fields ) {
unset($fields['mediaItems']);
return $fields;
}, 99, 1 ); |
@TylerBarnes, sorry for the delay, i was on vacation... I have removed that code. This also happens during Here is all of the custom code relating to WPGraphQL: <?php
// save "rendered" content to speed up graphql queries
add_action( 'save_post', function ( $post_id ) {
// if this is a revision returnn
if ( wp_is_post_revision( $post_id ) )
return;
// get post
$post = get_post( $post_id );
if ($post->post_type === "action_monitor") return;
// apply fitlers too post_content
$filtered_content = apply_filters( 'the_content', $post->post_content );
// append prerender info console log
$now = date('d F Y, h:i:s A');
$filtered_content = "<script type='text/javascript'>console.log({renderer: 'save_post', time: '{$now}'});</script>" . $filtered_content;
// save to post meta
update_post_meta( $post_id, 'post_content_filtered', $filtered_content );
//@TODO: when posts that may be included elsewhere change, update the including file
// for example, if reusable block is changed, check for posts with "ref: block-id" and render/save them
// or if a news post is changed, check for posts with news feeds and render/save them
//@TODO: don't save pre-rendered content for any post with reusable blocks or server rendered blocks (can check post content or have to use blacklist?)
} );
/**
* Remove unnecessary fields from the RootQuery
*/
add_filter( 'graphql_RootQuery_fields', function( $fields ) {
// unset($fields['allSettings']);
// // unset($fields['categories']);
// unset($fields['category']);
// unset($fields['comment']);
// unset($fields['comments']);
// // unset($fields['contentNode']);
// unset($fields['contentNodes']);
// unset($fields['contentType']);
// unset($fields['contentTypes']);
// unset($fields['discussionSettings']);
// unset($fields['generalSettings']);
// // unset($fields['isWpGatsby']);
// unset($fields['mediaItem']);
// unset($fields['mediaItemBy']);
// // unset($fields['mediaItems']);
// unset($fields['menu']);
// unset($fields['menuItem']);
// // unset($fields['menuItems']);
// // unset($fields['menus']);
// unset($fields['node']);
// unset($fields['nodeByUri']);
// unset($fields['page']);
// unset($fields['pageBy']);
// // unset($fields['pages']);
// unset($fields['plugin']);
// unset($fields['plugins']);
// unset($fields['post']);
// unset($fields['postBy']);
// unset($fields['postFormat']);
// unset($fields['postFormats']);
// // unset($fields['posts']);
// unset($fields['readingSettings']);
// unset($fields['registeredScripts']);
// unset($fields['registeredStylesheets']);
// unset($fields['revisions']);
// unset($fields['schemaMd5']);
// unset($fields['seo']);
// unset($fields['tag']);
// // unset($fields['tags']);
// unset($fields['taxonomies']);
// unset($fields['taxonomy']);
// unset($fields['termNode']);
// unset($fields['terms']);
// unset($fields['theme']);
// unset($fields['themes']);
// unset($fields['user']);
// unset($fields['userRole']);
// unset($fields['userRoles']);
// unset($fields['users']);
// unset($fields['viewer']);
// // unset($fields['wpGatsby']);
// // unset($fields['wpGatsbyCompatibility']);
// unset($fields['writingSettings']);
return $fields;
}, 99, 1 );
/**
* Return pre-rendered content in ContentNode
*/
// add_filter( 'graphql_PostObjectFieldFormatEnum_values', function($values) {
// $values['PRERENDERED'] = [
// 'name' => 'PRERENDERED',
// 'description' => __( 'Gets the content from the post_content_filtered postmeta field', 'wp-graphql' ),
// 'value' => 'prerendered',
// ];
// return $values;
// }, 99, 1 );
add_filter( 'graphql_Page_fields', function( $fields ) {
$fields['content']['resolve'] = contentResolver;
return $fields;
}, 99, 1 );
add_filter( 'graphql_Post_fields', function( $fields ) {
$fields['content']['resolve'] = contentResolver;
return $fields;
}, 99, 1 );
add_filter( 'graphql_ReusableBlock_fields', function( $fields ) {
$fields['content']['resolve'] = contentResolver;
return $fields;
}, 99, 1 );
/**
* resolver to return pre-rendered content
*/
function contentResolver( $root, $args, $context, $info ) {
$content = get_post_meta( $root->ID, 'post_content_filtered', true );
if ( !$content || $content == '' || strpos($content, '[vc_row') !== false ) {
$post = get_post( $root->ID );
if (class_exists('WPBMap')) WPBMap::addAllMappedShortcodes();
$content = apply_filters( 'the_content', $post->post_content );
$now = date('d F Y, h:i:s A');
$content = "<script type='text/javascript'>console.log({renderer: 'contentResolver', time: '{$now}'});</script>" . $content;
update_post_meta( $root->ID, 'post_content_filtered', $content );
}
return $content; //'FROM POSTMETA' . $content;
};
/**
* Disable post types from WPGraphQL
*/
add_filter( 'register_post_type_args', function($args, $post_type) {
if ( $post_type == "wp_block" ) {
$args['show_in_graphql'] = true;
$args['publicly_queryable'] = true;
$args['graphql_single_name'] = 'reusableBlock';
$args['graphql_plural_name'] = 'reusableBlocks';
} else if ( $post_type == "pts_program") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpPtsProgram';
$args['graphql_plural_name'] = 'wpPtsPrograms';
} else if ( $post_type == "pts_course") {
$args['show_in_graphql'] = true;
$args['graphql_single_name'] = 'wpPtsCourse';
$args['graphql_plural_name'] = 'wpPtsCourses';
} else if ( $post_type == "alerts") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpAlert';
$args['graphql_plural_name'] = 'wpAlerts';
} else if ( $post_type == "catalog_program") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpProgram';
$args['graphql_plural_name'] = 'wpPrograms';
} else if ( $post_type == "link") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpLink';
$args['graphql_plural_name'] = 'wpLinks';
} else if ( $post_type == "tour") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpTour';
$args['graphql_plural_name'] = 'wpTours';
} else if ( $post_type == "equivalencies") {
$args['show_in_graphql'] = false;
$args['graphql_single_name'] = 'wpEquivalency';
$args['graphql_plural_name'] = 'wpEquivalencies';
}
return $args;
}, 20, 2 );
add_action('graphql_register_types', function() {
register_graphql_field( 'ContentNode', 'topParentId', [
'type' => 'Number',
'description' => __( 'The ID of the topmost parent page', 'georgian' ),
'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
$wppost = get_post( $post->databaseId );
if ($wppost->post_parent) {
$ancestors=get_post_ancestors($wppost->ID);
$root=count($ancestors)-1;
$topparent = $ancestors[$root];
} else {
$topparent = $wppost->ID;
}
return $topparent;
}
]);
register_graphql_field( 'ContentNode', 'localParentId', [
'type' => 'Number',
'description' => __( 'The ID of the local parent page', 'georgian' ),
'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) {
$wppost = get_post( $post->databaseId );
if ($wppost->post_parent) {
$ancestors=get_post_ancestors($wppost->ID);
$count=count($ancestors);
if($count == 1)
{
$localParent = $ancestors[$count-1];
} else {
$localParent = $ancestors[$count-2];
}
} else {
$localParent = $wppost->ID;
}
return $localParent;
}
]);
register_graphql_connection( [
'fromType' => 'MenuItem',
'toType' => 'ReusableBlock',
'fromFieldName' => 'reusableBlock',
'connectionTypeName' => 'MenuItemNodeToReusableBlockNodeConnection',
'description' => 'The reusable block content for the Mega Menu',
'oneToOne' => true,
'resolve' => function ( WPGraphQL\Model\MenuItem $post, $args, WPGraphQL\AppContext $context, GraphQL\Type\Definition\ResolveInfo $info ) {
$blockId = gc_get_field('reusable_block_id', $post->databaseId);
if ( ! isset( $blockId ) ) {
return null;
}
$contentPost = get_post($blockId);
$resolver = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $post, $args, $context, $info );
$resolver->set_query_arg( 'p', $blockId );
$resolver->set_query_arg( 'post_type', 'wp_block' );
return $resolver->one_to_one()->get_connection();
},
] );
}); |
@TylerBarnes I just updated to |
@TylerBarnes I've fixed this, hopefully in an acceptable way, in PR #35817 |
Preliminary Checks
Description
i'm getting the following error during development:
I am assuming it is because I removed the
RootQuery.mediaItems
type from WPGraphQL (due to not having a reliable way to tellgatsby-source-wordpress
not to source it which is drastically slowing down my build times and I don't need themediaItems
on my gatsby site) via:Can this be changed to check for
undefined
first and/or create a plugin option to ignore certain nodes entirely on theRootQuery
?Reproduction Link
https://github.com/tsdexter/gatsby-repro
Steps to Reproduce
npm run develop
In order to run it with your own WP instance you will likely need to add to your functions.php file:
as it's likely the related code thats breaking it.
Expected Result
build process shouldn't crash
Actual Result
build process crashes with error message
Environment
Config Flags
No response
The text was updated successfully, but these errors were encountered: