This software is in beta, please be sure to use the
@beta tag when installing any of the related modules, for example:
yarn add postgraphile-plugin-connection-filter@beta
Coming from PostGraphile Version 4? Check out the migration guide!
If you already use PostgreSQL then you understand the value that a strongly typed and well defined schema can bring to application development; GraphQL is the perfect match for this technology when it comes to making your data layer accessible to your frontend application developers (or even API clients).
PostGraphile uses automation and intelligent defaults to eradicate the time consuming and repetitive parts of building a best practices GraphQL API, whilst giving you the tools you need to customize and extend your schema to be exactly what you need. And because it's powered by Grafast it's extremely unlikely that you'd be able to build a GraphQL API using traditional GraphQL/DataLoader patterns that's anywhere near as fast as a PostGraphile API - it truly runs rings around traditional API development practices.
PostGraphile doesn't have to be (and generally should not be) a "1-to-1 map" of your database.
Via schema extensions you can add any types/fields/args that you need to, which can communicate with any data source that Node itself can communicate with. You can also use the plugin interface to wrap plan resolvers with your own logic, which gives huge control over authorization, presentation, filtering, and various other topics.
PostGraphile will automatically reflect the permissions in your database and only expose the tables, columns, functions and mutations that are granted to it; but you should use smart tags and similar techniques to hone the GraphQL API to your needs.
By exporting the executable schema you can see the plan resolvers/types/fields that PostGraphile has generated for you and, should you choose to, you can take this code and make it your own - either for the entire schema, or for specific portions of it. This can be used to enable you to evolve your database tables without breaking your GraphQL schema.
We strongly advise that you start with as small a GraphQL API as you can, and then add features to it as you need them, rather than going for a "kitchen sink" approach!
If your company needs a GraphQL API and the data the API serves comes mostly (but not exclusively!) from PostgreSQL databases then PostGraphile can help you craft your perfect GraphQL API in a matter of days, if not hours; saving you weeks if not months of development time.
For databases that already use row-level security you might be able to build a secure, performant and extensible GraphQL API in mere minutes. We still recommend that you take some time to hone your API though!
If you are new to GraphQL we recommend you read through the official introduction to GraphQL here before continuing through the PostGraphile documentation.
Some of the features we offer:
- Incredible performance - even for your custom logic!
- Full GraphQL feature-set, including advanced topics such as:
- Excellent Relay support via our
- Global object identification
- Cursor pagination
- Mutation input objects and payloads
- Massively reduced load on your database without the complexity of caching/cache invalidation
- Integrates with any authentication middleware available in Node
- Easily add fields and mutations via JS/TS plugins or database functions
- Written in pure TypeScript - no binary modules!
- Very fast startup in serverless
- Bring your own PostgreSQL driver/adaptor (integrate with almost any Postgres client library)
- Run as a CLI, as a Node.js middleware, or a standalone GraphQL schema
- Easy customization via smart tags
- Explain your operations via Ruru (our Grafast-enhanced GraphiQL IDE)
- Auto-discovered relations
- Automatic CRUD mutations e.g.
- Almost all features are optional, and most can be customised on a per-table, per-column or per-constraint basis (as appropriate)
- Incredible versatility via a wide array of plugins:
- Powerful filtering
- Soft deletion
- Many-to-many navigation
- Ordering by related tables
- And many many more...
The easiest way to get started is with the CLI interface; if you
npx installed you can try it out with:
npx pgl@beta -P pgl/amber -e -c 'postgres:///mydb'
(Replace the connection string with a PostgreSQL connection string to your
database. If your data is not located in the
public schema of your database
you can specify a comma-separated list of database schemas with