Skip to content

Instantly share code, notes, and snippets.

Avatar

Kellen Mace kellenmace

View GitHub Profile
View pagination-fields.php
<?php
/**
* Plugin Name: Pagination Fields
* Description: Adds next & prev post data to WPGraphQL schema
* Version: 0.1.0
* Author: Kellen Mace
* Author URI: https://kellenmace.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
View user.ts
import { supabase } from '$lib/supabaseClient';
import type { AuthUser } from '@supabase/supabase-js';
import { writable } from 'svelte/store';
import type { Profile } from '../types/supabase';
interface User extends Omit<AuthUser, 'email'>, Profile {};
export const user = writable<User | undefined>(undefined);
supabase.auth.onAuthStateChange(async (event, session) => {
@kellenmace
kellenmace / faust-post-filtering-example.tsx
Created November 17, 2021 18:32
Faust.js Post Filtering Example
View faust-post-filtering-example.tsx
import { useState, useMemo } from "react";
import { getNextStaticProps } from '@faustjs/next';
import { GetStaticPropsContext } from 'next';
import { client } from '../../client';
import debounce from "just-debounce-it";
export default function Blog() {
const { usePosts, useQuery } = client;
const [selectedCategory, setSelectedCategory] = useState(undefined);
const [selectedAuthor, setSelectedAuthor] = useState(undefined);
@kellenmace
kellenmace / wpgraphql-user-meta-fields.php
Last active October 19, 2021 14:37
WPGraphQL User Meta Example
View wpgraphql-user-meta-fields.php
<?php
namespace MyCoolApp;
use WPGraphQL\Model\User;
class UserFields {
public function register_hooks() {
add_action( 'graphql_register_types', [ $this, 'register_fields' ] );
}
View set-organisation-posts-to-private.php
<?php
/**
* Set Organization posts to 'private' for unauthenticated users.
*
* @param boolean $is_private Whether the model is private
* @param string $model_name Name of the model the filter is currently being executed in
* @param mixed $data The un-modeled incoming data
* @param string|null $visibility The visibility that has currently been set for the data at this point
* @param null|int $owner The user ID for the owner of this piece of data
@kellenmace
kellenmace / index.js
Last active November 20, 2021 07:08
Get YouTube Video Transcript in JavaScript
View index.js
const fetch = require("node-fetch");
const xml2js = require("xml2js");
const he = require("he");
const TRANSCRIPTION_CHAR_KEY = "transcription";
// Test
(async () => {
const videoId = "ht14hTTDklA"; // HWPR Pagination video
// const videoId = "rB9ql0L0cUQ"; // Video with manually added captions
View wpgraphql-get-tag-url-paths.php
<?php
// Get all tag url paths for sitemap.
add_action('graphql_register_types', function () {
register_graphql_field('RootQuery', 'getTagUrlPaths', [
'type' => ['list_of' => 'String'],
'args' => [
'pageNo' => [
'type' => 'Int',
'description' => __('Page number', 'text-domain'),
View gatsbyPaginatedList.tsx
import { gql, useLazyQuery } from "@apollo/client";
import Layout from "../components/Layout";
interface Post {
databaseId: number;
title: string;
};
interface PostEdge {
@kellenmace
kellenmace / dynamic-module-import.js
Created March 18, 2021 16:56
Dynamically import an NPM module from dev.jspm.io to try it out
View dynamic-module-import.js
// Dynamically import an NPM module from dev.jspm.io to try it out.
// Run this in your browser console.
(async function() {
const axios = (await import('https://dev.jspm.io/axios')).default;
const response = await axios.get('https://pokeapi.co/api/v2/pokemon/');
console.log(response.data);
})();
@kellenmace
kellenmace / debugging-methods.md
Created January 12, 2021 01:59
Traditional vs. Headless WordPress Debugging Methods
View debugging-methods.md
TRADITIONAL HEADLESS
WP_DEBUG_DISPLAY 👉 Enable WPGraphQL Debug Mode & inspect response errors
die() / wp_die() / var_dump() 👉 wp_send_json() or Enable GraphQL Debug Mode and use graphql_debug()
Postman/REST client 👉 Enable GraphiQL IDE
WP_DEBUG_LOG 👉 Still works!
Xdebug on page load 👉 Xdebug triggered by GraphiQL request in the wp-admin
Query Monitor 👉 Enable GraphQL Query Logs
NewRelic/Profiling tools 👉 Enable GraphQL Tracing