The Guild LogoThe Guild Monogram
GraphQL Mesh

GraphQL Mesh

Query anything, run anywhere.

Contact Us

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:

yarn add @graphql-mesh/postgraphile

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

sources: - name: MyDb handler: postgraphile: connectionString: postgres://postgres:[email protected]/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:

yarn add @graphile/federation

and add those in your configuration file;

sources: - name: MyDb handler: postgraphile: connectionString: postgres://postgres:[email protected]/postgres appendPlugins: - "@graphile/federation"

Learn more about PostGraphile plugins

 

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.

yarn add @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.

yarn add @graphile/postgis

See more plugins to improve the experience!

 


 

Config API Reference#

  • connectionString (type: String) - A connection string to your Postgres database
  • schemaName (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 those
  • appendPlugins (type: Array of String) - Extra Postgraphile Plugins to append
  • skipPlugins (type: Array of String) - Postgraphile Plugins to skip (e.g. "graphile-build#NodePlugin")
  • options - - Extra Postgraphile options that will be added to the postgraphile constructor. It can either be an object or a string pointing to the object's path (e.g. "./my-config#options"). See the postgraphile docs for more information. One of:
    • JSON
    • String
  • subscriptions (type: Boolean) - Enable GraphQL websocket transport support for subscriptions (default: true)
  • live (type: Boolean) - Enables live-query support via GraphQL subscriptions (sends updated payload any time nested collections/records change) (default: true)