I'm trying to save my custom post type posts to local json file but the problem is when i save it with the language attribute a received the error.
{"errors":[{"message":"Field \"language\" is not defined by type RootQueryToEventConnectionWhereArgs.","extensions":{"category":"graphql"},"locations":[{"line":2,"column":44}]}]}
Maybe you help me to fix my code or maybe you can suggest solution to save posts to local json file.
Also in debug when file trying to save post there is one more error
Deprecated: Function WPGraphQL\Data\Connection\AbstractConnectionResolver::getArgs is deprecated since version 1.11.0! Use WPGraphQL\Data\Connection\PostObjectConnectionResolver::get_args() instead. in /home/localhost.com/public_html/wp-includes/functions.php on line 5383
I'm trying to save my custom post type posts to local json file but the problem is when i save it with the language attribute a received the error.
{"errors":[{"message":"Field \"language\" is not defined by type RootQueryToEventConnectionWhereArgs.","extensions":{"category":"graphql"},"locations":[{"line":2,"column":44}]}]}
Maybe you help me to fix my code or maybe you can suggest solution to save posts to local json file.
Also in debug when file trying to save post there is one more error
Deprecated: Function WPGraphQL\Data\Connection\AbstractConnectionResolver::getArgs is deprecated since version 1.11.0! Use WPGraphQL\Data\Connection\PostObjectConnectionResolver::get_args() instead. in /home/localhost.com/public_html/wp-includes/functions.php on line 5383
add_action( 'graphql_register_types', function() { register_graphql_enum_type( 'LanguageCodeFilterEnum', [ 'description' => __( 'Filter by language code', 'domain' ), 'values' => [ 'ALL' => [ 'value' => 'all', 'description' => __( 'All languages', 'domain' ), ], 'CURRENT' => [ 'value' => 'current', 'description' => __( 'Current language', 'domain' ), ], 'EN' => [ 'value' => 'EN', 'description' => __( 'EN language', 'domain' ), ], 'UK' => [ 'value' => 'UK', 'description' => __( 'UK language', 'domain' ), ], ], ] ); } );
`function save_event_data_to_json($post_id) { $post_type = get_post_type($post_id); if ($post_type !== 'event') { return; }
$query_en = <<<GRAPHQL query HOME_PAGE(\$language: LanguageCodeFilterEnum = EN){ events(first: 1000, after: null, where: {language: \$language}) { edges { node { title uri slug eventId featuredImage { node { sourceUrl } } eventPost { previewSection { dateEnd dateStart eventTitle imgSource interfaceDate } } eventPeriods { nodes { id name eventPeriodsTime { dateEnd dateStart } } } eventTypes { nodes { id name } } } } } } GRAPHQL;
$data_en = graphql(array( 'query' => $query_en, ));
$file_en = ABSPATH . 'wp-content/uploads/events_en.json'; if (WP_Filesystem()) { global $wp_filesystem; $wp_filesystem->put_contents($file_en, json_encode($data_en, JSON_UNESCAPED_UNICODE), FS_CHMOD_FILE); } } add_action('save_post', 'save_event_data_to_json'); add_action('edit_post', 'save_event_data_to_json');`