PostGraphile

Instant GraphQL API for PostgreSQL database


Try it now!

The fastest way to get a full GraphQL API up and running based on a PostgreSQL database schema.

npm install -g postgraphile
postgraphile -c postgres://user:[email protected]/dbname \
  --schema schema_name

Solves N+1 queries issues

Using graphile-build's look-ahead features a single root level GraphQL query, no matter how nested, can become just one SQL query.

Customisable with SQL

PostGraphile supports custom queries, custom mutations and computed columns in your PostgreSQL database automatically.

Customisable with JS plugins

The GraphQL schema PostGraphile uses is entirely built from Graphile Build plugins, you can disable any of the built in plugins to restrict the functionality or add additional plugins to extended or enhanced your generated schema.

This allows you to add (or remove) fields, create new types, add functionality, replace functionality or or even tweak existing functionality (e.g. wrapping an existing resolver with your own higher-order function) to gain powerful control over your API.

Build your schema with plugins
buildSchema(plugins)
 
type Person {
  # @deprecated Use 'name' instead
  # The person's first name
  firstName: String

  #...
Transform your schema with ease
buildSchema([...plugins,
  DeprecateFromCommentPlugin])
type Person {
  # The person's first name
  firstName: String @deprecated(
    reason: "Use 'name' instead")

  #...

Fully compatible

Graphile uses the reference GraphQL implementation under the hood, so you know it's spec compliant.

You can use regular GraphQL objects from other libraries in your generated schema - you only need to change the parts of your code that you wish to trigger hooks for.

GraphiQL with auto-generated documentation

GraphiQL displaying allSuperheroes

PostgreSQL schema watching

PostGraphile has an excellent developer experience (DX) when you use the --watch CLI flag - it will automatically re-generate the GraphQL schema when your database changes. What's more, it will automatically reload GraphiQL's documentation too, so you can see your new schema features right away! No need to restart the server!

Secure

Using PostgreSQL's Role-Based Access Control (RBAC) and Row-Level Security policies (RLS, introduced in PostgreSQL 9.5), PostGraphile leverages the tried-and-tested authentication baked right in to the worlds most advanced open source database - no more reinventing the wheel! Thanks to RLS's granularity it's possible to express complex authorisation logic in simple policies; and because the authentication is in your database you can ensure nothing (not even companion microservices) can bypass it.

PostGraphile uses industry standard JWT authentication, allowing for stateless authorisation which also works great with CORS.

Quick to start

npm install -g postgraphile
postgraphile -c postgres://user:[email protected]/dbname \
  --schema schema_name

Questions, comments or feedback?
Email [email protected]

Keep up to date on Graphile and PostGraphile features/changes. Subscribe to our occasional announcements newsletter: