Migrate to GraphQL Mesh v1
PostgreSQL / PostGraphile

This handler allows you to use the GraphQL schema created by PostGraphile , based on a PostgreSQL database schema.
To get started, install the handler library:
npm i @graphql-mesh/postgraphileNow, you can use it directly in your Mesh config file:
sources:
- name: MyDb
handler:
postgraphile:
connectionString: postgres://postgres:password@localhost/postgres
# You can also use environment variables like below
# connectionString: postgres://{env.POSTGRES_USER}:{env.POSTGRES_PASSWORD}@localhost/postgresYou can check out our example that uses schema stitching with a PostgreSQL data source. Click here to open the example on GitHub .
External Plugins (e.g. FederationPlugin, PgManyToManyPlugin, PostGISPlugin)
You can add PostGraphile plugins for example FederationPlugin. You can install it like below:
npm i @graphile/federationand add those in your configuration file;
sources:
- name: MyDb
handler:
postgraphile:
connectionString: postgres://postgres:password@localhost/postgres
appendPlugins:
- '@graphile/federation'Learn more about PostGraphile plugins here .
Federation and Automatic Type Merging support
The Federation plugin converts your Postgraphile schema into a federated schema that can also be
recognized by Stitching, which brings Automatic Type Merging. So you can install
@graphile/federation package like above and add it under appendPlugins.
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-manyPostGIS Support
If you use PostGIS in your PostgreSQL database, you need to install @graphile/postgis package
and add it under appendPlugins.
npm i @graphile/postgisSee more plugins to improve the experience!
Config API Reference
connectionString(type:String) - A connection string to your Postgres database (postgres://…/postgresql://…). Supports Mesh env interpolation (e.g.postgres://{env.PGUSER}:…). Optional whenpoolis an existingpg.Pool(or module export).schemaName(type:Array of String, required) - PostgreSQL schema(s) to introspect (default: public). Only the first entry is used — multi-schema PostGraphile setups are not supported on this path.pool(type:Any) - Existingpg.Poolinstance, or a module path that exports one (modulePath#exportName). Plain pool settings objects are ignored. When set, introspection and execution reuse this pool (including TLS);connectionStringmay be omitted.tables(type:Array of String, required) - Use specific tables for your schematableFields(type:Array of Object, required) - Use specific fields of specific tables:table(type:String, required)fields(type:Array of String, required)