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
51 lines (50 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var PgMutationProceduresPlugin = function PgMutationProceduresPlugin(builder) {
builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
const {
extend,
pgIntrospectionResultsByKind: introspectionResultsByKind,
inflection,
pgMakeProcField: makeProcField,
pgOmit: omit,
swallowError,
describePgEntity,
sqlCommentByAddingTags
} = build;
const {
scope: {
isRootMutation
},
fieldWithHooks
} = context;
if (!isRootMutation) {
return fields;
}
return extend(fields, introspectionResultsByKind.procedure.reduce((memo, proc) => {
// PERFORMANCE: These used to be .filter(...) calls
if (proc.isStable) return memo;
if (!proc.namespace) return memo;
if (omit(proc, "execute")) return memo;
const fieldName = inflection.functionMutationName(proc);
try {
memo = extend(memo, {
[fieldName]: makeProcField(fieldName, proc, build, {
fieldWithHooks,
isMutation: true
})
}, `Adding mutation field for ${describePgEntity(proc)}. You can rename this field with a 'Smart Comment':\n\n ${sqlCommentByAddingTags(proc, {
name: "newNameHere"
})}`);
} catch (e) {
swallowError(e);
}
return memo;
}, {}), `Adding mutation procedure to root Mutation field`);
}, ["PgMutationProcedures"]);
};
exports.default = PgMutationProceduresPlugin;
//# sourceMappingURL=PgMutationProceduresPlugin.js.map