Skip to content

A Fastify plugin for integrating PostGraphile schemas with Mercurius

License

Notifications You must be signed in to change notification settings

autotelic/mercurius-postgraphile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mercurius PostGraphile

A Fastify plugin for integrating PostGraphile schemas with Mercurius

Contents

Usage

npm i @autotelic/mercurius-postgraphile
const mercuriusPostGraphile = require('@autotelic/mercurius-postgraphile')
const { Pool } = require('pg')
const connectionString = process.env.DATABASE_URL
const pgPool = new Pool({ connectionString })

module.exports = async function (fastify, options) {
  fastify.register(mercuriusPostGraphile, {
    connectionString,
    pgPool
  })
}

API

Options

Name Status Type Default Description
connectionString Required String - A postgreSQL database connection string, i.e. postgres://postgres:password@0.0.0.0:5432/postgres?sslmode=disable.
pgPool Required Object - A client or pool instance that will be passed to the pg library and used to connect to a PostgreSQL backend.
instanceName Optional String public A string which specifies the PostgreSQL schema that PostGraphile will use to create a GraphQL schema.
localStitchOpts Optional Object {} An object containing local subschema config options.
postGraphileStitchOpts Optional Object {} An object containing PostGraphile subschema config options. stitchOpts for both the local and PostGraphile schemas implement the SubschemaConfig interface. Documention can be found here
postGraphileContextOpts Optional Object/Function {} An object or callback function containing withPostGraphileContext options, outlined here
postGraphileSchemaOpts Optional Object {} An object containing createPostGraphileSchema options, outlined here

Run the Example

Install Dependencies and Run a Local Postgres Container

npm i
docker-compose up -d

Run the server

npm run example

Make Requests to the Server

http :3000/graphql
http POST :3000/graphql

Explore Graphiql

http://localhost:3000/graphiql

The user query from PostGraphile and the localUser query from Mercurius are used to merge the User type. Check out the example to explore the stitch options implemented in merging the local and PostGraphile schemas.

query {
  user(id: 1) {
    username
    verified
  }
  localUser(id: 1) {
    username
    verified
  }
}

Resources

About

A Fastify plugin for integrating PostGraphile schemas with Mercurius

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •