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
| $opt_name = 'graphql_demo'; | |
| $theme = wp_get_theme(); // For use with some settings. Not necessary. | |
| $args = array( | |
| 'display_name' => $theme->get( 'Name' ), | |
| 'display_version' => $theme->get( 'Version' ), | |
| 'menu_title' => esc_html__( 'Sample Options', 'redux-framework-demo' ), | |
| 'customizer' => true, | |
| ); |
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' => 'RootQuery', | |
| 'toType' => 'Post', | |
| 'fromFieldName' => 'popularPosts', | |
| 'connectionTypeName' => 'RootQueryToPopularPostsConnection', | |
| 'resolve' => function( $root, $args, \WPGraphQL\AppContext $context, $info ) { | |
| $resolver = new \WPGraphQL\Data\Connection\PostObjectConnectionResolver( $root, $args, $context, $info ); |
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', |