graphile-settings 4.1.0 → 4.3.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.
- package/esm/index.d.ts +1 -2
- package/esm/index.js +2 -4
- package/esm/plugins/index.d.ts +4 -13
- package/esm/plugins/index.js +5 -21
- package/esm/presets/constructive-preset.d.ts +4 -0
- package/esm/presets/constructive-preset.js +17 -9
- package/esm/upload-resolver.d.ts +43 -0
- package/esm/upload-resolver.js +168 -0
- package/index.d.ts +1 -2
- package/index.js +4 -7
- package/package.json +26 -14
- package/plugins/index.d.ts +4 -13
- package/plugins/index.js +32 -44
- package/presets/constructive-preset.d.ts +4 -0
- package/presets/constructive-preset.js +26 -18
- package/upload-resolver.d.ts +43 -0
- package/upload-resolver.js +175 -0
- package/esm/plugins/conflict-detector.d.ts +0 -7
- package/esm/plugins/conflict-detector.js +0 -67
- package/esm/plugins/custom-inflector.d.ts +0 -9
- package/esm/plugins/custom-inflector.js +0 -382
- package/esm/plugins/enable-all-filter-columns.d.ts +0 -60
- package/esm/plugins/enable-all-filter-columns.js +0 -85
- package/esm/plugins/inflector-logger.d.ts +0 -7
- package/esm/plugins/inflector-logger.js +0 -215
- package/esm/plugins/many-to-many-preset.d.ts +0 -62
- package/esm/plugins/many-to-many-preset.js +0 -86
- package/esm/plugins/meta-schema/cache.d.ts +0 -4
- package/esm/plugins/meta-schema/cache.js +0 -7
- package/esm/plugins/meta-schema/constraint-meta-builders.d.ts +0 -13
- package/esm/plugins/meta-schema/constraint-meta-builders.js +0 -51
- package/esm/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/esm/plugins/meta-schema/graphql-meta-field.js +0 -201
- package/esm/plugins/meta-schema/inflection-utils.d.ts +0 -4
- package/esm/plugins/meta-schema/inflection-utils.js +0 -20
- package/esm/plugins/meta-schema/name-meta-builders.d.ts +0 -4
- package/esm/plugins/meta-schema/name-meta-builders.js +0 -38
- package/esm/plugins/meta-schema/plugin.d.ts +0 -2
- package/esm/plugins/meta-schema/plugin.js +0 -23
- package/esm/plugins/meta-schema/relation-meta-builders.d.ts +0 -8
- package/esm/plugins/meta-schema/relation-meta-builders.js +0 -115
- package/esm/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/esm/plugins/meta-schema/table-meta-builder.js +0 -69
- package/esm/plugins/meta-schema/table-meta-context.d.ts +0 -13
- package/esm/plugins/meta-schema/table-meta-context.js +0 -11
- package/esm/plugins/meta-schema/table-resource-utils.d.ts +0 -12
- package/esm/plugins/meta-schema/table-resource-utils.js +0 -50
- package/esm/plugins/meta-schema/type-mappings.d.ts +0 -3
- package/esm/plugins/meta-schema/type-mappings.js +0 -75
- package/esm/plugins/meta-schema/types.d.ts +0 -206
- package/esm/plugins/meta-schema/types.js +0 -1
- package/esm/plugins/meta-schema.d.ts +0 -19
- package/esm/plugins/meta-schema.js +0 -20
- package/esm/plugins/minimal-preset.d.ts +0 -7
- package/esm/plugins/minimal-preset.js +0 -42
- package/esm/plugins/pg-type-mappings.d.ts +0 -41
- package/esm/plugins/pg-type-mappings.js +0 -122
- package/esm/plugins/primary-key-only.d.ts +0 -96
- package/esm/plugins/primary-key-only.js +0 -143
- package/plugins/conflict-detector.d.ts +0 -7
- package/plugins/conflict-detector.js +0 -70
- package/plugins/custom-inflector.d.ts +0 -9
- package/plugins/custom-inflector.js +0 -385
- package/plugins/enable-all-filter-columns.d.ts +0 -60
- package/plugins/enable-all-filter-columns.js +0 -88
- package/plugins/inflector-logger.d.ts +0 -7
- package/plugins/inflector-logger.js +0 -218
- package/plugins/many-to-many-preset.d.ts +0 -62
- package/plugins/many-to-many-preset.js +0 -89
- package/plugins/meta-schema/cache.d.ts +0 -4
- package/plugins/meta-schema/cache.js +0 -12
- package/plugins/meta-schema/constraint-meta-builders.d.ts +0 -13
- package/plugins/meta-schema/constraint-meta-builders.js +0 -58
- package/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/plugins/meta-schema/graphql-meta-field.js +0 -204
- package/plugins/meta-schema/inflection-utils.d.ts +0 -4
- package/plugins/meta-schema/inflection-utils.js +0 -25
- package/plugins/meta-schema/name-meta-builders.d.ts +0 -4
- package/plugins/meta-schema/name-meta-builders.js +0 -43
- package/plugins/meta-schema/plugin.d.ts +0 -2
- package/plugins/meta-schema/plugin.js +0 -26
- package/plugins/meta-schema/relation-meta-builders.d.ts +0 -8
- package/plugins/meta-schema/relation-meta-builders.js +0 -120
- package/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/plugins/meta-schema/table-meta-builder.js +0 -72
- package/plugins/meta-schema/table-meta-context.d.ts +0 -13
- package/plugins/meta-schema/table-meta-context.js +0 -15
- package/plugins/meta-schema/table-resource-utils.d.ts +0 -12
- package/plugins/meta-schema/table-resource-utils.js +0 -60
- package/plugins/meta-schema/type-mappings.d.ts +0 -3
- package/plugins/meta-schema/type-mappings.js +0 -79
- package/plugins/meta-schema/types.d.ts +0 -206
- package/plugins/meta-schema/types.js +0 -2
- package/plugins/meta-schema.d.ts +0 -19
- package/plugins/meta-schema.js +0 -20
- package/plugins/minimal-preset.d.ts +0 -7
- package/plugins/minimal-preset.js +0 -45
- package/plugins/pg-type-mappings.d.ts +0 -41
- package/plugins/pg-type-mappings.js +0 -128
- package/plugins/primary-key-only.d.ts +0 -96
- package/plugins/primary-key-only.js +0 -147
|
@@ -1,20 +0,0 @@
|
|
|
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 { cachedTablesMeta } from './meta-schema/cache';
|
|
8
|
-
import { MetaSchemaPlugin } from './meta-schema/plugin';
|
|
9
|
-
import { buildFieldMeta, pgTypeToGqlType } from './meta-schema/type-mappings';
|
|
10
|
-
export { MetaSchemaPlugin };
|
|
11
|
-
export const MetaSchemaPreset = {
|
|
12
|
-
plugins: [MetaSchemaPlugin],
|
|
13
|
-
};
|
|
14
|
-
/** @internal Exported for testing only */
|
|
15
|
-
export { pgTypeToGqlType as _pgTypeToGqlType };
|
|
16
|
-
/** @internal Exported for testing only */
|
|
17
|
-
export { buildFieldMeta as _buildFieldMeta };
|
|
18
|
-
/** @internal Exported for testing only */
|
|
19
|
-
export { cachedTablesMeta as _cachedTablesMeta };
|
|
20
|
-
export default MetaSchemaPlugin;
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { defaultPreset as graphileBuildPreset } from 'graphile-build';
|
|
2
|
-
import { defaultPreset as graphileBuildPgPreset } from 'graphile-build-pg';
|
|
3
|
-
/**
|
|
4
|
-
* Minimal PostGraphile v5 preset without Node/Relay features.
|
|
5
|
-
*
|
|
6
|
-
* This preset builds a clean GraphQL API from PostgreSQL without:
|
|
7
|
-
* - Global Node ID (Relay spec) - so `id` columns stay as `id`
|
|
8
|
-
* - Schema prefixing for naming conflicts
|
|
9
|
-
*
|
|
10
|
-
* We use the default presets from graphile-build and graphile-build-pg
|
|
11
|
-
* and disable all Node-related plugins.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* List of Node/Relay-related plugins to disable.
|
|
15
|
-
* These implement the Relay Global Object Identification spec which:
|
|
16
|
-
* - Adds a global `id` field to types
|
|
17
|
-
* - Renames actual `id` columns to `rowId`
|
|
18
|
-
* - Adds Node interface and nodeId lookups
|
|
19
|
-
*
|
|
20
|
-
* Since we use UUIDs, we don't need any of this.
|
|
21
|
-
*/
|
|
22
|
-
const NODE_PLUGINS_TO_DISABLE = [
|
|
23
|
-
// Core Node plugins from graphile-build
|
|
24
|
-
'NodePlugin',
|
|
25
|
-
'AddNodeInterfaceToSuitableTypesPlugin',
|
|
26
|
-
'NodeIdCodecBase64JSONPlugin',
|
|
27
|
-
'NodeIdCodecPipeStringPlugin',
|
|
28
|
-
'RegisterQueryNodePlugin',
|
|
29
|
-
'NodeAccessorPlugin',
|
|
30
|
-
// PG-specific Node plugins from graphile-build-pg
|
|
31
|
-
'PgNodeIdAttributesPlugin',
|
|
32
|
-
'PgTableNodePlugin',
|
|
33
|
-
];
|
|
34
|
-
/**
|
|
35
|
-
* Minimal preset with all the PostgreSQL functionality but without Node/Relay features.
|
|
36
|
-
* This keeps `id` columns as `id` (no renaming to `rowId`).
|
|
37
|
-
*/
|
|
38
|
-
export const MinimalPreset = {
|
|
39
|
-
extends: [graphileBuildPreset, graphileBuildPgPreset],
|
|
40
|
-
disablePlugins: NODE_PLUGINS_TO_DISABLE,
|
|
41
|
-
};
|
|
42
|
-
export default MinimalPreset;
|
|
@@ -1,41 +0,0 @@
|
|
|
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;
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { GraphQLString } from 'graphql';
|
|
2
|
-
import sql from 'pg-sql2';
|
|
3
|
-
/**
|
|
4
|
-
* Default type mappings for common custom PostgreSQL types.
|
|
5
|
-
* These are typically domain types or composite types that should be
|
|
6
|
-
* represented as simple scalars in GraphQL.
|
|
7
|
-
*/
|
|
8
|
-
const DEFAULT_MAPPINGS = [
|
|
9
|
-
{ name: 'email', namespaceName: 'public', type: 'String' },
|
|
10
|
-
{ name: 'hostname', namespaceName: 'public', type: 'String' },
|
|
11
|
-
{ name: 'origin', namespaceName: 'public', type: 'String' },
|
|
12
|
-
{ name: 'url', namespaceName: 'public', type: 'String' },
|
|
13
|
-
];
|
|
14
|
-
/**
|
|
15
|
-
* Plugin that maps custom PostgreSQL types to GraphQL scalar types.
|
|
16
|
-
*
|
|
17
|
-
* This is useful for domain types or composite types that should be
|
|
18
|
-
* represented as simple scalars (String, JSON) in the GraphQL API.
|
|
19
|
-
*
|
|
20
|
-
* For example, if you have:
|
|
21
|
-
* CREATE DOMAIN email AS text;
|
|
22
|
-
* CREATE TYPE url AS (value text);
|
|
23
|
-
*
|
|
24
|
-
* This plugin will map them to GraphQL String type instead of creating
|
|
25
|
-
* complex object types.
|
|
26
|
-
*
|
|
27
|
-
* The plugin handles both:
|
|
28
|
-
* 1. Domain types (simple aliases) - maps directly to the target scalar
|
|
29
|
-
* 2. Composite types - extracts the first field's value when converting from PG
|
|
30
|
-
*/
|
|
31
|
-
export const PgTypeMappingsPlugin = {
|
|
32
|
-
name: 'PgTypeMappingsPlugin',
|
|
33
|
-
version: '1.0.0',
|
|
34
|
-
gather: {
|
|
35
|
-
hooks: {
|
|
36
|
-
async pgCodecs_findPgCodec(info, event) {
|
|
37
|
-
if (event.pgCodec) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const { pgType: type, serviceName } = event;
|
|
41
|
-
// Find the namespace for this type
|
|
42
|
-
const namespace = await info.helpers.pgIntrospection.getNamespace(serviceName, type.typnamespace);
|
|
43
|
-
if (!namespace) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
// Check if this type matches any of our mappings
|
|
47
|
-
const mapping = DEFAULT_MAPPINGS.find(m => m.name === type.typname && m.namespaceName === namespace.nspname);
|
|
48
|
-
if (!mapping) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
// Create a codec for this type
|
|
52
|
-
// For composite types, the fromPg function extracts the first field's value
|
|
53
|
-
// For domain types, it just passes through the value
|
|
54
|
-
event.pgCodec = {
|
|
55
|
-
name: type.typname,
|
|
56
|
-
sqlType: sql.identifier(namespace.nspname, type.typname),
|
|
57
|
-
fromPg: (value) => {
|
|
58
|
-
if (value == null) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
// If it's already a scalar, return it
|
|
62
|
-
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
// For composite types, extract the first field's value
|
|
66
|
-
const obj = value;
|
|
67
|
-
const keys = Object.keys(obj);
|
|
68
|
-
if (keys.length > 0) {
|
|
69
|
-
return obj[keys[0]];
|
|
70
|
-
}
|
|
71
|
-
return value;
|
|
72
|
-
},
|
|
73
|
-
toPg: (value) => value,
|
|
74
|
-
attributes: undefined,
|
|
75
|
-
executor: null,
|
|
76
|
-
extensions: {
|
|
77
|
-
oid: type._id,
|
|
78
|
-
pg: {
|
|
79
|
-
serviceName,
|
|
80
|
-
schemaName: namespace.nspname,
|
|
81
|
-
name: type.typname,
|
|
82
|
-
},
|
|
83
|
-
tags: {
|
|
84
|
-
// Mark this as a custom mapped type
|
|
85
|
-
pgTypeMappings: mapping.type,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
schema: {
|
|
93
|
-
hooks: {
|
|
94
|
-
init(_, build) {
|
|
95
|
-
const { setGraphQLTypeForPgCodec } = build;
|
|
96
|
-
// Map our custom codecs to GraphQL types
|
|
97
|
-
for (const codec of Object.values(build.input.pgRegistry.pgCodecs)) {
|
|
98
|
-
const mappingType = codec.extensions?.tags?.pgTypeMappings;
|
|
99
|
-
if (mappingType) {
|
|
100
|
-
const gqlTypeName = GraphQLString.name;
|
|
101
|
-
setGraphQLTypeForPgCodec(codec, 'input', gqlTypeName);
|
|
102
|
-
setGraphQLTypeForPgCodec(codec, 'output', gqlTypeName);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return _;
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Preset that includes the PG type mappings plugin.
|
|
112
|
-
*
|
|
113
|
-
* This preset maps common custom PostgreSQL types to GraphQL scalars:
|
|
114
|
-
* - email -> String
|
|
115
|
-
* - hostname -> String
|
|
116
|
-
* - url -> String
|
|
117
|
-
* - origin -> String
|
|
118
|
-
*/
|
|
119
|
-
export const PgTypeMappingsPreset = {
|
|
120
|
-
plugins: [PgTypeMappingsPlugin],
|
|
121
|
-
};
|
|
122
|
-
export default PgTypeMappingsPlugin;
|
|
@@ -1,96 +0,0 @@
|
|
|
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;
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PrimaryKeyOnlyPlugin - Disables non-primary-key unique constraint lookups for
|
|
3
|
-
* BOTH queries AND mutations.
|
|
4
|
-
*
|
|
5
|
-
* WHY THIS EXISTS:
|
|
6
|
-
* PostGraphile v5 creates fields for EVERY unique constraint on a table:
|
|
7
|
-
*
|
|
8
|
-
* QUERIES (PgRowByUniquePlugin):
|
|
9
|
-
* - `user(id)`, `userByEmail(email)`, `userByUsername(username)`
|
|
10
|
-
*
|
|
11
|
-
* MUTATIONS (PgMutationUpdateDeletePlugin):
|
|
12
|
-
* - `updateUser`, `updateUserByEmail`, `updateUserByUsername`
|
|
13
|
-
* - `deleteUser`, `deleteUserByEmail`, `deleteUserByUsername`
|
|
14
|
-
*
|
|
15
|
-
* For code generation (React Query, etc.), this creates unnecessary complexity.
|
|
16
|
-
* The same operations can be done using the primary key lookup or filters.
|
|
17
|
-
* Standardizing on primary keys reduces the API surface and generated code.
|
|
18
|
-
*
|
|
19
|
-
* SOURCE CODE REFERENCES:
|
|
20
|
-
*
|
|
21
|
-
* 1. Query fields (PgRowByUniquePlugin):
|
|
22
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRowByUniquePlugin.ts#L42-L257
|
|
23
|
-
*
|
|
24
|
-
* The behavior check for queries:
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const fieldBehaviorScope = "query:resource:single";
|
|
27
|
-
* if (!build.behavior.pgResourceUniqueMatches([resource, unique], fieldBehaviorScope)) {
|
|
28
|
-
* return memo; // Skip this field
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* 2. Mutation fields (PgMutationUpdateDeletePlugin):
|
|
33
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgMutationUpdateDeletePlugin.ts
|
|
34
|
-
*
|
|
35
|
-
* The behavior check for mutations:
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const constraintMode = `constraint:${mode}`; // "constraint:resource:update" or "constraint:resource:delete"
|
|
38
|
-
* ...resource.uniques.filter((unique) => {
|
|
39
|
-
* return build.behavior.pgResourceUniqueMatches([resource, unique], constraintMode);
|
|
40
|
-
* })
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* OUR FIX:
|
|
44
|
-
* We use the behavior system's OVERRIDE phase (not inferred) to disable these behaviors.
|
|
45
|
-
* The override phase runs AFTER the behavior multiplication/preferences system processes
|
|
46
|
-
* behaviors, giving us the final say on what's enabled/disabled.
|
|
47
|
-
*
|
|
48
|
-
* Behaviors we control:
|
|
49
|
-
* - `-single` - Disables query lookups (userByEmail, etc.)
|
|
50
|
-
* - `-constraint:resource:update` - Disables updateByX mutations
|
|
51
|
-
* - `-constraint:resource:delete` - Disables deleteByX mutations
|
|
52
|
-
*
|
|
53
|
-
* CONFIGURATION OPTIONS:
|
|
54
|
-
*
|
|
55
|
-
* 1. `disableAllUniqueLookups: false` (default - PrimaryKeyOnlyPreset):
|
|
56
|
-
* - Primary key: query lookup + mutations enabled
|
|
57
|
-
* - Non-primary-key: everything disabled
|
|
58
|
-
* Result: `user(id)`, `updateUser`, `deleteUser` only
|
|
59
|
-
*
|
|
60
|
-
* 2. `disableAllUniqueLookups: true` (NoUniqueLookupPreset):
|
|
61
|
-
* - Primary key: query lookup DISABLED, mutations ENABLED
|
|
62
|
-
* - Non-primary-key: everything disabled
|
|
63
|
-
* Result: No query lookups (use filters), but `updateUser`, `deleteUser` still work
|
|
64
|
-
*/
|
|
65
|
-
/**
|
|
66
|
-
* Creates a plugin that controls unique constraint lookup behavior.
|
|
67
|
-
*
|
|
68
|
-
* @param options - Configuration options
|
|
69
|
-
* @param options.disableAllUniqueLookups - If true, disables ALL unique lookups including primary keys
|
|
70
|
-
*/
|
|
71
|
-
export function createUniqueLookupPlugin(options = {}) {
|
|
72
|
-
const { disableAllUniqueLookups = false } = options;
|
|
73
|
-
return {
|
|
74
|
-
name: 'UniqueLookupPlugin',
|
|
75
|
-
version: '1.0.0',
|
|
76
|
-
description: disableAllUniqueLookups
|
|
77
|
-
? 'Disables all unique constraint lookups (use filters instead)'
|
|
78
|
-
: 'Disables non-primary-key unique constraint lookups to reduce API surface',
|
|
79
|
-
schema: {
|
|
80
|
-
entityBehavior: {
|
|
81
|
-
pgResourceUnique: {
|
|
82
|
-
// Use 'override' phase instead of 'inferred' - override runs AFTER
|
|
83
|
-
// the behavior multiplication/preferences system processes behaviors,
|
|
84
|
-
// so it has the final say on what behaviors are enabled/disabled.
|
|
85
|
-
override: {
|
|
86
|
-
provides: ['uniqueLookupControl'],
|
|
87
|
-
callback(behavior, [_resource, unique]) {
|
|
88
|
-
if (disableAllUniqueLookups) {
|
|
89
|
-
// Disable ALL unique QUERY lookups - users must use filters
|
|
90
|
-
// But KEEP primary key mutations (updateX, deleteX)
|
|
91
|
-
if (unique.isPrimary) {
|
|
92
|
-
// Primary key: only disable query lookups, keep mutations
|
|
93
|
-
return [behavior, '-single'];
|
|
94
|
-
}
|
|
95
|
-
// Non-primary-key: disable everything (queries and mutations)
|
|
96
|
-
return [
|
|
97
|
-
behavior,
|
|
98
|
-
'-single',
|
|
99
|
-
'-constraint:resource:update',
|
|
100
|
-
'-constraint:resource:delete',
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
// Only allow primary key lookups (both queries and mutations)
|
|
104
|
-
if (!unique.isPrimary) {
|
|
105
|
-
// Disable non-primary-key unique constraint lookups for queries and mutations
|
|
106
|
-
return [
|
|
107
|
-
behavior,
|
|
108
|
-
'-single',
|
|
109
|
-
'-constraint:resource:update',
|
|
110
|
-
'-constraint:resource:delete',
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
return behavior;
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
// Default plugin instance (primary key only)
|
|
122
|
-
export const PrimaryKeyOnlyPlugin = createUniqueLookupPlugin({
|
|
123
|
-
disableAllUniqueLookups: false,
|
|
124
|
-
});
|
|
125
|
-
// Plugin that disables ALL unique lookups
|
|
126
|
-
export const NoUniqueLookupPlugin = createUniqueLookupPlugin({
|
|
127
|
-
disableAllUniqueLookups: true,
|
|
128
|
-
});
|
|
129
|
-
/**
|
|
130
|
-
* Preset that keeps only primary key lookups.
|
|
131
|
-
* Use this in your main preset's `extends` array.
|
|
132
|
-
*/
|
|
133
|
-
export const PrimaryKeyOnlyPreset = {
|
|
134
|
-
plugins: [PrimaryKeyOnlyPlugin],
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Preset that disables ALL unique lookups (including primary keys).
|
|
138
|
-
* Users must use collection queries with filters instead.
|
|
139
|
-
* Use this in your main preset's `extends` array.
|
|
140
|
-
*/
|
|
141
|
-
export const NoUniqueLookupPreset = {
|
|
142
|
-
plugins: [NoUniqueLookupPlugin],
|
|
143
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
-
export declare const ConflictDetectorPlugin: GraphileConfig.Plugin;
|
|
3
|
-
/**
|
|
4
|
-
* Preset that includes the conflict detector plugin.
|
|
5
|
-
*/
|
|
6
|
-
export declare const ConflictDetectorPreset: GraphileConfig.Preset;
|
|
7
|
-
export default ConflictDetectorPlugin;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConflictDetectorPreset = exports.ConflictDetectorPlugin = void 0;
|
|
4
|
-
exports.ConflictDetectorPlugin = {
|
|
5
|
-
name: 'ConflictDetectorPlugin',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
schema: {
|
|
8
|
-
hooks: {
|
|
9
|
-
build(build) {
|
|
10
|
-
// Track codecs by their GraphQL name to detect conflicts
|
|
11
|
-
const codecsByName = new Map();
|
|
12
|
-
// Get configured schemas from pgServices to only check relevant codecs
|
|
13
|
-
const configuredSchemas = new Set();
|
|
14
|
-
const pgServices = build.resolvedPreset?.pgServices ?? [];
|
|
15
|
-
for (const service of pgServices) {
|
|
16
|
-
for (const schema of service.schemas ?? ['public']) {
|
|
17
|
-
configuredSchemas.add(schema);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Iterate through all codecs to find tables
|
|
21
|
-
for (const codec of Object.values(build.input.pgRegistry.pgCodecs)) {
|
|
22
|
-
// Skip non-table codecs (those without attributes or anonymous ones)
|
|
23
|
-
if (!codec.attributes || codec.isAnonymous)
|
|
24
|
-
continue;
|
|
25
|
-
// Get the schema name from the codec's extensions
|
|
26
|
-
const pgExtensions = codec.extensions?.pg;
|
|
27
|
-
const schemaName = pgExtensions?.schemaName || 'unknown';
|
|
28
|
-
const tableName = codec.name;
|
|
29
|
-
// Skip codecs from schemas not in the configured list
|
|
30
|
-
if (configuredSchemas.size > 0 && !configuredSchemas.has(schemaName)) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
// Get the GraphQL name that would be generated
|
|
34
|
-
const graphqlName = build.inflection.tableType(codec);
|
|
35
|
-
const info = {
|
|
36
|
-
name: graphqlName,
|
|
37
|
-
schemaName,
|
|
38
|
-
tableName,
|
|
39
|
-
};
|
|
40
|
-
if (!codecsByName.has(graphqlName)) {
|
|
41
|
-
codecsByName.set(graphqlName, []);
|
|
42
|
-
}
|
|
43
|
-
codecsByName.get(graphqlName).push(info);
|
|
44
|
-
}
|
|
45
|
-
// Check for conflicts and log warnings
|
|
46
|
-
for (const [graphqlName, codecs] of codecsByName) {
|
|
47
|
-
if (codecs.length > 1) {
|
|
48
|
-
const locations = codecs
|
|
49
|
-
.map((c) => `${c.schemaName}.${c.tableName}`)
|
|
50
|
-
.join(', ');
|
|
51
|
-
console.warn(`\nNAMING CONFLICT DETECTED: GraphQL type "${graphqlName}" would be generated from multiple tables:\n` +
|
|
52
|
-
` Tables: ${locations}\n` +
|
|
53
|
-
` Resolution options:\n` +
|
|
54
|
-
` 1. Add @name smart tag to one table: COMMENT ON TABLE schema.table IS E'@name UniqueTypeName';\n` +
|
|
55
|
-
` 2. Rename one of the tables in the database\n` +
|
|
56
|
-
` 3. Exclude one table from the schema using @omit smart tag\n`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return build;
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Preset that includes the conflict detector plugin.
|
|
66
|
-
*/
|
|
67
|
-
exports.ConflictDetectorPreset = {
|
|
68
|
-
plugins: [exports.ConflictDetectorPlugin],
|
|
69
|
-
};
|
|
70
|
-
exports.default = exports.ConflictDetectorPlugin;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
-
export declare const InflektPlugin: GraphileConfig.Plugin;
|
|
3
|
-
/**
|
|
4
|
-
* Preset that includes the inflekt-based inflector plugin.
|
|
5
|
-
* Use this in your main preset's `extends` array.
|
|
6
|
-
*/
|
|
7
|
-
export declare const InflektPreset: GraphileConfig.Preset;
|
|
8
|
-
export declare const CustomInflectorPlugin: GraphileConfig.Plugin;
|
|
9
|
-
export declare const CustomInflectorPreset: GraphileConfig.Preset;
|