GraphQL Schema Plugins
PostGraphile’s schema generator is built from a number of
graphile-build plugins. You can
write your own plugins — either using the helpers available in graphile-utils
,
or using the raw plugin interface available from Graphile Build.
If you’re looking for an easy way to remove/rename things, check out smart tags.
Inflection example
Here’s an example of a simple plugin which uses the “inflection”
system to rename all database columns named full_name
to be
output as name
in GraphQL:
/** @type {GraphileConfig.Plugin} */
const FullNameToNamePlugin = {
name: "FullNameToNamePlugin",
inflection: {
replace: {
attribute(previous, options, details) {
if (details.attributeName === "full_name") {
return "name";
} else {
return previous?.(details) ?? details.attributeName;
}
},
},
},
};
Writing Plugins
We’ve created a number of plugin helpers for common tasks:
- To add new fields and types,
see
extendSchema
- To change how fields and types are automatically named, see “Overriding inflection”
- To change how fields are planned,
see
wrapPlans
- To make certain fields nullable or non-nullable,
see
changeNullability
- To process the generated schema,
see
processSchema
For everything else, you can write raw Graphile Build plugins.
Do look over our plugin gallery for examples of plugins. These are generally suitable for copying/pasting into your app and then customizing to your needs.
Loading Plugins
Once you’ve written (or installed) a plugin, you can load it via your preset:
import MyPlugin from "./myPlugin.mjs";
export default {
// ...
plugins: [MyPlugin],
};
Remember: multiple versions of graphql
in your node_modules
will cause
problems; so we strongly recommend using the graphql
object that's
available on the Build
object (second argument to hooks) rather than requiring
your own version.
Schema plugins
📄️ Adding and replacing inflectors
Inflection relates to naming things; please see the [inflection
📄️ changeNullability
Use this plugin generator to easily change the nullability of fields and arguments in
📄️ extendSchema
extendSchema is the plugin generator you need to know about. It’s
📄️ processSchema
This plugin enables a way of processing the schema after it’s built.
📄️ wrapPlans
PostGraphile generates plan resolvers automatically for the fields that it
📄️ addPgTableCondition
PostGraphile adds condition arguments to various of the table collection
📄️ addPgTableOrderBy
PostGraphile adds orderBy arguments to various of the table collection fields
📄️ pgSmartTags
Smart Tags enable you to customize how (or if) your PostgreSQL resources are
📄️ Graphile Build
The PostGraphile GraphQL schema is constructed out of a number of Graphile
📄️ Plugin Gallery
Sorry, this has not been ported from the V4 documentation yet.
📄️ Community Plugins
Community members can write plugins for PostGraphile that extends its