Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

brooklyn-labs/postgraphile-plugin-remove-foreign-key-fields

Repository files navigation

postgraphile-plugin-remove-foreign-key-fields

GitHub Workflow Status (with branch) npm (scoped) License

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-plugin-remove-foreign-key-fields

Add plugin to postgraphile.

import express from "express";
import { postgraphile } from "postgraphile";
import { RemoveForeignKeyFieldsPlugin } from "postgraphile-plugin-remove-foreign-key-fields";
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`);
});

About

This PostGraphile plugin removes all foreign key fields from the GraphQL schema while still allowing foreign relationships to be created.

Topics

Resources

License

Stars

Watchers

Forks

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /