Skip to Content
Mesh
v0Source HandlersPostgreSQL / PostGraphile
⚠️
This is the documentation for the old GraphQL Mesh version v0. We recommend upgrading to the latest GraphQL Mesh version v1.

Migrate to GraphQL Mesh v1

PostgreSQL / PostGraphile

image

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/postgraphile

Now, you can use it directly in your Mesh config file:

.meshrc.yaml
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/postgres
💡

You 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/federation

and add those in your configuration file;

.meshrc.yaml
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-many

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
💡

See 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 when pool is an existing pg.Pool (or module export).
  • schemaName (type: Array of String) - 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) - Existing pg.Pool instance, 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); connectionString may be omitted.
  • tables (type: Array of String) - Use specific tables for your schema
  • tableFields (type: Array of Object) - Use specific fields of specific tables:
    • table (type: String, required)
    • fields (type: Array of String, required)
Last updated on