JSPM

  • Created
  • Published
  • Downloads 43109
  • Score
    100M100P100Q165695F
  • License MIT

Advanced filtering of Connections in PostGraphile

Package Exports

  • postgraphile-plugin-connection-filter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postgraphile-plugin-connection-filter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

postgraphile-plugin-connection-filter

This plugin adds a filter: argument to Connection types in PostGraphile v4.

Disclaimer

These plugins target the alpha releases of PostGraphile v4. Bug reports and pull requests are very much welcome.

Compatibility

PostGraphile 4.0.0-alpha2.20 and earlier requires a 1.0.0-alpha.0 version of this plugin.

PostGraphile 4.0.0-alpha2.21 through 4.0.0-alpha2.25 requires a 1.0.0-alpha.1 version of this plugin.

PostGraphile 4.0.0-alpha2.26 and later requires a 1.0.0-alpha.2 version of this plugin.

Usage

CLI

postgraphile --append-plugins `pwd`/path/to/this/plugin/index.js

Library

const express = require("express");
const { postgraphile } = require("postgraphile");
const PostGraphileConnectionFilterPlugin = require("./path/to/this/plugin/index.js");

const app = express();

app.use(
  postgraphile(pgConfig, schema, {
    graphiql: true,
    appendPlugins: [PostGraphileConnectionFilterPlugin],
  })
);

app.listen(3000);

The following options can be passed via graphileBuildOptions (called graphqlBuildOptions in PostGraphile 4.0.0-alpha2.20 and earlier):

connectionFilterUsesShortNames

Use short names (e.g. eq, ne, lt, lte) for operators

postgraphile(pgConfig, schema, {
  ...
  graphileBuildOptions: {
    connectionFilterUsesShortNames: true,
  },
})

connectionFilterAllowedFieldTypes

Restrict filters to specific field types

postgraphile(pgConfig, schema, {
  ...
  graphileBuildOptions: {
    connectionFilterAllowedFieldTypes: ["String", "Int"],
  },
})

To add/remove/modify individual operators, you can edit src/PgConnectionArgFilterOperatorsPlugin.js.

Development

To establish a test environment, create an empty Postgres database (e.g. graphile_build_test) and set a TEST_DATABASE_URL environment variable with your connection string (e.g. postgres://localhost:5432/graphile_build_test). Ensure that psql is installed locally and then run:

npm install
npm test