Skip to content

Instantly share code, notes, and snippets.

View benjie's full-sized avatar

Benjie benjie

View GitHub Profile
@benjie
benjie / JSONL.md
Last active March 18, 2024 10:55
Alternative ways of representing incremental delivery over HTTP

Streamed JSONL

Each payload is just appended as a condensed JSON (no newlines!) payload, with a newline at the end:

HTTP/1.1 200 OK
Content-Type: application/graphql-response+jsonl
Cache-Control: no-cache

{"data":{...},"hasNext":true}
@benjie
benjie / graphql@15.5.0.patch
Created December 20, 2023 11:28
Patch for bug in OverlappingFieldsCanBeMergedRule in graphql@^15; apply with `patch-package` or `pnpm patch` or similar.
diff --git a/validation/rules/OverlappingFieldsCanBeMergedRule.js b/validation/rules/OverlappingFieldsCanBeMergedRule.js
index 3fd18139ada7a3e766c78725c8a05ad18a42cddd..ec3cc13ce8efc700f39a4d0fc0f96331b7708906 100644
--- a/validation/rules/OverlappingFieldsCanBeMergedRule.js
+++ b/validation/rules/OverlappingFieldsCanBeMergedRule.js
@@ -180,6 +180,23 @@ function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFiel
// and any fragment names found in the given fragment.
for (var i = 0; i < fragmentNames2.length; i++) {
+ // Memoize so two fragments are not compared for conflicts more than once.
+ const referencedFragmentName = fragmentNames2[i];
@benjie
benjie / SemanticNonNullSyntax.graphql
Last active February 9, 2024 16:56
Ideas for what the SemanticNonNull syntax could look like
type User {
id: ID!
username: String*
avatarUrl: String
bio: String
friends: [User*]*
}
type User {
id: ID!
username: ~String
declare global {
namespace GraphileBuild {
interface PgCodecTags {
// This enables TypeScript autocomplete for our @group smart tag
group?: string | string[];
}
interface Inflection {
// Our inflector to pick the name of the grouped type, e.g. `User` table
// type, and `address` group might produce `UserAddress` grouped type name
groupedTypeName(details: {
@benjie
benjie / run-in-console.js
Last active February 19, 2024 11:50
GitHub pull request JS snippet to mark all ".mermaid" files as viewed (substitute for any file extension)
((suffix) => {let abort = false; [...$$(`a[title$="${suffix}"]`)].map(el => {const checks = el.parentNode.parentNode.parentNode.querySelectorAll('.js-reviewed-checkbox');if (checks.length !== 1) { throw new Error("Script out of date?");} return checks[0]}).forEach((inpt, i) => setTimeout(() => {if (abort || inpt.checked) return; inpt.click();}, i * 1000))})(".mermaid")
a = () => () => () => 2;
console.log(a``````);

PostGraphile reproduction script

Hello, you've probably been sent here because you've found an issue in your usage of PostGraphile. I (Benjie) deal with a lot of support requests that have insufficient information for me to diagnose the problem, so I'll ask for a minimal reproduction. Making a minimal reproduction allows me to diagnose (and potentially fix!) the issue much more easily, and is also a valuable exercise for you during your debugging - who knows, maybe whilst attempting to create the reproduction you'll figure out what went wrong and fix your own issue?

To use this, please download the script locally, and then populate the DATABASE

@benjie
benjie / swc.js
Last active October 26, 2021 12:03
A script for running SWC in a monorepo that uses TypeScript project references (`tsc --build` / `tsc -b`) compiling everything in parallel with optional watch mode. For this to work you MUST have `isolatedModules: true`.
const swc = require("@swc/core");
const chokidar = require("chokidar");
const glob = require("glob");
const { promises: fsp } = require("fs");
const { basename, dirname } = require("path");
const { createHash } = require("crypto");
const mkdirp = require("mkdirp");
const WATCH = process.argv[2] === "--watch";
#!/usr/bin/env bash
set -e
# What DB are we messing with? (THIS DB WILL BE OVERWRITTEN!)
DATABASE="timethor"
SCHEMA="main"
# Populate database
dropdb --if-exists "$DATABASE"
createdb "$DATABASE"
import { Plugin } from 'postgraphile';
/**
* Allows you to override the default orderBy for a given field to be the
* orderBy with the given name. Usage:
*
* ```
* const MyOrderByPlugin = makeSetDefaultOrderByForFieldPlugin(
* 'MyTableName',
* 'myRelationName',