Command Line Interface
The easiest way to get up and running with PostGraphile is to use the Command Line Interface.
To try without installing, run the pgl command via the npx command that
comes bundled with Node.js:
npx pgl -P pgl/amber -e -c postgres:///mydb
You should replace postgres:///mydb with a PostgreSQL connection string
pointing at your database, and if you use a non-standard PostgreSQL schema you
should indicate the schema name via -s my_schema_name_here.
For a more permanent installation we suggest you create yourself a new
directory for your project, we'll refer to this as ~/postgraphile. Open a
terminal in this directory and install PostGraphile:
- npm
- Yarn
- pnpm
- Bun
cd ~/postgraphile
npm install postgraphile@rc
cd ~/postgraphile
yarn add postgraphile@rc
cd ~/postgraphile
pnpm add postgraphile@rc
cd ~/postgraphile
bun add postgraphile@rc
You can then run PostGraphile equivalent to above via:
- npm
- Yarn
- pnpm
- Bun
npx postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
yarn dlx postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
pnpm dlx postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
bun x postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
The -e option should only be used in development.
CLI flags
The CLI accepts a small number of configuration options to get you started. It
also reads options from a graphile.config.js file from the
current working directory (if it exists); by specifying all options in this file
you can run PostGraphile with no (or minimal) CLI flags.
--version
output the version number--help
output usage information--preset <string>(alias:-P){ extends: [...] } can be used to specify a comma-separated list of presets to add to the configuration--allow-explain(alias:-e){ grafast: { explain: true } } enables "explain" mode, you won't want this in production but it's very helpful in development to know what's going on--connection <string>(alias:-c){ pgServices: [makePgService({ connectionString: '...' })] } the PostgreSQL connection string. If omitted, inferred fromenvironmental variables
.
Examples:db,postgres:///db,postgres://user:password@domain:port/db?ssl=true--superuser-connection <string>(alias:-S){ pgServices: [makePgService({ superuserConnectionString:'...' })] } the PostgreSQL superuser connection string to use for installing watch fixtures (if--watchis enabled). If omitted, the regular connection string will be used.--schema <string>(alias:-s){ pgServices: [makePgService({ schemas: ['...'] })] } a comma-separated list of PostgreSQL schemas to be introspected.--watch(alias:-w){ grafserv: { watch: true } } automatically updates your GraphQL schema when your database schema changes (NOTE: requires DB superuser to installpostgraphile_watchschema)--host <string>(alias:-n){ grafserv: { host: 'localhost' } } the hostname to be used. Defaults tolocalhost--port <number>(alias:-p){ grafserv: { port: 5678 } } the port to be used. Defaults to 5678
pgl vs postgraphile
New to V5 if PostGraphile is the pgl command. This is almost identical to the
postgraphile command (it actually defers to postgraphile under the hood),
with the following differences:
pglhas nopeerDependencies- as soon as you start installing plugins that need peerDependencies you should consider moving topostgraphilepglexposespostgraphile/presets/amberaspgl/amber(and similar forpgl/v4andpgl/relay), so it's more concise
pgl is most suitable for running from npx without the need to permanently
install anything. If you want to start using PostGraphile in your project you
should install postgraphile instead.