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( 'register_post_type_args', function( $args, $post_type ) { | |
if ( 'wp_template_part' === $post_type ) { | |
$args['show_in_graphql'] = true; | |
$args['graphql_single_name'] = 'TemplatePart'; | |
$args['graphql_plural_name'] = 'TemplateParts'; | |
} | |
return $args; |
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 Request Logger | |
* Description: This plugin logs WPGraphQL Requests to a Custom Post Type. This is a debugging tool. Not intended for production use. Also, not fully tested. Use at your own risk. | |
* Plugin Author: Jason Bahl | |
* Author URI: https://www.wpgraphql.com | |
*/ | |
add_action( 'init', function() { | |
register_post_type( 'graphql_request_logs', [ |
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
// NOTE, THIS IS VERY EXPERIMENTAL. TAKE THIS WITH A BIG GRAIN OF SALT, BUT DO WHAT YOU WILL WITH IT. | |
register_graphql_object_type("ThemeSettings", [ | |
'description' => 'Theme Settings', | |
'fields' => [ | |
'primaryColor' => [ | |
'type' => 'string', | |
'description' => 'Primary Color', | |
'resolve' => function ($settings) { | |
$colors = $settings->settings->color->palette->theme; |
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 ( 'content' === $field_key && 'Post' === $type_name ) { | |
return 'your override value'; | |
} | |
return $default; | |
}, 10, 9 ); |
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
const { hooks, useAppContext } = wpGraphiQL | |
const { useState } = wp.element | |
const DemoButton = props => { | |
const { GraphiQL, graphiql } = props; | |
const [ count, setCount ] = useState( 0 ) | |
return ( |
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
/** | |
* This is an example showing how to add a custom action | |
* to the operation action menu | |
*/ | |
hooks.addFilter( | |
"graphiql_operation_action_menu_items", | |
"graphiql-extension", | |
(menuItems, props) => { | |
const { Menu } = props; |
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
const { hooks } = wpGraphiQL; | |
import LZString from 'lz-string' | |
hooks.addFilter( 'graphiql_after_graphiql', 'wp-graphiql-extension', (res, props) => { | |
const encoded = LZString.compressToEncodedURIComponent(props.query) | |
const decoded = LZString.decompressFromEncodedURIComponent(encoded) | |
res.push( | |
<div style={{maxWidth: `200px`}}> |
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
{ | |
posts { | |
nodes { | |
id | |
title | |
author { | |
node { | |
id | |
firstName | |
avatar { |
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( $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 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 | |
} | |
} |