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@beta -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
cd ~/postgraphile
npm install postgraphile@beta
cd ~/postgraphile
yarn add postgraphile@beta
cd ~/postgraphile
pnpm add postgraphile@beta
You can then run PostGraphile equivalent to above via:
- npm
- Yarn
- pnpm
npx postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
npx postgraphile -P postgraphile/presets/amber -e -c postgres:///mydb
npx 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
) Equivalent to:{ extends: [...] }
can be used to specify a comma-separated list of presets to add to the configuration--allow-explain
(alias:-e
) Equivalent to:{ 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
) Equivalent to:{ pgServices: [makePgService({ connectionString: '...' })] }
the PostgreSQL connection string. If omitted, inferred from environmental variables.
Examples:db
,postgres:///db
,postgres://user:password@domain:port/db?ssl=true
--superuser-connection <string>
(alias:-S
) Equivalent to:{ pgServices: [makePgService({ superuserConnectionString:'...' })] }
the PostgreSQL superuser connection string to use for installing watch fixtures (if--watch
is enabled). If omitted, the regular connection string will be used.--schema <string>
(alias:-s
) Equivalent to:{ pgServices: [makePgService({ schemas: ['...'] })] }
a comma-separated list of PostgreSQL schemas to be introspected.--watch
(alias:-w
) Equivalent to:{ grafserv: { watch: true } }
automatically updates your GraphQL schema when your database schema changes (NOTE: requires DB superuser to installpostgraphile_watch
schema)--host <string>
(alias:-n
) Equivalent to:{ grafserv: { host: 'localhost' } }
the hostname to be used. Defaults tolocalhost
--port <number>
(alias:-p
) Equivalent to:{ 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:
pgl
has nopeerDependencies
- as soon as you start installing plugins that need peerDependencies you should consider moving topostgraphile
pgl
exposespostgraphile/presets/amber
aspgl/amber
(and similar forpgl/v4
andpgl/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.