graphile-settings 4.9.2 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/esm/plugins/PublicKeySignature.d.ts +11 -0
  2. package/esm/plugins/PublicKeySignature.js +184 -0
  3. package/esm/plugins/conflict-detector.d.ts +7 -0
  4. package/esm/plugins/conflict-detector.js +67 -0
  5. package/esm/plugins/custom-inflector.d.ts +9 -0
  6. package/esm/plugins/custom-inflector.js +394 -0
  7. package/esm/plugins/enable-all-filter-columns.d.ts +60 -0
  8. package/esm/plugins/enable-all-filter-columns.js +85 -0
  9. package/esm/plugins/index.d.ts +16 -4
  10. package/esm/plugins/index.js +25 -4
  11. package/esm/plugins/inflector-logger.d.ts +7 -0
  12. package/esm/plugins/inflector-logger.js +215 -0
  13. package/esm/plugins/many-to-many-preset.d.ts +62 -0
  14. package/esm/plugins/many-to-many-preset.js +86 -0
  15. package/esm/plugins/meta-schema/cache.d.ts +4 -0
  16. package/esm/plugins/meta-schema/cache.js +7 -0
  17. package/esm/plugins/meta-schema/constraint-meta-builders.d.ts +13 -0
  18. package/esm/plugins/meta-schema/constraint-meta-builders.js +51 -0
  19. package/esm/plugins/meta-schema/graphql-meta-field.d.ts +4 -0
  20. package/esm/plugins/meta-schema/graphql-meta-field.js +201 -0
  21. package/esm/plugins/meta-schema/inflection-utils.d.ts +4 -0
  22. package/esm/plugins/meta-schema/inflection-utils.js +20 -0
  23. package/esm/plugins/meta-schema/name-meta-builders.d.ts +4 -0
  24. package/esm/plugins/meta-schema/name-meta-builders.js +38 -0
  25. package/esm/plugins/meta-schema/plugin.d.ts +2 -0
  26. package/esm/plugins/meta-schema/plugin.js +23 -0
  27. package/esm/plugins/meta-schema/relation-meta-builders.d.ts +8 -0
  28. package/esm/plugins/meta-schema/relation-meta-builders.js +115 -0
  29. package/esm/plugins/meta-schema/table-meta-builder.d.ts +2 -0
  30. package/esm/plugins/meta-schema/table-meta-builder.js +69 -0
  31. package/esm/plugins/meta-schema/table-meta-context.d.ts +13 -0
  32. package/esm/plugins/meta-schema/table-meta-context.js +11 -0
  33. package/esm/plugins/meta-schema/table-resource-utils.d.ts +12 -0
  34. package/esm/plugins/meta-schema/table-resource-utils.js +50 -0
  35. package/esm/plugins/meta-schema/type-mappings.d.ts +3 -0
  36. package/esm/plugins/meta-schema/type-mappings.js +75 -0
  37. package/esm/plugins/meta-schema/types.d.ts +206 -0
  38. package/esm/plugins/meta-schema/types.js +1 -0
  39. package/esm/plugins/meta-schema.d.ts +19 -0
  40. package/esm/plugins/meta-schema.js +20 -0
  41. package/esm/plugins/minimal-preset.d.ts +7 -0
  42. package/esm/plugins/minimal-preset.js +42 -0
  43. package/esm/plugins/pg-type-mappings.d.ts +41 -0
  44. package/esm/plugins/pg-type-mappings.js +122 -0
  45. package/esm/plugins/primary-key-only.d.ts +96 -0
  46. package/esm/plugins/primary-key-only.js +143 -0
  47. package/esm/plugins/required-input-plugin.d.ts +37 -0
  48. package/esm/plugins/required-input-plugin.js +88 -0
  49. package/esm/presets/constructive-preset.js +2 -1
  50. package/package.json +11 -9
  51. package/plugins/PublicKeySignature.d.ts +11 -0
  52. package/plugins/PublicKeySignature.js +191 -0
  53. package/plugins/conflict-detector.d.ts +7 -0
  54. package/plugins/conflict-detector.js +70 -0
  55. package/plugins/custom-inflector.d.ts +9 -0
  56. package/plugins/custom-inflector.js +397 -0
  57. package/plugins/enable-all-filter-columns.d.ts +60 -0
  58. package/plugins/enable-all-filter-columns.js +88 -0
  59. package/plugins/index.d.ts +16 -4
  60. package/plugins/index.js +54 -31
  61. package/plugins/inflector-logger.d.ts +7 -0
  62. package/plugins/inflector-logger.js +218 -0
  63. package/plugins/many-to-many-preset.d.ts +62 -0
  64. package/plugins/many-to-many-preset.js +89 -0
  65. package/plugins/meta-schema/cache.d.ts +4 -0
  66. package/plugins/meta-schema/cache.js +12 -0
  67. package/plugins/meta-schema/constraint-meta-builders.d.ts +13 -0
  68. package/plugins/meta-schema/constraint-meta-builders.js +58 -0
  69. package/plugins/meta-schema/graphql-meta-field.d.ts +4 -0
  70. package/plugins/meta-schema/graphql-meta-field.js +204 -0
  71. package/plugins/meta-schema/inflection-utils.d.ts +4 -0
  72. package/plugins/meta-schema/inflection-utils.js +25 -0
  73. package/plugins/meta-schema/name-meta-builders.d.ts +4 -0
  74. package/plugins/meta-schema/name-meta-builders.js +43 -0
  75. package/plugins/meta-schema/plugin.d.ts +2 -0
  76. package/plugins/meta-schema/plugin.js +26 -0
  77. package/plugins/meta-schema/relation-meta-builders.d.ts +8 -0
  78. package/plugins/meta-schema/relation-meta-builders.js +120 -0
  79. package/plugins/meta-schema/table-meta-builder.d.ts +2 -0
  80. package/plugins/meta-schema/table-meta-builder.js +72 -0
  81. package/plugins/meta-schema/table-meta-context.d.ts +13 -0
  82. package/plugins/meta-schema/table-meta-context.js +15 -0
  83. package/plugins/meta-schema/table-resource-utils.d.ts +12 -0
  84. package/plugins/meta-schema/table-resource-utils.js +60 -0
  85. package/plugins/meta-schema/type-mappings.d.ts +3 -0
  86. package/plugins/meta-schema/type-mappings.js +79 -0
  87. package/plugins/meta-schema/types.d.ts +206 -0
  88. package/plugins/meta-schema/types.js +2 -0
  89. package/plugins/meta-schema.d.ts +19 -0
  90. package/plugins/meta-schema.js +20 -0
  91. package/plugins/minimal-preset.d.ts +7 -0
  92. package/plugins/minimal-preset.js +45 -0
  93. package/plugins/pg-type-mappings.d.ts +41 -0
  94. package/plugins/pg-type-mappings.js +128 -0
  95. package/plugins/primary-key-only.d.ts +96 -0
  96. package/plugins/primary-key-only.js +147 -0
  97. package/plugins/required-input-plugin.d.ts +37 -0
  98. package/plugins/required-input-plugin.js +91 -0
  99. package/presets/constructive-preset.js +11 -10
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pgTypeToGqlType = pgTypeToGqlType;
4
+ exports.buildFieldMeta = buildFieldMeta;
5
+ const PG_TO_GQL_TYPE = {
6
+ text: 'String',
7
+ varchar: 'String',
8
+ char: 'String',
9
+ name: 'String',
10
+ bpchar: 'String',
11
+ uuid: 'UUID',
12
+ int2: 'Int',
13
+ int4: 'Int',
14
+ integer: 'Int',
15
+ int8: 'BigInt',
16
+ bigint: 'BigInt',
17
+ float4: 'Float',
18
+ float8: 'Float',
19
+ numeric: 'BigFloat',
20
+ bool: 'Boolean',
21
+ boolean: 'Boolean',
22
+ timestamptz: 'Datetime',
23
+ timestamp: 'Datetime',
24
+ date: 'Date',
25
+ time: 'Time',
26
+ timetz: 'Time',
27
+ json: 'JSON',
28
+ jsonb: 'JSON',
29
+ interval: 'Interval',
30
+ point: 'Point',
31
+ geometry: 'GeoJSON',
32
+ geography: 'GeoJSON',
33
+ inet: 'InternetAddress',
34
+ cidr: 'InternetAddress',
35
+ xml: 'String',
36
+ bytea: 'String',
37
+ macaddr: 'String',
38
+ };
39
+ function pgTypeToGqlType(pgTypeName) {
40
+ return PG_TO_GQL_TYPE[pgTypeName] || pgTypeName;
41
+ }
42
+ function resolveGqlTypeName(build, codec) {
43
+ if (!codec)
44
+ return 'unknown';
45
+ try {
46
+ const codecForLookup = codec.arrayOfCodec || codec;
47
+ if (build?.hasGraphQLTypeForPgCodec?.(codecForLookup, 'output')) {
48
+ const resolved = build.getGraphQLTypeNameByPgCodec?.(codecForLookup, 'output');
49
+ if (resolved)
50
+ return resolved;
51
+ }
52
+ }
53
+ catch {
54
+ // Fall through to static fallback mapping.
55
+ }
56
+ const pgTypeName = codec.name || 'unknown';
57
+ const mapped = pgTypeToGqlType(pgTypeName);
58
+ if (mapped !== pgTypeName)
59
+ return mapped;
60
+ const nestedTypeName = codec.arrayOfCodec?.name;
61
+ return nestedTypeName ? pgTypeToGqlType(nestedTypeName) : pgTypeName;
62
+ }
63
+ function buildFieldMeta(name, attr, build) {
64
+ const pgType = attr?.codec?.name || 'unknown';
65
+ const isNotNull = attr?.notNull || false;
66
+ const hasDefault = attr?.hasDefault || false;
67
+ return {
68
+ name,
69
+ type: {
70
+ pgType,
71
+ gqlType: build ? resolveGqlTypeName(build, attr?.codec) : pgTypeToGqlType(pgType),
72
+ isArray: !!attr?.codec?.arrayOfCodec,
73
+ isNotNull,
74
+ hasDefault,
75
+ },
76
+ isNotNull,
77
+ hasDefault,
78
+ };
79
+ }
@@ -0,0 +1,206 @@
1
+ export interface TableMeta {
2
+ name: string;
3
+ schemaName: string;
4
+ fields: FieldMeta[];
5
+ indexes: IndexMeta[];
6
+ constraints: ConstraintsMeta;
7
+ foreignKeyConstraints: ForeignKeyConstraintMeta[];
8
+ primaryKeyConstraints: PrimaryKeyConstraintMeta[];
9
+ uniqueConstraints: UniqueConstraintMeta[];
10
+ relations: RelationsMeta;
11
+ inflection: InflectionMeta;
12
+ query: QueryMeta;
13
+ }
14
+ export interface FieldMeta {
15
+ name: string;
16
+ type: TypeMeta;
17
+ isNotNull: boolean;
18
+ hasDefault: boolean;
19
+ }
20
+ export interface TypeMeta {
21
+ pgType: string;
22
+ gqlType: string;
23
+ isArray: boolean;
24
+ isNotNull?: boolean;
25
+ hasDefault?: boolean;
26
+ }
27
+ export interface IndexMeta {
28
+ name: string;
29
+ isUnique: boolean;
30
+ isPrimary: boolean;
31
+ columns: string[];
32
+ fields: FieldMeta[];
33
+ }
34
+ export interface ConstraintsMeta {
35
+ primaryKey: PrimaryKeyConstraintMeta | null;
36
+ unique: UniqueConstraintMeta[];
37
+ foreignKey: ForeignKeyConstraintMeta[];
38
+ }
39
+ export interface PrimaryKeyConstraintMeta {
40
+ name: string;
41
+ fields: FieldMeta[];
42
+ }
43
+ export interface UniqueConstraintMeta {
44
+ name: string;
45
+ fields: FieldMeta[];
46
+ }
47
+ export interface ForeignKeyConstraintMeta {
48
+ name: string;
49
+ fields: FieldMeta[];
50
+ referencedTable: string;
51
+ referencedFields: string[];
52
+ refFields: FieldMeta[];
53
+ refTable: {
54
+ name: string;
55
+ };
56
+ }
57
+ export interface RelationsMeta {
58
+ belongsTo: BelongsToRelation[];
59
+ has: HasRelation[];
60
+ hasOne: HasRelation[];
61
+ hasMany: HasRelation[];
62
+ manyToMany: ManyToManyRelation[];
63
+ }
64
+ export interface BelongsToRelation {
65
+ fieldName: string | null;
66
+ isUnique: boolean;
67
+ type: string | null;
68
+ keys: FieldMeta[];
69
+ references: {
70
+ name: string;
71
+ };
72
+ }
73
+ export interface HasRelation {
74
+ fieldName: string | null;
75
+ isUnique: boolean;
76
+ type: string | null;
77
+ keys: FieldMeta[];
78
+ referencedBy: {
79
+ name: string;
80
+ };
81
+ }
82
+ export interface ManyToManyRelation {
83
+ fieldName: string | null;
84
+ type: string | null;
85
+ junctionTable: {
86
+ name: string;
87
+ };
88
+ junctionLeftConstraint: ForeignKeyConstraintMeta;
89
+ junctionLeftKeyAttributes: FieldMeta[];
90
+ junctionRightConstraint: ForeignKeyConstraintMeta;
91
+ junctionRightKeyAttributes: FieldMeta[];
92
+ leftKeyAttributes: FieldMeta[];
93
+ rightKeyAttributes: FieldMeta[];
94
+ rightTable: {
95
+ name: string;
96
+ };
97
+ }
98
+ export interface InflectionMeta {
99
+ tableType: string;
100
+ allRows: string;
101
+ connection: string;
102
+ edge: string;
103
+ filterType: string | null;
104
+ orderByType: string;
105
+ conditionType: string;
106
+ patchType: string | null;
107
+ createInputType: string;
108
+ createPayloadType: string;
109
+ updatePayloadType: string | null;
110
+ deletePayloadType: string;
111
+ }
112
+ export interface QueryMeta {
113
+ all: string;
114
+ one: string | null;
115
+ create: string | null;
116
+ update: string | null;
117
+ delete: string | null;
118
+ }
119
+ export interface PgCodec {
120
+ name: string;
121
+ attributes?: Record<string, PgAttribute>;
122
+ arrayOfCodec?: PgCodec | null;
123
+ isAnonymous?: boolean;
124
+ extensions?: {
125
+ pg?: {
126
+ schemaName?: string;
127
+ };
128
+ };
129
+ }
130
+ export interface PgAttribute {
131
+ codec?: PgCodec | null;
132
+ notNull?: boolean;
133
+ hasDefault?: boolean;
134
+ }
135
+ export interface PgUnique {
136
+ attributes: string[];
137
+ isPrimary?: boolean;
138
+ tags?: {
139
+ name?: string;
140
+ };
141
+ }
142
+ export interface PgRelation {
143
+ isReferencee?: boolean;
144
+ localAttributes?: string[];
145
+ remoteAttributes?: string[];
146
+ remoteResource?: PgTableResource | null;
147
+ }
148
+ export interface PgTableResource {
149
+ codec?: PgCodec;
150
+ uniques?: PgUnique[];
151
+ relations?: Record<string, PgRelation>;
152
+ parameters?: unknown;
153
+ isVirtual?: boolean;
154
+ isUnique?: boolean;
155
+ getRelation?: (relationName: string) => PgRelation | undefined;
156
+ getRelations?: () => Record<string, PgRelation>;
157
+ }
158
+ export interface PgManyToManyRelationDetails {
159
+ leftTable: PgTableResource;
160
+ leftRelationName: string;
161
+ junctionTable: PgTableResource;
162
+ rightRelationName: string;
163
+ rightTable: PgTableResource;
164
+ allowsMultipleEdgesToNode?: boolean;
165
+ }
166
+ export interface MetaInflection {
167
+ tableType: (codec: PgCodec) => string;
168
+ _attributeName?: (input: {
169
+ attributeName: string;
170
+ codec: PgCodec;
171
+ }) => string;
172
+ camelCase?: (value: string) => string;
173
+ _manyToManyRelation?: (details: PgManyToManyRelationDetails) => string | null | undefined;
174
+ allRows?: (resource: PgTableResource) => string | null | undefined;
175
+ connectionType?: (tableType: string) => string | null | undefined;
176
+ edgeType?: (tableType: string) => string | null | undefined;
177
+ filterType?: (tableType: string) => string | null | undefined;
178
+ orderByType?: (tableType: string) => string | null | undefined;
179
+ conditionType?: (tableType: string) => string | null | undefined;
180
+ patchType?: (tableType: string) => string | null | undefined;
181
+ createInputType?: (resource: PgTableResource) => string | null | undefined;
182
+ createPayloadType?: (resource: PgTableResource) => string | null | undefined;
183
+ updatePayloadType?: (resource: PgTableResource) => string | null | undefined;
184
+ deletePayloadType?: (resource: PgTableResource) => string | null | undefined;
185
+ tableFieldName?: (resource: PgTableResource) => string | null | undefined;
186
+ createField?: (resource: PgTableResource) => string | null | undefined;
187
+ updateByKeys?: (resource: PgTableResource) => string | null | undefined;
188
+ deleteByKeys?: (resource: PgTableResource) => string | null | undefined;
189
+ }
190
+ export interface GqlTypeResolverBuild {
191
+ hasGraphQLTypeForPgCodec?: (codec: PgCodec, mode?: 'output' | 'input' | string) => boolean;
192
+ getGraphQLTypeNameByPgCodec?: (codec: PgCodec, mode?: 'output' | 'input' | string) => string | null | undefined;
193
+ }
194
+ export interface MetaBuild extends GqlTypeResolverBuild {
195
+ input: {
196
+ pgRegistry: {
197
+ pgResources: Record<string, PgTableResource>;
198
+ };
199
+ };
200
+ inflection: MetaInflection;
201
+ options?: {
202
+ pgSchemas?: string[];
203
+ [key: string]: unknown;
204
+ };
205
+ pgManyToManyRealtionshipsByResource?: Map<unknown, unknown>;
206
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * PostGraphile v5 Meta Schema Plugin
3
+ *
4
+ * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
5
+ * constraints, indexes, and relations for code generation tooling.
6
+ */
7
+ import type { GraphileConfig } from 'graphile-config';
8
+ import { cachedTablesMeta } from './meta-schema/cache';
9
+ import { MetaSchemaPlugin } from './meta-schema/plugin';
10
+ import { buildFieldMeta, pgTypeToGqlType } from './meta-schema/type-mappings';
11
+ export { MetaSchemaPlugin };
12
+ export declare const MetaSchemaPreset: GraphileConfig.Preset;
13
+ /** @internal Exported for testing only */
14
+ export { pgTypeToGqlType as _pgTypeToGqlType };
15
+ /** @internal Exported for testing only */
16
+ export { buildFieldMeta as _buildFieldMeta };
17
+ /** @internal Exported for testing only */
18
+ export { cachedTablesMeta as _cachedTablesMeta };
19
+ export default MetaSchemaPlugin;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * PostGraphile v5 Meta Schema Plugin
4
+ *
5
+ * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
6
+ * constraints, indexes, and relations for code generation tooling.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports._cachedTablesMeta = exports._buildFieldMeta = exports._pgTypeToGqlType = exports.MetaSchemaPreset = exports.MetaSchemaPlugin = void 0;
10
+ const cache_1 = require("./meta-schema/cache");
11
+ Object.defineProperty(exports, "_cachedTablesMeta", { enumerable: true, get: function () { return cache_1.cachedTablesMeta; } });
12
+ const plugin_1 = require("./meta-schema/plugin");
13
+ Object.defineProperty(exports, "MetaSchemaPlugin", { enumerable: true, get: function () { return plugin_1.MetaSchemaPlugin; } });
14
+ const type_mappings_1 = require("./meta-schema/type-mappings");
15
+ Object.defineProperty(exports, "_buildFieldMeta", { enumerable: true, get: function () { return type_mappings_1.buildFieldMeta; } });
16
+ Object.defineProperty(exports, "_pgTypeToGqlType", { enumerable: true, get: function () { return type_mappings_1.pgTypeToGqlType; } });
17
+ exports.MetaSchemaPreset = {
18
+ plugins: [plugin_1.MetaSchemaPlugin],
19
+ };
20
+ exports.default = plugin_1.MetaSchemaPlugin;
@@ -0,0 +1,7 @@
1
+ import type { GraphileConfig } from 'graphile-config';
2
+ /**
3
+ * Minimal preset with all the PostgreSQL functionality but without Node/Relay features.
4
+ * This keeps `id` columns as `id` (no renaming to `rowId`).
5
+ */
6
+ export declare const MinimalPreset: GraphileConfig.Preset;
7
+ export default MinimalPreset;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MinimalPreset = void 0;
4
+ const graphile_build_1 = require("graphile-build");
5
+ const graphile_build_pg_1 = require("graphile-build-pg");
6
+ /**
7
+ * Minimal PostGraphile v5 preset without Node/Relay features.
8
+ *
9
+ * This preset builds a clean GraphQL API from PostgreSQL without:
10
+ * - Global Node ID (Relay spec) - so `id` columns stay as `id`
11
+ * - Schema prefixing for naming conflicts
12
+ *
13
+ * We use the default presets from graphile-build and graphile-build-pg
14
+ * and disable all Node-related plugins.
15
+ */
16
+ /**
17
+ * List of Node/Relay-related plugins to disable.
18
+ * These implement the Relay Global Object Identification spec which:
19
+ * - Adds a global `id` field to types
20
+ * - Renames actual `id` columns to `rowId`
21
+ * - Adds Node interface and nodeId lookups
22
+ *
23
+ * Since we use UUIDs, we don't need any of this.
24
+ */
25
+ const NODE_PLUGINS_TO_DISABLE = [
26
+ // Core Node plugins from graphile-build
27
+ 'NodePlugin',
28
+ 'AddNodeInterfaceToSuitableTypesPlugin',
29
+ 'NodeIdCodecBase64JSONPlugin',
30
+ 'NodeIdCodecPipeStringPlugin',
31
+ 'RegisterQueryNodePlugin',
32
+ 'NodeAccessorPlugin',
33
+ // PG-specific Node plugins from graphile-build-pg
34
+ 'PgNodeIdAttributesPlugin',
35
+ 'PgTableNodePlugin',
36
+ ];
37
+ /**
38
+ * Minimal preset with all the PostgreSQL functionality but without Node/Relay features.
39
+ * This keeps `id` columns as `id` (no renaming to `rowId`).
40
+ */
41
+ exports.MinimalPreset = {
42
+ extends: [graphile_build_1.defaultPreset, graphile_build_pg_1.defaultPreset],
43
+ disablePlugins: NODE_PLUGINS_TO_DISABLE,
44
+ };
45
+ exports.default = exports.MinimalPreset;
@@ -0,0 +1,41 @@
1
+ import type { GraphileConfig } from 'graphile-config';
2
+ /**
3
+ * Type mapping configuration for custom PostgreSQL types.
4
+ */
5
+ export interface TypeMapping {
6
+ /** PostgreSQL type name */
7
+ name: string;
8
+ /** PostgreSQL schema/namespace name */
9
+ namespaceName: string;
10
+ /** GraphQL type to map to */
11
+ type: 'String';
12
+ }
13
+ /**
14
+ * Plugin that maps custom PostgreSQL types to GraphQL scalar types.
15
+ *
16
+ * This is useful for domain types or composite types that should be
17
+ * represented as simple scalars (String, JSON) in the GraphQL API.
18
+ *
19
+ * For example, if you have:
20
+ * CREATE DOMAIN email AS text;
21
+ * CREATE TYPE url AS (value text);
22
+ *
23
+ * This plugin will map them to GraphQL String type instead of creating
24
+ * complex object types.
25
+ *
26
+ * The plugin handles both:
27
+ * 1. Domain types (simple aliases) - maps directly to the target scalar
28
+ * 2. Composite types - extracts the first field's value when converting from PG
29
+ */
30
+ export declare const PgTypeMappingsPlugin: GraphileConfig.Plugin;
31
+ /**
32
+ * Preset that includes the PG type mappings plugin.
33
+ *
34
+ * This preset maps common custom PostgreSQL types to GraphQL scalars:
35
+ * - email -> String
36
+ * - hostname -> String
37
+ * - url -> String
38
+ * - origin -> String
39
+ */
40
+ export declare const PgTypeMappingsPreset: GraphileConfig.Preset;
41
+ export default PgTypeMappingsPlugin;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PgTypeMappingsPreset = exports.PgTypeMappingsPlugin = void 0;
7
+ const graphql_1 = require("graphql");
8
+ const pg_sql2_1 = __importDefault(require("pg-sql2"));
9
+ /**
10
+ * Default type mappings for common custom PostgreSQL types.
11
+ * These are typically domain types or composite types that should be
12
+ * represented as simple scalars in GraphQL.
13
+ */
14
+ const DEFAULT_MAPPINGS = [
15
+ { name: 'email', namespaceName: 'public', type: 'String' },
16
+ { name: 'hostname', namespaceName: 'public', type: 'String' },
17
+ { name: 'origin', namespaceName: 'public', type: 'String' },
18
+ { name: 'url', namespaceName: 'public', type: 'String' },
19
+ ];
20
+ /**
21
+ * Plugin that maps custom PostgreSQL types to GraphQL scalar types.
22
+ *
23
+ * This is useful for domain types or composite types that should be
24
+ * represented as simple scalars (String, JSON) in the GraphQL API.
25
+ *
26
+ * For example, if you have:
27
+ * CREATE DOMAIN email AS text;
28
+ * CREATE TYPE url AS (value text);
29
+ *
30
+ * This plugin will map them to GraphQL String type instead of creating
31
+ * complex object types.
32
+ *
33
+ * The plugin handles both:
34
+ * 1. Domain types (simple aliases) - maps directly to the target scalar
35
+ * 2. Composite types - extracts the first field's value when converting from PG
36
+ */
37
+ exports.PgTypeMappingsPlugin = {
38
+ name: 'PgTypeMappingsPlugin',
39
+ version: '1.0.0',
40
+ gather: {
41
+ hooks: {
42
+ async pgCodecs_findPgCodec(info, event) {
43
+ if (event.pgCodec) {
44
+ return;
45
+ }
46
+ const { pgType: type, serviceName } = event;
47
+ // Find the namespace for this type
48
+ const namespace = await info.helpers.pgIntrospection.getNamespace(serviceName, type.typnamespace);
49
+ if (!namespace) {
50
+ return;
51
+ }
52
+ // Check if this type matches any of our mappings
53
+ const mapping = DEFAULT_MAPPINGS.find(m => m.name === type.typname && m.namespaceName === namespace.nspname);
54
+ if (!mapping) {
55
+ return;
56
+ }
57
+ // Create a codec for this type
58
+ // For composite types, the fromPg function extracts the first field's value
59
+ // For domain types, it just passes through the value
60
+ event.pgCodec = {
61
+ name: type.typname,
62
+ sqlType: pg_sql2_1.default.identifier(namespace.nspname, type.typname),
63
+ fromPg: (value) => {
64
+ if (value == null) {
65
+ return null;
66
+ }
67
+ // If it's already a scalar, return it
68
+ if (typeof value !== 'object' || Array.isArray(value)) {
69
+ return value;
70
+ }
71
+ // For composite types, extract the first field's value
72
+ const obj = value;
73
+ const keys = Object.keys(obj);
74
+ if (keys.length > 0) {
75
+ return obj[keys[0]];
76
+ }
77
+ return value;
78
+ },
79
+ toPg: (value) => value,
80
+ attributes: undefined,
81
+ executor: null,
82
+ extensions: {
83
+ oid: type._id,
84
+ pg: {
85
+ serviceName,
86
+ schemaName: namespace.nspname,
87
+ name: type.typname,
88
+ },
89
+ tags: {
90
+ // Mark this as a custom mapped type
91
+ pgTypeMappings: mapping.type,
92
+ },
93
+ },
94
+ };
95
+ },
96
+ },
97
+ },
98
+ schema: {
99
+ hooks: {
100
+ init(_, build) {
101
+ const { setGraphQLTypeForPgCodec } = build;
102
+ // Map our custom codecs to GraphQL types
103
+ for (const codec of Object.values(build.input.pgRegistry.pgCodecs)) {
104
+ const mappingType = codec.extensions?.tags?.pgTypeMappings;
105
+ if (mappingType) {
106
+ const gqlTypeName = graphql_1.GraphQLString.name;
107
+ setGraphQLTypeForPgCodec(codec, 'input', gqlTypeName);
108
+ setGraphQLTypeForPgCodec(codec, 'output', gqlTypeName);
109
+ }
110
+ }
111
+ return _;
112
+ },
113
+ },
114
+ },
115
+ };
116
+ /**
117
+ * Preset that includes the PG type mappings plugin.
118
+ *
119
+ * This preset maps common custom PostgreSQL types to GraphQL scalars:
120
+ * - email -> String
121
+ * - hostname -> String
122
+ * - url -> String
123
+ * - origin -> String
124
+ */
125
+ exports.PgTypeMappingsPreset = {
126
+ plugins: [exports.PgTypeMappingsPlugin],
127
+ };
128
+ exports.default = exports.PgTypeMappingsPlugin;
@@ -0,0 +1,96 @@
1
+ import type { GraphileConfig } from 'graphile-config';
2
+ /**
3
+ * Configuration options for unique lookup behavior.
4
+ */
5
+ export interface UniqueLookupOptions {
6
+ /**
7
+ * If true, disables ALL unique constraint lookups including primary keys.
8
+ * Users must use collection queries with filters instead.
9
+ * Default: false (primary key lookups are kept)
10
+ */
11
+ disableAllUniqueLookups?: boolean;
12
+ }
13
+ /**
14
+ * PrimaryKeyOnlyPlugin - Disables non-primary-key unique constraint lookups for
15
+ * BOTH queries AND mutations.
16
+ *
17
+ * WHY THIS EXISTS:
18
+ * PostGraphile v5 creates fields for EVERY unique constraint on a table:
19
+ *
20
+ * QUERIES (PgRowByUniquePlugin):
21
+ * - `user(id)`, `userByEmail(email)`, `userByUsername(username)`
22
+ *
23
+ * MUTATIONS (PgMutationUpdateDeletePlugin):
24
+ * - `updateUser`, `updateUserByEmail`, `updateUserByUsername`
25
+ * - `deleteUser`, `deleteUserByEmail`, `deleteUserByUsername`
26
+ *
27
+ * For code generation (React Query, etc.), this creates unnecessary complexity.
28
+ * The same operations can be done using the primary key lookup or filters.
29
+ * Standardizing on primary keys reduces the API surface and generated code.
30
+ *
31
+ * SOURCE CODE REFERENCES:
32
+ *
33
+ * 1. Query fields (PgRowByUniquePlugin):
34
+ * https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRowByUniquePlugin.ts#L42-L257
35
+ *
36
+ * The behavior check for queries:
37
+ * ```typescript
38
+ * const fieldBehaviorScope = "query:resource:single";
39
+ * if (!build.behavior.pgResourceUniqueMatches([resource, unique], fieldBehaviorScope)) {
40
+ * return memo; // Skip this field
41
+ * }
42
+ * ```
43
+ *
44
+ * 2. Mutation fields (PgMutationUpdateDeletePlugin):
45
+ * https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgMutationUpdateDeletePlugin.ts
46
+ *
47
+ * The behavior check for mutations:
48
+ * ```typescript
49
+ * const constraintMode = `constraint:${mode}`; // "constraint:resource:update" or "constraint:resource:delete"
50
+ * ...resource.uniques.filter((unique) => {
51
+ * return build.behavior.pgResourceUniqueMatches([resource, unique], constraintMode);
52
+ * })
53
+ * ```
54
+ *
55
+ * OUR FIX:
56
+ * We use the behavior system's OVERRIDE phase (not inferred) to disable these behaviors.
57
+ * The override phase runs AFTER the behavior multiplication/preferences system processes
58
+ * behaviors, giving us the final say on what's enabled/disabled.
59
+ *
60
+ * Behaviors we control:
61
+ * - `-single` - Disables query lookups (userByEmail, etc.)
62
+ * - `-constraint:resource:update` - Disables updateByX mutations
63
+ * - `-constraint:resource:delete` - Disables deleteByX mutations
64
+ *
65
+ * CONFIGURATION OPTIONS:
66
+ *
67
+ * 1. `disableAllUniqueLookups: false` (default - PrimaryKeyOnlyPreset):
68
+ * - Primary key: query lookup + mutations enabled
69
+ * - Non-primary-key: everything disabled
70
+ * Result: `user(id)`, `updateUser`, `deleteUser` only
71
+ *
72
+ * 2. `disableAllUniqueLookups: true` (NoUniqueLookupPreset):
73
+ * - Primary key: query lookup DISABLED, mutations ENABLED
74
+ * - Non-primary-key: everything disabled
75
+ * Result: No query lookups (use filters), but `updateUser`, `deleteUser` still work
76
+ */
77
+ /**
78
+ * Creates a plugin that controls unique constraint lookup behavior.
79
+ *
80
+ * @param options - Configuration options
81
+ * @param options.disableAllUniqueLookups - If true, disables ALL unique lookups including primary keys
82
+ */
83
+ export declare function createUniqueLookupPlugin(options?: UniqueLookupOptions): GraphileConfig.Plugin;
84
+ export declare const PrimaryKeyOnlyPlugin: GraphileConfig.Plugin;
85
+ export declare const NoUniqueLookupPlugin: GraphileConfig.Plugin;
86
+ /**
87
+ * Preset that keeps only primary key lookups.
88
+ * Use this in your main preset's `extends` array.
89
+ */
90
+ export declare const PrimaryKeyOnlyPreset: GraphileConfig.Preset;
91
+ /**
92
+ * Preset that disables ALL unique lookups (including primary keys).
93
+ * Users must use collection queries with filters instead.
94
+ * Use this in your main preset's `extends` array.
95
+ */
96
+ export declare const NoUniqueLookupPreset: GraphileConfig.Preset;