This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WPGraphQL Track GetText | |
* Description: Test plugin for tracking the number of times the wp-graphql textdomain is translated during a WPGraphQL request. The count is output in the "extensions" portion of the graphql response. | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'graphql_register_types', function() { | |
register_graphql_connection( [ | |
'fromType' => 'Page', | |
'toType' => 'Page', | |
'connectionTypeName' => 'PageSiblings', | |
'fromFieldName' => 'siblings', | |
'resolve' => function( $page, $args, $context, $info ) { | |
$parent = $page->parentDatabaseId ?? null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'graphql_cache_invalidation_init', static function( \WPGraphQL\SmartCache\Cache\Invalidation $invalidation ) { | |
add_action( 'updated_option', static function( $option, $value, $original_value ) use ( $invalidation ) { | |
// phpcs:ignore | |
if ( ! isset( $_POST['_acf_screen'] ) || 'options' !== $_POST['_acf_screen'] ) { | |
return; | |
} | |
// phpcs:ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'graphql_query_analyzer_graphql_keys', function( $graphql_keys, $return_keys, $skipped_keys, $return_keys_array, $skipped_keys_array ) { | |
$keys_array = explode( ' ', $return_keys ); | |
if ( empty( $keys_array ) || ! in_array( 'operation:GetPostBySlug', $keys_array, true ) ) { | |
return $graphql_keys; | |
} | |
if ( ( $key = array_search('list:tag', $keys_array ) ) !== false ) { | |
unset( $keys_array[$key] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'graphql_return_response', function( $filtered_response, $response, $schema, $operation, $query, $variables, $request, $query_id ) { | |
$errors = []; | |
if ( ! is_array( $filtered_response ) && ! empty( $filtered_response->errors ) && is_array( $filtered_response->errors ) ) { | |
$errors = $filtered_response->errors; | |
} else if ( is_array( $filtered_response ) && ! empty( $filtered_response['errors'] ) && is_array( $filtered_response['errors'] ) ) { | |
$errors = $filtered_response['errors']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _graphql_acf_sanitize_flexible_content_resolver( $value, $acf_field, $context, $type_name ) { | |
if ( ! isset( $value['acf_fc_layout'] ) ) { | |
return null; | |
} | |
$type_registry = $context->type_registry; | |
$field_type_name = $type_name . '_' . ucfirst( \WPGraphQL\ACF\Config::camel_case( $acf_field['name'] ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _graphql_acf_sanitize_post_object_resolver( $value ) { | |
if ( ! $value instanceof \WPGraphQL\Model\Post ) { | |
return $value; | |
} | |
if ( 'publish' !== $value->status ) { | |
return $value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add Hobbies to GraphQl | |
add_action('graphql_init', function () { | |
$hobbies = [ | |
// 'type' => 'String', | |
'type' => ['list_of' => 'String'], | |
'description' => __('Custom field for user mutations', 'your-textdomain'), | |
'resolve' => function ($post) { | |
$hobbies = get_post_meta($post->ID, 'hobbies', true); | |
return !empty($hobbies) ? $hobbies : ''; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'graphql_pre_resolve_field', function( $default, $source, $args, $context, $info, $type_name, $field_key, $field, $field_resolver ) { | |
// if the field is not the 'tags' field, and the | |
if ( ! ( 'tags' === $field_key && 'post' === strtolower( $type_name ) ) ) { | |
return $default; | |
} | |
$empty = [ | |
'edges' => [], | |
'nodes' => [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'graphql_register_types', function() { | |
register_graphql_field( 'RootQuery', 'testType', [ | |
'type' => 'TestType', | |
'resolve' => function() { | |
return [ | |
'__typename' => 'TestType', | |
'test' => 'Test Field Value...', | |
'id' => 'root:testType:1' | |
]; |
NewerOlder