| name | graphile-v5-presets |
| description | Create and compose PostGraphile v5 presets. Use when asked to "create a preset", "configure PostGraphile", "combine presets", "disable plugins", or when setting up a new PostGraphile v5 server. |
| compatibility | PostGraphile v5+, graphile-config |
| metadata | {"author":"constructive-io","version":"1.0.0"} |
PostGraphile v5 Presets
Create and compose PostGraphile v5 presets for configuring your GraphQL API.
Official Documentation
When to Apply
Use this skill when:
- Setting up a new PostGraphile v5 server
- Creating a custom preset that combines multiple features
- Disabling unwanted default plugins
- Configuring schema options
Quick Start
Basic Preset Structure
import type { GraphileConfig } from 'graphile-config';
export const MyPreset: GraphileConfig.Preset = {
extends: [
OtherPreset,
],
plugins: [
MyPlugin,
],
disablePlugins: [
'PluginToDisable',
],
schema: {
},
grafserv: {
port: 5433,
graphqlPath: '/graphql',
graphiqlPath: '/graphiql',
},
};
Preset Composition
Extending Multiple Presets
Presets are merged in order - later presets override earlier ones:
import { PostGraphileAmberPreset } from 'postgraphile/presets/amber';
import { PostGraphileConnectionFilterPreset } from 'postgraphile-plugin-connection-filter';
export const MyPreset: GraphileConfig.Preset = {
extends: [
PostGraphileAmberPreset,
PostGraphileConnectionFilterPreset,
MinimalPreset,
InflektPreset,
],
};
Creating a Composable Preset
Make your preset easy to combine with others:
export const NoRelayPreset: GraphileConfig.Preset = {
disablePlugins: [
'NodePlugin',
'PgTableNodePlugin',
],
};
export const FilterPreset: GraphileConfig.Preset = {
extends: [PostGraphileConnectionFilterPreset],
schema: {
connectionFilterRelations: false,
},
};
export const MyAppPreset: GraphileConfig.Preset = {
extends: [
PostGraphileAmberPreset,
NoRelayPreset,
FilterPreset,
],
};
Disabling Plugins
By Plugin Name
Use disablePlugins array with plugin names as strings:
export const MinimalPreset: GraphileConfig.Preset = {
disablePlugins: [
'NodePlugin',
'AddNodeInterfaceToSuitableTypesPlugin',
'NodeIdCodecBase64JSONPlugin',
'NodeIdCodecPipeStringPlugin',
'RegisterQueryNodePlugin',
'NodeAccessorPlugin',
'PgNodeIdAttributesPlugin',
'PgTableNodePlugin',
'PgConnectionArgFilterBackwardRelationsPlugin',
'PgConnectionArgFilterForwardRelationsPlugin',
],
};
Finding Plugin Names
Plugin names are the name property of the plugin object. Check the source code or use the InflectorLoggerPlugin to see what's being generated.
Schema Configuration
Common Schema Options
export const MyPreset: GraphileConfig.Preset = {
schema: {
connectionFilterRelations: false,
connectionFilterComputedColumns: false,
connectionFilterSetofFunctions: false,
connectionFilterLogicalOperators: true,
connectionFilterArrays: true,
pgJwtSecret: process.env.JWT_SECRET,
pgDefaultRole: 'app_anonymous',
},
};
Server Configuration
Grafserv Options
export const MyPreset: GraphileConfig.Preset = {
grafserv: {
port: 5433,
graphqlPath: '/graphql',
graphiqlPath: '/graphiql',
websockets: true,
watch: process.env.NODE_ENV === 'development',
},
};
Using Presets
With makePgService
import { postgraphile } from 'postgraphile';
import { makePgService } from 'postgraphile/adaptors/pg';
import { MyPreset } from './preset';
const preset: GraphileConfig.Preset = {
extends: [MyPreset],
pgServices: [
makePgService({
connectionString: process.env.DATABASE_URL,
schemas: ['public', 'app'],
}),
],
};
const pgl = postgraphile(preset);
With Express
import express from 'express';
import { createServer } from 'http';
import { postgraphile } from 'postgraphile';
import { grafserv } from 'postgraphile/grafserv/express/v4';
const app = express();
const server = createServer(app);
const pgl = postgraphile(preset);
const serv = pgl.createServ(grafserv);
await serv.addTo(app, server);
server.listen(5433, () => {
console.log('Server running on http://localhost:5433');
});
Complete Example
import type { GraphileConfig } from 'graphile-config';
import { PostGraphileAmberPreset } from 'postgraphile/presets/amber';
import { PostGraphileConnectionFilterPreset } from 'postgraphile-plugin-connection-filter';
import { makePgService } from 'postgraphile/adaptors/pg';
import { MinimalPreset } from './plugins/minimal-preset';
import { InflektPreset } from './plugins/custom-inflector';
import { PrimaryKeyOnlyPreset } from './plugins/primary-key-only';
export const ConstructivePreset: GraphileConfig.Preset = {
extends: [
MinimalPreset,
InflektPreset,
PrimaryKeyOnlyPreset,
PostGraphileConnectionFilterPreset,
],
disablePlugins: [
'PgConnectionArgFilterBackwardRelationsPlugin',
'PgConnectionArgFilterForwardRelationsPlugin',
],
schema: {
connectionFilterRelations: false,
connectionFilterComputedColumns: false,
},
};
const preset: GraphileConfig.Preset = {
extends: [ConstructivePreset],
pgServices: [
makePgService({
connectionString: process.env.DATABASE_URL,
schemas: ['public'],
}),
],
grafserv: {
port: 5433,
graphqlPath: '/graphql',
graphiqlPath: '/graphiql',
},
};
Troubleshooting
| Issue | Solution |
|---|
| Plugin not disabled | Check exact plugin name (case-sensitive) |
| Preset not applied | Verify extends order (later overrides earlier) |
| Schema option ignored | Some options require specific plugins to be enabled |
| Type errors | Ensure graphile-config types are installed |
References
- PostGraphile v5 Configuration Docs: https://postgraphile.org/postgraphile/next/config
- See
graphile-v5-minimal skill for disabling Node/Relay
- See
graphile-v5-behaviors skill for controlling what gets generated
- See
graphile-v5-plugins skill for creating custom plugins
- See
graphile-v5-debugging skill for graphile config print CLI command