Skip to content

Instantly share code, notes, and snippets.

View benjie's full-sized avatar

Benjie benjie

View GitHub Profile
@benjie
benjie / strip_tags_from_introspection.js
Created May 21, 2021 15:24
A Graphile Engine plugin to strip all tags/descriptions from introspection results
module.exports = (builder) => {
builder.hook("build", (build) => {
const oldPgAugmentIntrospectionResults =
build.pgAugmentIntrospectionResults;
build.pgAugmentIntrospectionResults = (inIntrospectionResult) => {
let pgIntrospectionResultsByKind = inIntrospectionResult;
if (oldPgAugmentIntrospectionResults) {
pgIntrospectionResultsByKind = oldPgAugmentIntrospectionResults(
pgIntrospectionResultsByKind,
);
const symbols = [];
for (let i = 0; i < 1000; ++i) {
symbols[i] = Symbol(`key_${i}`);
//symbols[i] = `key_${i}`;
}
function test1() {
const map = new Map();
for (let i = 0; i < 10000; ++i) {
SELECT
pg_size_pretty(total_bytes) AS total,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(toast_bytes) AS toast,
pg_size_pretty(total_bytes - index_bytes - toast_bytes) AS table
FROM (
SELECT
pg_total_relation_size(c.oid) AS total_bytes,
pg_indexes_size(c.oid) AS index_bytes,
coalesce(pg_total_relation_size(reltoastrelid), 0) AS toast_bytes
@benjie
benjie / loop_perf.js
Last active June 4, 2021 13:58
Comparing loop method performance in JS
const arr = [];
const ARRAY_SIZE = parseInt(process.argv[2], 10) || 10;
const RUNS = Math.ceil(1000000000 / ARRAY_SIZE);
console.log(`Performing ${RUNS} runs of arrays with ${ARRAY_SIZE} elements`);
for (let i = 0; i < ARRAY_SIZE; i++) arr[i] = i;
function runTest(name, testFunction) {
if (global.gc) global.gc();
@benjie
benjie / PostGraphile_introspection.sql
Created March 9, 2021 19:35
PostGraphile introspection query
-- This is a compiled version of the PostGraphile introspection query.
-- The query that would actually run may differ from this based on
-- what version of PostgreSQL you're running and what your PostGraphile
-- options are.
-- @see https://www.postgresql.org/docs/9.5/static/catalogs.html
-- @see https://github.com/graphile/graphile-engine/blob/master/packages/graphile-build-pg/src/plugins/introspectionQuery.js
--
with
accessible_roles(_oid) as (
@benjie
benjie / oneof_syntax.md
Last active January 23, 2021 10:47
Potential ideas for syntax to use for the "oneof" input/argument/output polymorphism proposal to the GraphQL Spec.

oneof syntax discussion

After going full circle on @oneField directive -> tagged type -> back again, the GraphQL Input Unions Working Group have determined that our current best proposal is to add a variant of the existing input object type that accepts only one field, and a variant of object fields that accept only one argument. Though the changes to introspection for this are likely to be relatively small (e.g. adding something like __Type.isOneOf: Boolean and `__Field.isOneOf:

@benjie
benjie / DeprecateTypePlugin.ts
Created August 13, 2020 18:38
Deprecate all fields that reference a named output type in Graphile Engine
import type { Plugin } from "graphile-build";
const makeDeprecateTypePlugin = (typeName: string, deprecationReason: string): Plugin => builder => {
builder.hook('GraphQLObjectType:fields:field', (field, { graphql }) => {
if (graphql.getNamedType(field.type).name !== typeName) {
return field;
}
return {
...field,
deprecationReason,
const { promises: fsp } = require("fs");
async function main(name) {
const content = await fsp.readFile(`./${name}.test.ts.snap`, "utf8");
const lines = content.split("\n");
const results = {};
let header = "";
for (let lineNumber = 0; lineNumber < lines.length; lineNumber++) {
const line = lines[lineNumber];
if (line.startsWith("//")) {
@benjie
benjie / OneOfExploration.md
Last active December 4, 2023 14:41
Exploring how `oneOf` could work in a GraphQL schema

oneOf exploration

This document is a work-in-progress exploration of how the "oneOf" solution to input polymorphism might work within a GraphQL schema.

Base schema

For the examples below, we'll be using the following shared types using existing GraphQL syntax:

@benjie
benjie / .gmrc
Created October 10, 2019 15:51
Example gmrc from https://github.com/graphile/starter/blob/master/.gmrc (not published at time of writing)
{
"pgSettings": {
"search_path": "app_public,app_private,app_hidden,public"
},
"placeholders": {
":DATABASE_AUTHENTICATOR": "!ENV",
":DATABASE_VISITOR": "!ENV"
},
"afterReset": [
"afterReset.sql",