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 databaseschemaName(type:Array of String, required) - An array of strings which specifies the PostgreSQL schemas that PostGraphile will use to create a GraphQL schema. The default schema is the public schema.pool(type:Any) - Connection Pool instance or settings or you can provide the path of a code file that exports any of thoseappendPlugins(type:Array of String) - Extra PostGraphile v5 plugins to append (must be GraphileConfig.Plugin objects compatible with v5)skipPlugins(type:Array of String) - PostGraphile v5 plugin names to disable (e.g. “NodePlugin”)options- - A PostGraphile v5 preset object or the path to a file exporting one (e.g. ”./my-config#preset”). This is merged on top of the default PostGraphileAmberPreset. See the PostGraphile v5 docs for more information. One of:JSONString
contextOptions(type:Any) - A file that exports a function which takes mesh context as a parameter and returns extra context to merge into the GraphQL execution context (e.g. ”./my-function#getContext”). The returned object may includepgSettingsfor per-request PostgreSQL settings. See the PostGraphile v5 docs for more information.