Skip to content

Instantly share code, notes, and snippets.

View jasonbahl's full-sized avatar
:octocat:

Jason Bahl jasonbahl

:octocat:
View GitHub Profile
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`}}>
@jasonbahl
jasonbahl / query-posts
Created September 16, 2021 21:43
Query for posts, authors and terms
{
posts {
nodes {
id
title
author {
node {
id
firstName
avatar {
@jasonbahl
jasonbahl / update-wp-graphql-woocommerce-resolveNode.php
Created July 29, 2021 15:18
Allow WPGraphQL for WooCommerce resolveNode callbacks to work with WPGraphQL v1.15+
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 );
}
@jasonbahl
jasonbahl / functions.php
Created July 27, 2021 04:27
Create new posts with unique authors
add_action( 'init', function() {
return;
$users = graphql([
'query' => '
{
users(first:100) {
nodes {
databaseId
}
}
// 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) }}
<script>
export default {
methods: {
getDate(date) {
const newDate = new Date(date);
const newDateString = `${newDate.toLocaleString("default", {
month: "long",
})}, ${newDate.getDate()} ${newDate.getFullYear()}`;
return newDateString;
},
// src/pages/Blog.vue
<static-query>
query {
posts {
edges {
node {
title
content
uri
// src/templates/Post.vue
<article>
<h1 class="title">{{ $page.post.title }}</h1>
<div class="content" v-html="$page.post.content"></div>
</article>
<template>
<div>
<h1 v-html="$page.post.title" />
<div v-html="$page.post.content" />
</div>
</template>
<page-query>
query ($id: ID!) {
post(id: $id) {
add_action( 'plugins_loaded', function() {
if ( ! class_exists( 'Redux' ) ) {
return;
}
add_action( 'redux/loaded', function( $redux ) {
if ( ! isset( $redux->sections ) || empty( $redux->sections ) ) {
return;