PostgreSQL

This handler allows you to use the GraphQL schema created by PostGraphile, based on a PostgreSQL database schema.
How to use?
To get started, install the handler library:
npm i @omnigraph/postgraphileNow, you can use it directly in your Mesh config file:
mesh.config.ts
import { defineConfig } from '@graphql-mesh/compose-cli'
import { loadPostgraphileSubgraph } from '@omnigraph/postgraphile'
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadPostgraphileSubgraph('MyPostgreSQL', {
connectionString: 'postgres://postgres:password@localhost/postgres'
// You can also use environment variables like below
// connectionString: `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@localhost/postgres`
})
}
]
})Configuration
| Parameter | Type | Description |
|---|---|---|
connectionString | string | A connection string to your Postgres database |
schemas | string[] | PostgreSQL schemas PostGraphile will use (default: ['public']) |
appendPlugins | GraphileConfig.Plugin[] | Extra PostGraphile v5 plugins to append |
skipPlugins | string[] | PostGraphile v5 plugin names to disable (e.g. "NodePlugin") |
options | GraphileConfig.Preset | A PostGraphile v5 preset object merged on top of the default PostGraphileAmberPreset |
Gateway
When using the composed schema with @graphql-hive/gateway, install the transport package:
npm i @graphql-mesh/transport-postgraphileThe transport is automatically detected from the composed schema and used by the gateway.
Many-to-Many support
Suppose you want to have automatic many-to-many mapping across your entities. You can install
@graphile-contrib/pg-many-to-many and add it under appendPlugins.
npm i @graphile-contrib/pg-many-to-manymesh.config.ts
// @ts-ignore - not typed
import PgManyToManyPlugin from '@graphile-contrib/pg-many-to-many'
import { defineConfig } from '@graphql-mesh/compose-cli'
import { loadPostgraphileSubgraph } from '@omnigraph/postgraphile'
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadPostgraphileSubgraph('MyPostgreSQL', {
connectionString: 'postgres://postgres:password@localhost/postgres',
appendPlugins: [PgManyToManyPlugin]
})
}
]
})PostGIS Support
If you use PostGIS in your PostgreSQL database, you need to install @graphile/postgis package
and add it under appendPlugins.
npm i @graphile/postgis