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_pre_resolve_field', function( $nil, $source, $args, \WPGraphQL\AppContext $context, \GraphQL\Type\Definition\ResolveInfo $info, $type_name, $field_key, $field, $field_resolver ) { | |
| if ( 'RootQueryToShippingMethodConnection' === $type_name ) { | |
| if ( 'nodes' === $field_key ) { | |
| if ( ! empty( $source['nodes'] ) && is_array( $source['nodes'] ) ) { | |
| $nodes = []; | |
| foreach ( $source['nodes'] as $node ) { | |
| $nodes[] = \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_shipping_method( $node ); | |
| } |
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() { | |
| return; | |
| $users = graphql([ | |
| 'query' => ' | |
| { | |
| users(first:100) { | |
| nodes { | |
| databaseId | |
| } | |
| } |
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
| // src/pages/Blog.vue | |
| <template> | |
| <Layout> | |
| <section> | |
| <article v-for="(post, index) in $static.posts.edges" :key="index"> | |
| <h1>{{ post.node.title }}</h1> | |
| <p> | |
| By <span>{{ post.node.author.node.name }}</span> on | |
| {{ getDate(post.node.date) }} |
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
| <script> | |
| export default { | |
| methods: { | |
| getDate(date) { | |
| const newDate = new Date(date); | |
| const newDateString = `${newDate.toLocaleString("default", { | |
| month: "long", | |
| })}, ${newDate.getDate()} ${newDate.getFullYear()}`; | |
| return newDateString; | |
| }, |
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
| // src/pages/Blog.vue | |
| <static-query> | |
| query { | |
| posts { | |
| edges { | |
| node { | |
| title | |
| content | |
| uri |
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
| // src/templates/Post.vue | |
| <article> | |
| <h1 class="title">{{ $page.post.title }}</h1> | |
| <div class="content" v-html="$page.post.content"></div> | |
| </article> |
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
| <template> | |
| <div> | |
| <h1 v-html="$page.post.title" /> | |
| <div v-html="$page.post.content" /> | |
| </div> | |
| </template> | |
| <page-query> | |
| query ($id: ID!) { | |
| post(id: $id) { |
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( 'plugins_loaded', function() { | |
| if ( ! class_exists( 'Redux' ) ) { | |
| return; | |
| } | |
| add_action( 'redux/loaded', function( $redux ) { | |
| if ( ! isset( $redux->sections ) || empty( $redux->sections ) ) { | |
| return; |
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 ); |