Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions graphile/graphile-settings/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export {
} from './pg-type-mappings';
export type { TypeMapping } from './pg-type-mappings';

// Uppercase enum values to match v4 CONSTANT_CASE convention
export {
UppercaseEnumsPlugin,
UppercaseEnumsPreset,
} from './uppercase-enums';

// Search plugin for tsvector full-text search conditions (includes TsvectorCodec)
export {
PgSearchPlugin,
Expand Down
33 changes: 33 additions & 0 deletions graphile/graphile-settings/src/plugins/uppercase-enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { GraphileConfig } from 'graphile-config';

/**
* Plugin that uppercases PostgreSQL enum values in the GraphQL schema.
*
* WHY THIS EXISTS:
* In PostGraphile v4, custom PostgreSQL enum values (e.g., 'app', 'core', 'module')
* were automatically uppercased to CONSTANT_CASE ('APP', 'CORE', 'MODULE').
* In PostGraphile v5, the default `enumValue` inflector preserves the original
* PostgreSQL casing via `coerceToGraphQLName(value)`, resulting in lowercase
* enum values in the GraphQL schema.
*
* This plugin overrides the `enumValue` inflector to uppercase the result,
* restoring v4 behavior. It delegates to the previous inflector first to
* retain all special character handling (asterisks, symbols, etc.).
*/
export const UppercaseEnumsPlugin: GraphileConfig.Plugin = {
name: 'UppercaseEnumsPlugin',
version: '1.0.0',

inflection: {
replace: {
enumValue(previous, _options, value, codec) {
const result = previous!(value, codec);
return result.toUpperCase();
},
},
},
};

export const UppercaseEnumsPreset: GraphileConfig.Preset = {
plugins: [UppercaseEnumsPlugin],
};
2 changes: 2 additions & 0 deletions graphile/graphile-settings/src/presets/constructive-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ManyToManyOptInPreset } from '../plugins/many-to-many-preset';
import { MetaSchemaPreset } from '../plugins/meta-schema';
import { PgSearchPreset } from 'graphile-search-plugin';
import { PgTypeMappingsPreset } from '../plugins/pg-type-mappings';
import { UppercaseEnumsPreset } from '../plugins/uppercase-enums';

/**
* Constructive PostGraphile v5 Preset
Expand Down Expand Up @@ -61,6 +62,7 @@ export const ConstructivePreset: GraphileConfig.Preset = {
MetaSchemaPreset,
PgSearchPreset({ pgSearchPrefix: 'fullText' }),
PgTypeMappingsPreset,
UppercaseEnumsPreset,
],
/**
* Disable relation filter plugins from postgraphile-plugin-connection-filter.
Expand Down