trailpack-postgraphql

0.1.0 • Public • Published

trailpack-postgraphql

Gitter NPM version NPM downloads Follow @trailsjs on Twitter

📦 Trailpack to integrate Postgraphql into a Trails application

WARNING :

This Trailpack work only with trailpack-express as webserver

Intallation

With yo :

npm install -g yo generator-trails
yo trails:trailpack trailpack-postgraphql

With npm (you will have to create config file manually) :

npm install --save trailpack-postgraphql

Configuration

First you need to add this trailpack to your main configuration :

// config/main.js
 
module.exports = {
   ...
 
   packs: [
      ...
      require('trailpack-postgraphql'),
      ...
   ]
   ...
}

You need to add postgraphql to your web middlewares:

// config/web.js
middlewares: {
        order: [
          'addMethods',
          'cookieParser',
          'session',
          'postgraphql',
          'bodyParser',
          'methodOverride',
          'router',
          'www',
          '404',
          '500'
        ]
      }

And to configure postgraphql:

// config/postgraphql.js
'use strict'
 
/**
 * Postgraphql Configuration
 *
 * @see {@link http://github.com/mikehostetler/trailpack-postgraphql
 */
module.exports = {
  /**
   * Postgres connection string
   *
   * Passed directly to the `pg` module
   * Docs: https://github.com/brianc/node-postgres
   */
  pgConfig: 'postgres://localhost:5432',
 
  /**
   * Default Schema Name
   */
  schemaName: 'public',
 
  /**
   * Postraphql Options
   * See:
   * https://github.com/postgraphql/postgraphql/blob/master/docs/library.md
   */
  opts: {
 
    /*
    classicIds: joi.string(),
    dynamicJson: false,
    disableDefaultMutations: false,
 
    graphqlRoute: '/graphql',
    graphiql: false,
    graphiqlRoute: '/graphiql',
    pgDefaultRole: '',
 
    jwtSecret: '',
    jwtAudiences: '',
    jwtPgTypeIdentifier: '',
 
    watchPg: false,
    disableQueryLog: true,
    enableCors: false,
 
    exportJsonSchemaPath: '',
    exportGqlSchemaPath: '',
    bodySizeLimit: '100kB'
    */
  }
}

Then make sure to include the new file in config/index.js

//config/index.js
...
exports.postgraphql = require('./postgraphql')

Usage

GraphQL endpoint now available

You should now have a GraphQL endpoint available at http://localhost:3000/graphql

GraphiQL

You can verify that you installed this Trailpack correctly by enabling the bundled graphiql interface which is available at http://localhost:3000/graphiql by default.

Graphiql must be enabled in the configuration to be turned on

License

MIT

Package Sidebar

Install

npm i trailpack-postgraphql

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mikehostetler