fastify-postgraphile
enables the use of Postgraphile in a Fastify application.
Supports Fastify versions 3.x
npm i fastify-postgraphile
This is the suggested way to work and the only one directly implemented by postgraphile
.
const fastify = require('fastify')()
fastify.register(require('fastify-postgraphile'), {
pool: {
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: 'password',
port: 5432
},
schemas: 'public',
middleware: true // default
postgraphileOptions: {
// all the options you can pass to the postgraphile function
}
})
fastify.listen(3000)
Require fastify-postgraphile
and register it as any other plugin, it will add a graphql
reply decorator.
Consider that this is a mode with no built-in routes, you only have a reply decorator already attached to Postgraphile.
const fastify = require('fastify')()
fastify.register(require('fastify-postgraphile'), {
pool: {
user: 'postgres',
host: 'localhost',
database: 'postgres',
password: 'password',
port: 5432
},
schemas: 'public',
middleware: false
})
fastify.get('/', async (req, reply) => {
return reply.graphql(req.body.query, req.body.variables)
})
fastify.listen(3000)
- pool: accepts a configuration object for the
pg
connection (see doc) - schemas: accepts
string
orstring[]
containing the schemas you want to connect to - contextOptions: see Postgraphile doc
- middleware: when
true
it enables the default mode of Postgraphile, this is the default configuration and the one supported by Postgraphile - postgraphileOptions: see Postgraphile doc (working only in
middleware
mode)
The code is a port for Fastify of postgraphile
.
Licensed under MIT.
postgraphile
license