graphile-build-pg
Version:
Build a GraphQL schema by reflection over a PostgreSQL schema. Easy to customize since it's built with plugins on graphile-build
27 lines (25 loc) • 679 B
Flow
// @flow
import type { Plugin } from "graphile-build";
export default (async function PgNodeAliasPostGraphile(builder) {
builder.hook(
"GraphQLObjectType",
(object, build, context) => {
const {
setNodeAlias,
inflection: { pluralize },
} = build;
if (!setNodeAlias) {
// Node plugin must be disabled.
return object;
}
const {
scope: { isPgRowType, isPgCompoundType, pgIntrospection: table },
} = context;
if (isPgRowType || isPgCompoundType) {
setNodeAlias(object.name, pluralize(table.name));
}
return object;
},
["PgNodeAliasPostGraphile"]
);
}: Plugin);