This file contains hidden or 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( 'NodeWithContentEditor', 'unencodedContent', [ | |
| 'type' => 'String', | |
| 'resolve' => function( $post ) { | |
| $content = get_post( $post->databaseId )->post_content; | |
| return ! empty( $content ) ? apply_filters( 'the_content', $content ) : null; | |
| } | |
| ]); | |
| }); |
This file contains hidden or 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_disable_admin', '__return_false' ); |
This file contains hidden or 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_connection_query_args', function( $args, \WPGraphQL\Data\Connection\AbstractConnectionResolver $connection ) { | |
| // Get the Info from the resolver | |
| $info = $connection->getInfo(); | |
| // Get the field name being queried | |
| $field_name = $info->fieldName; | |
| // If the resolver isn't for the children field, return the $args and move on | |
| if ( 'children' !== $field_name ) { |
This file contains hidden or 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
| $blocks = \WP_Block_Type_Registry::get_instance(); | |
| $registered_blocks = $blocks->get_all_registered(); | |
| if ( ! empty( $registered_blocks ) ) { | |
| register_graphql_interface_type( 'ContentEditorBlock', [ | |
| 'description' => __( 'Blocks used by the content editor', 'wp-graphql' ), | |
| 'resolveType' => function( $block ) { | |
| return isset( $block['name'] ) ? $this->get_type( graphql_format_type_name( $block['name'] ) ) : null; | |
| }, | |
| 'fields' => [ |
This file contains hidden or 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( 'init', function() { | |
| if ( is_graphql_http_request() ) { | |
| wp_send_json( [ 'server' => $_SERVER ] ); | |
| } | |
| } ); |
This file contains hidden or 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( 'init', function() { | |
| register_graphql_connection([ | |
| 'fromType' => 'Post', | |
| 'toType' => 'Category', | |
| 'fromFieldName' => 'primaryCat', | |
| 'oneToOne' => true, | |
| 'resolve' => function( \WPGraphQL\Model\Post $post, $args, $context, $info ) { | |
| $primary_term = null; |
This file contains hidden or 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_object_type( 'keyValue', [ | |
| 'description' => __( 'Keys and their values, both cast as strings', 'your-textdomain' ), | |
| 'fields' => [ | |
| 'key' => [ | |
| 'type' => 'String', | |
| ], | |
| 'value' => [ | |
| 'type' => 'String', |
This file contains hidden or 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' => 'Tag', | |
| 'toType' => 'ContentNode', | |
| 'fromFieldName' => 'contentNodes', | |
| 'resolve' => function( \WPGraphQL\Model\Term $source, $args, $context, $info ) { | |
| // Get all post types allowed in GraphQL | |
| $post_types = WPGraphQL::get_allowed_post_types(); | |
| // Instantiate a new PostObjectConnectionResolver class |
This file contains hidden or 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_allowed_fields_on_restricted_type', function( $fields, $model_name, $data, $visibility, $owner, $current_user ) { | |
| if ( 'PostTypeObject' === $model_name ) { | |
| $fields[] = 'label'; | |
| } | |
| return $fields; | |
| }, 10, 6 ); |