postgraphile-remove-foreign-key-fields-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

postgraphile-remove-foreign-key-fields-plugin

CircleCI npm version

Motivation

This PostGraphile plugin removes all foreign key fields from the GraphQL schema while still allowing foreign relationships to be created. Primary key fields (which may also be used as a foreign key) are not removed from the GraphQL schema.

Example

type Person {
  id
  firstName
  lastName
  addressId
  address {
    id
    street
    city
    state
    postalCode
  }
}

This extension will remove addressId from the Person type in an effort to simplify the schema.

type Person {
  id
  firstName
  lastName
  address {
    id
    street
    city
    state
    postalCode
  }
}

You can still get the address id through the Address type.

Person->address->id.

Getting Started

Install npm package.

npm install postgraphile-remove-foreign-key-fields-plugin

Add plugin to postgraphile.

import express from "express";
import { postgraphile } from "postgraphile";
import { RemoveForeignKeyFieldsPlugin } from "postgraphile-remove-foreign-key-fields-plugin";

const app = express();

// Add PostGraphile middleware.
app.use(
  postgraphile(`postgres://username:password@localhost:5432/postgres`, {
    appendPlugins: [RemoveForeignKeyFieldsPlugin],
  }),
);

// Start up server.
app.listen(3000, "localhost", 511, () => {
  logger.info(`🚀 Server listening at http://localhost:3000`);
});

Package Sidebar

Install

npm i postgraphile-remove-foreign-key-fields-plugin

Weekly Downloads

125

Version

1.2.0

License

MIT

Unpacked Size

13.2 kB

Total Files

8

Last publish

Collaborators

  • jarvisuser90