Skip to content

Instantly share code, notes, and snippets.

@benjie
Created October 27, 2021 15:22
Show Gist options
  • Save benjie/6a40e05b484b79141ba2b492218ada17 to your computer and use it in GitHub Desktop.
Save benjie/6a40e05b484b79141ba2b492218ada17 to your computer and use it in GitHub Desktop.

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 (choose something unique, use your name or something) and SCHEMA (use whatever your PostgreSQL schema is called, if you don't know then it's probably public, but may be something like app_public or something completely different) and create a MINIMAL structure in your database where the -- YOUR SQL HERE comment is. You can even INSERT sample data there if it's needed to see the issue.

IMPORTANT: this is a bash script, so $ placeholders will be replaced. In particular this means that CREATE FUNCTION ... AS $$ will cause an error to be thrown. To resolve this, escape the dollars, e.g. CREATE FUNCTION ... AS \$\$.

Run the script and see if you can reproduce your issue at http://localhost:5000 (in GraphiQL).

If you can, great - send that on through along with the query you issued.

If you cannot, now's where you start building the reproduction script up - perhaps your database didn't have the critical information, or perhaps you need to add some more plugins. Go ahead and do that, and keep running the script until your issue is reproduced... Then STRIP THINGS OUT so that it's the smallest it can be whilst still reproducing the issue. The script should only contain essential information; if it's more than 50-60 lines long then you've definitely got too much stuff in there and there's a strong chance I'll ask you to make the script more minimal (it's currently 37 lines long).

Once you have a minimal reproduction, send me the contents of your script along with the query that you issued to see the problem.

I have limited time, please help me to help you by creating the smallest reproduction you can.

If you'd like to help buy me more time to spend on open source, please become a sponsor:

https://www.graphile.org/sponsor/


PHONE CALLS AVAILABLE: if your issue is really holding you up and open source response times aren't good enough (and you don't already have a support contract) you can book an hour with me on screen sharing: https://benjie.dev

#!/usr/bin/env bash
set -e
# What DB are we messing with? (THIS DB WILL BE OVERWRITTEN!)
DATABASE="issue-1234"
SCHEMA="app_public"
# Populate database
dropdb --if-exists "$DATABASE"
createdb "$DATABASE"
psql -X1v ON_ERROR_STOP=1 "$DATABASE" <<HERE
create schema $SCHEMA;
-- YOUR SQL HERE
HERE
# Install deps
yarn add --dev postgraphile @graphile-contrib/pg-simplify-inflector
# Run PostGraphile
yarn postgraphile \
--subscriptions \
--watch \
--dynamic-json \
--no-setof-functions-contain-nulls \
--no-ignore-rbac \
--no-ignore-indexes \
--show-error-stack=json \
--extended-errors hint,detail,errcode \
--append-plugins @graphile-contrib/pg-simplify-inflector \
--graphiql "/" \
--enhance-graphiql \
--allow-explain \
--enable-query-batching \
--legacy-relations omit \
--connection "$DATABASE" \
--schema "$SCHEMA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment