graphile-settings 4.1.1 → 4.3.1
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 +14 -6
- 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,60 +0,0 @@
|
|
|
1
|
-
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
-
/**
|
|
3
|
-
* EnableAllFilterColumnsPlugin - Enables filtering on ALL columns, not just indexed ones.
|
|
4
|
-
*
|
|
5
|
-
* WHY THIS EXISTS:
|
|
6
|
-
* PostGraphile v5's `PgIndexBehaviorsPlugin` restricts filtering to only indexed columns
|
|
7
|
-
* by default. This is a performance optimization - filtering on non-indexed columns can
|
|
8
|
-
* cause slow table scans. However, for development and flexibility, we want to allow
|
|
9
|
-
* filtering on all columns and let developers/DBAs decide which columns need indexes.
|
|
10
|
-
*
|
|
11
|
-
* SOURCE CODE REFERENCE:
|
|
12
|
-
* PgIndexBehaviorsPlugin marks non-indexed columns with `extensions.isIndexed = false`
|
|
13
|
-
* and then adds `-filterBy` behavior to remove them from filters:
|
|
14
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgIndexBehaviorsPlugin.ts
|
|
15
|
-
*
|
|
16
|
-
* The relevant v5 code (from PgIndexBehaviorsPlugin):
|
|
17
|
-
* ```typescript
|
|
18
|
-
* entityBehavior: {
|
|
19
|
-
* pgCodecAttribute: {
|
|
20
|
-
* inferred: {
|
|
21
|
-
* after: ["inferred"],
|
|
22
|
-
* provides: ["postInferred"],
|
|
23
|
-
* callback(behavior, [codec, attributeName]) {
|
|
24
|
-
* const newBehavior = [behavior];
|
|
25
|
-
* const attr = codec.attributes[attributeName];
|
|
26
|
-
* if (attr.extensions?.isIndexed === false) {
|
|
27
|
-
* newBehavior.push("-filterBy", "-orderBy"); // <-- This removes filterBy!
|
|
28
|
-
* }
|
|
29
|
-
* return newBehavior;
|
|
30
|
-
* },
|
|
31
|
-
* },
|
|
32
|
-
* },
|
|
33
|
-
* },
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* OUR FIX:
|
|
37
|
-
* We add a behavior callback that runs AFTER PgIndexBehaviorsPlugin's "postInferred" phase
|
|
38
|
-
* and adds `+attribute:filterBy` back to ALL columns, regardless of index status.
|
|
39
|
-
*
|
|
40
|
-
* This means:
|
|
41
|
-
* - All columns will appear in the connection filter's filter argument
|
|
42
|
-
* - Developers can filter by any column
|
|
43
|
-
* - It's the developer's/DBA's responsibility to add indexes for frequently filtered columns
|
|
44
|
-
*
|
|
45
|
-
* PERFORMANCE WARNING:
|
|
46
|
-
* Filtering on non-indexed columns can cause full table scans, which may be slow on large
|
|
47
|
-
* tables. Monitor your query performance and add indexes as needed. You can check which
|
|
48
|
-
* columns are indexed by querying pg_indexes or using EXPLAIN ANALYZE on your queries.
|
|
49
|
-
*
|
|
50
|
-
* To identify non-indexed columns being filtered, you can:
|
|
51
|
-
* 1. Enable slow query logging in PostgreSQL (log_min_duration_statement)
|
|
52
|
-
* 2. Use EXPLAIN ANALYZE on queries to see if they're doing sequential scans
|
|
53
|
-
* 3. Check pg_stat_user_tables for seq_scan counts
|
|
54
|
-
*/
|
|
55
|
-
export declare const EnableAllFilterColumnsPlugin: GraphileConfig.Plugin;
|
|
56
|
-
/**
|
|
57
|
-
* Preset that includes the EnableAllFilterColumnsPlugin.
|
|
58
|
-
* Add this to your main preset's `extends` array.
|
|
59
|
-
*/
|
|
60
|
-
export declare const EnableAllFilterColumnsPreset: GraphileConfig.Preset;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EnableAllFilterColumnsPlugin - Enables filtering on ALL columns, not just indexed ones.
|
|
3
|
-
*
|
|
4
|
-
* WHY THIS EXISTS:
|
|
5
|
-
* PostGraphile v5's `PgIndexBehaviorsPlugin` restricts filtering to only indexed columns
|
|
6
|
-
* by default. This is a performance optimization - filtering on non-indexed columns can
|
|
7
|
-
* cause slow table scans. However, for development and flexibility, we want to allow
|
|
8
|
-
* filtering on all columns and let developers/DBAs decide which columns need indexes.
|
|
9
|
-
*
|
|
10
|
-
* SOURCE CODE REFERENCE:
|
|
11
|
-
* PgIndexBehaviorsPlugin marks non-indexed columns with `extensions.isIndexed = false`
|
|
12
|
-
* and then adds `-filterBy` behavior to remove them from filters:
|
|
13
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgIndexBehaviorsPlugin.ts
|
|
14
|
-
*
|
|
15
|
-
* The relevant v5 code (from PgIndexBehaviorsPlugin):
|
|
16
|
-
* ```typescript
|
|
17
|
-
* entityBehavior: {
|
|
18
|
-
* pgCodecAttribute: {
|
|
19
|
-
* inferred: {
|
|
20
|
-
* after: ["inferred"],
|
|
21
|
-
* provides: ["postInferred"],
|
|
22
|
-
* callback(behavior, [codec, attributeName]) {
|
|
23
|
-
* const newBehavior = [behavior];
|
|
24
|
-
* const attr = codec.attributes[attributeName];
|
|
25
|
-
* if (attr.extensions?.isIndexed === false) {
|
|
26
|
-
* newBehavior.push("-filterBy", "-orderBy"); // <-- This removes filterBy!
|
|
27
|
-
* }
|
|
28
|
-
* return newBehavior;
|
|
29
|
-
* },
|
|
30
|
-
* },
|
|
31
|
-
* },
|
|
32
|
-
* },
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* OUR FIX:
|
|
36
|
-
* We add a behavior callback that runs AFTER PgIndexBehaviorsPlugin's "postInferred" phase
|
|
37
|
-
* and adds `+attribute:filterBy` back to ALL columns, regardless of index status.
|
|
38
|
-
*
|
|
39
|
-
* This means:
|
|
40
|
-
* - All columns will appear in the connection filter's filter argument
|
|
41
|
-
* - Developers can filter by any column
|
|
42
|
-
* - It's the developer's/DBA's responsibility to add indexes for frequently filtered columns
|
|
43
|
-
*
|
|
44
|
-
* PERFORMANCE WARNING:
|
|
45
|
-
* Filtering on non-indexed columns can cause full table scans, which may be slow on large
|
|
46
|
-
* tables. Monitor your query performance and add indexes as needed. You can check which
|
|
47
|
-
* columns are indexed by querying pg_indexes or using EXPLAIN ANALYZE on your queries.
|
|
48
|
-
*
|
|
49
|
-
* To identify non-indexed columns being filtered, you can:
|
|
50
|
-
* 1. Enable slow query logging in PostgreSQL (log_min_duration_statement)
|
|
51
|
-
* 2. Use EXPLAIN ANALYZE on queries to see if they're doing sequential scans
|
|
52
|
-
* 3. Check pg_stat_user_tables for seq_scan counts
|
|
53
|
-
*/
|
|
54
|
-
export const EnableAllFilterColumnsPlugin = {
|
|
55
|
-
name: 'EnableAllFilterColumnsPlugin',
|
|
56
|
-
version: '1.0.0',
|
|
57
|
-
description: 'Enables filtering on all columns, not just indexed ones',
|
|
58
|
-
schema: {
|
|
59
|
-
entityBehavior: {
|
|
60
|
-
pgCodecAttribute: {
|
|
61
|
-
/**
|
|
62
|
-
* This callback runs in the "inferred" phase AFTER PgIndexBehaviorsPlugin's
|
|
63
|
-
* "postInferred" phase. It adds `filterBy` back to ALL columns, overriding
|
|
64
|
-
* the `-filterBy` that PgIndexBehaviorsPlugin adds to non-indexed columns.
|
|
65
|
-
*/
|
|
66
|
-
inferred: {
|
|
67
|
-
after: ['postInferred'],
|
|
68
|
-
provides: ['enableAllFilters'],
|
|
69
|
-
callback(behavior) {
|
|
70
|
-
// Add filterBy to override any -filterBy from PgIndexBehaviorsPlugin
|
|
71
|
-
// The behavior system will resolve conflicts, with later additions winning
|
|
72
|
-
return [behavior, 'filterBy'];
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Preset that includes the EnableAllFilterColumnsPlugin.
|
|
81
|
-
* Add this to your main preset's `extends` array.
|
|
82
|
-
*/
|
|
83
|
-
export const EnableAllFilterColumnsPreset = {
|
|
84
|
-
plugins: [EnableAllFilterColumnsPlugin],
|
|
85
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
-
export declare const InflectorLoggerPlugin: GraphileConfig.Plugin;
|
|
3
|
-
/**
|
|
4
|
-
* Preset that includes the inflector logger plugin.
|
|
5
|
-
* Use this in your main preset's `extends` array.
|
|
6
|
-
*/
|
|
7
|
-
export declare const InflectorLoggerPreset: GraphileConfig.Preset;
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* InflectorLoggerPlugin - Logs inflector calls during schema build for debugging.
|
|
3
|
-
*
|
|
4
|
-
* This plugin wraps key inflectors to log what fields are being generated and why.
|
|
5
|
-
* It passes through to the default behavior but logs the inputs and outputs.
|
|
6
|
-
*
|
|
7
|
-
* WHEN DO PLUGINS RUN?
|
|
8
|
-
* Plugins only run at BUILD TIME, not on every request. The schema is built once
|
|
9
|
-
* and cached. This means logging only happens during schema generation, not during
|
|
10
|
-
* query execution.
|
|
11
|
-
*
|
|
12
|
-
* SOURCE CODE REFERENCES:
|
|
13
|
-
*
|
|
14
|
-
* 1. PgRowByUniquePlugin - Creates root Query fields for unique constraints
|
|
15
|
-
* (e.g., `userById`, `userByEmail`, `postBySlug`)
|
|
16
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRowByUniquePlugin.ts#L42-L257
|
|
17
|
-
*
|
|
18
|
-
* 2. PgRelationsPlugin - Creates relationship fields on types for foreign keys
|
|
19
|
-
* - Forward relations: `post.author` (from posts.author_id -> users.id)
|
|
20
|
-
* - Backward relations: `user.posts` (from users.id <- posts.author_id)
|
|
21
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L167-L638
|
|
22
|
-
*
|
|
23
|
-
* 3. PgAttributesPlugin - Creates fields for table columns
|
|
24
|
-
* Also contains the `_attributeName` inflector that renames `id` to `rowId`
|
|
25
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgAttributesPlugin.ts#L289-L298
|
|
26
|
-
*
|
|
27
|
-
* 4. PgTablesPlugin - Creates GraphQL types for tables
|
|
28
|
-
* Contains the `_schemaPrefix` inflector that adds schema prefixes
|
|
29
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgTablesPlugin.ts#L261-L271
|
|
30
|
-
*
|
|
31
|
-
* USAGE:
|
|
32
|
-
* Add InflectorLoggerPlugin to your preset's plugins array.
|
|
33
|
-
* Set INFLECTOR_LOG=1 environment variable to enable logging.
|
|
34
|
-
*/
|
|
35
|
-
const LOG_ENABLED = process.env.INFLECTOR_LOG === '1';
|
|
36
|
-
function log(category, message, details) {
|
|
37
|
-
if (!LOG_ENABLED)
|
|
38
|
-
return;
|
|
39
|
-
const detailsStr = details ? ` ${JSON.stringify(details)}` : '';
|
|
40
|
-
console.log(`[Inflector:${category}]${detailsStr} => ${message}`);
|
|
41
|
-
}
|
|
42
|
-
export const InflectorLoggerPlugin = {
|
|
43
|
-
name: 'InflectorLoggerPlugin',
|
|
44
|
-
version: '1.0.0',
|
|
45
|
-
description: 'Logs inflector calls during schema build for debugging',
|
|
46
|
-
inflection: {
|
|
47
|
-
replace: {
|
|
48
|
-
/**
|
|
49
|
-
* Logs when root Query fields are created for unique constraints.
|
|
50
|
-
* Source: PgRowByUniquePlugin
|
|
51
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRowByUniquePlugin.ts#L50-L63
|
|
52
|
-
*/
|
|
53
|
-
rowByUnique(previous, _options, details) {
|
|
54
|
-
const result = previous(details);
|
|
55
|
-
const { unique, resource } = details;
|
|
56
|
-
log('rowByUnique', result, {
|
|
57
|
-
resource: resource.name,
|
|
58
|
-
uniqueAttributes: unique.attributes,
|
|
59
|
-
isPrimary: unique.isPrimary,
|
|
60
|
-
});
|
|
61
|
-
return result;
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* Logs when forward relation fields are created (e.g., post.author).
|
|
65
|
-
* Source: PgRelationsPlugin
|
|
66
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L228-L230
|
|
67
|
-
*/
|
|
68
|
-
singleRelation(previous, _options, details) {
|
|
69
|
-
const result = previous(details);
|
|
70
|
-
const { codec, relationName, registry } = details;
|
|
71
|
-
const relation = registry.pgRelations[codec.name]?.[relationName];
|
|
72
|
-
log('singleRelation', result, {
|
|
73
|
-
fromType: codec.name,
|
|
74
|
-
relationName,
|
|
75
|
-
toType: relation?.remoteResource?.name,
|
|
76
|
-
localAttributes: relation?.localAttributes,
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
79
|
-
},
|
|
80
|
-
/**
|
|
81
|
-
* Logs when backward single relation fields are created.
|
|
82
|
-
* Source: PgRelationsPlugin
|
|
83
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L250-L252
|
|
84
|
-
*/
|
|
85
|
-
singleRelationBackwards(previous, _options, details) {
|
|
86
|
-
const result = previous(details);
|
|
87
|
-
const { codec, relationName, registry } = details;
|
|
88
|
-
const relation = registry.pgRelations[codec.name]?.[relationName];
|
|
89
|
-
log('singleRelationBackwards', result, {
|
|
90
|
-
fromType: codec.name,
|
|
91
|
-
relationName,
|
|
92
|
-
toType: relation?.remoteResource?.name,
|
|
93
|
-
remoteAttributes: relation?.remoteAttributes,
|
|
94
|
-
});
|
|
95
|
-
return result;
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* Logs when many-relation fields are created (e.g., user.posts).
|
|
99
|
-
* Source: PgRelationsPlugin
|
|
100
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L268-L270
|
|
101
|
-
*/
|
|
102
|
-
_manyRelation(previous, _options, details) {
|
|
103
|
-
const result = previous(details);
|
|
104
|
-
const { codec, relationName, registry } = details;
|
|
105
|
-
const relation = registry.pgRelations[codec.name]?.[relationName];
|
|
106
|
-
log('manyRelation', result, {
|
|
107
|
-
fromType: codec.name,
|
|
108
|
-
relationName,
|
|
109
|
-
toType: relation?.remoteResource?.name,
|
|
110
|
-
remoteAttributes: relation?.remoteAttributes,
|
|
111
|
-
});
|
|
112
|
-
return result;
|
|
113
|
-
},
|
|
114
|
-
/**
|
|
115
|
-
* Logs when connection fields are created for many relations.
|
|
116
|
-
* Source: PgRelationsPlugin
|
|
117
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L271-L279
|
|
118
|
-
*/
|
|
119
|
-
manyRelationConnection(previous, _options, details) {
|
|
120
|
-
const result = previous(details);
|
|
121
|
-
const { codec, relationName } = details;
|
|
122
|
-
log('manyRelationConnection', result, {
|
|
123
|
-
fromType: codec.name,
|
|
124
|
-
relationName,
|
|
125
|
-
});
|
|
126
|
-
return result;
|
|
127
|
-
},
|
|
128
|
-
/**
|
|
129
|
-
* Logs when list fields are created for many relations.
|
|
130
|
-
* Source: PgRelationsPlugin
|
|
131
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts#L280-L288
|
|
132
|
-
*/
|
|
133
|
-
manyRelationList(previous, _options, details) {
|
|
134
|
-
const result = previous(details);
|
|
135
|
-
const { codec, relationName } = details;
|
|
136
|
-
log('manyRelationList', result, {
|
|
137
|
-
fromType: codec.name,
|
|
138
|
-
relationName,
|
|
139
|
-
});
|
|
140
|
-
return result;
|
|
141
|
-
},
|
|
142
|
-
/**
|
|
143
|
-
* Logs when root connection fields are created (e.g., Query.users).
|
|
144
|
-
* Source: PgAllRowsPlugin
|
|
145
|
-
*/
|
|
146
|
-
allRowsConnection(previous, _options, resource) {
|
|
147
|
-
const result = previous(resource);
|
|
148
|
-
log('allRowsConnection', result, {
|
|
149
|
-
resource: resource.name,
|
|
150
|
-
});
|
|
151
|
-
return result;
|
|
152
|
-
},
|
|
153
|
-
/**
|
|
154
|
-
* Logs when update mutation fields are created.
|
|
155
|
-
* Source: PgMutationUpdateDeletePlugin
|
|
156
|
-
*/
|
|
157
|
-
updateByKeysField(previous, _options, details) {
|
|
158
|
-
const result = previous(details);
|
|
159
|
-
const { resource, unique } = details;
|
|
160
|
-
log('updateByKeysField', result, {
|
|
161
|
-
resource: resource.name,
|
|
162
|
-
uniqueAttributes: unique.attributes,
|
|
163
|
-
isPrimary: unique.isPrimary,
|
|
164
|
-
});
|
|
165
|
-
return result;
|
|
166
|
-
},
|
|
167
|
-
/**
|
|
168
|
-
* Logs when delete mutation fields are created.
|
|
169
|
-
* Source: PgMutationUpdateDeletePlugin
|
|
170
|
-
*/
|
|
171
|
-
deleteByKeysField(previous, _options, details) {
|
|
172
|
-
const result = previous(details);
|
|
173
|
-
const { resource, unique } = details;
|
|
174
|
-
log('deleteByKeysField', result, {
|
|
175
|
-
resource: resource.name,
|
|
176
|
-
uniqueAttributes: unique.attributes,
|
|
177
|
-
isPrimary: unique.isPrimary,
|
|
178
|
-
});
|
|
179
|
-
return result;
|
|
180
|
-
},
|
|
181
|
-
/**
|
|
182
|
-
* Logs when attribute (column) fields are created.
|
|
183
|
-
* Source: PgAttributesPlugin
|
|
184
|
-
* https://github.com/graphile/crystal/blob/924b2515c6bd30e5905ac1419a25244b40c8bb4d/graphile-build/graphile-build-pg/src/plugins/PgAttributesPlugin.ts#L289-L298
|
|
185
|
-
*/
|
|
186
|
-
attribute(previous, _options, details) {
|
|
187
|
-
const result = previous(details);
|
|
188
|
-
const { attributeName, codec } = details;
|
|
189
|
-
log('attribute', result, {
|
|
190
|
-
codec: codec.name,
|
|
191
|
-
attributeName,
|
|
192
|
-
});
|
|
193
|
-
return result;
|
|
194
|
-
},
|
|
195
|
-
/**
|
|
196
|
-
* Logs when table types are created.
|
|
197
|
-
* Source: PgTablesPlugin
|
|
198
|
-
*/
|
|
199
|
-
tableType(previous, _options, codec) {
|
|
200
|
-
const result = previous(codec);
|
|
201
|
-
log('tableType', result, {
|
|
202
|
-
codec: codec.name,
|
|
203
|
-
});
|
|
204
|
-
return result;
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Preset that includes the inflector logger plugin.
|
|
211
|
-
* Use this in your main preset's `extends` array.
|
|
212
|
-
*/
|
|
213
|
-
export const InflectorLoggerPreset = {
|
|
214
|
-
plugins: [InflectorLoggerPlugin],
|
|
215
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { GraphileConfig } from 'graphile-config';
|
|
2
|
-
/**
|
|
3
|
-
* Many-to-Many Preset with OPT-IN behavior (disabled by default).
|
|
4
|
-
*
|
|
5
|
-
* WHY THIS EXISTS:
|
|
6
|
-
* The default @graphile-contrib/pg-many-to-many plugin adds many-to-many connection
|
|
7
|
-
* fields to EVERY junction table automatically. This can bloat the API with fields
|
|
8
|
-
* that may never be used.
|
|
9
|
-
*
|
|
10
|
-
* OUR FIX:
|
|
11
|
-
* We override the default behavior to be OPT-IN instead of OPT-OUT:
|
|
12
|
-
* - By default, NO many-to-many fields are generated
|
|
13
|
-
* - To enable for a specific junction table, use: @behavior +manyToMany
|
|
14
|
-
*
|
|
15
|
-
* USAGE:
|
|
16
|
-
* To enable many-to-many for a specific junction table, add a smart comment:
|
|
17
|
-
*
|
|
18
|
-
* ```sql
|
|
19
|
-
* -- Enable many-to-many through this junction table
|
|
20
|
-
* COMMENT ON TABLE post_tags IS E'@behavior +manyToMany';
|
|
21
|
-
*
|
|
22
|
-
* -- Or enable on a specific constraint
|
|
23
|
-
* COMMENT ON CONSTRAINT post_tags_tag_id_fkey ON post_tags IS E'@behavior +manyToMany';
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* SOURCE CODE REFERENCE:
|
|
27
|
-
* The many-to-many plugin uses the behavior system to control field generation:
|
|
28
|
-
* https://github.com/graphile-contrib/pg-many-to-many/blob/v2.0.0-rc.1/src/PgManyToManyRelationPlugin.ts#L478-L503
|
|
29
|
-
*
|
|
30
|
-
* The plugin defines these behaviors:
|
|
31
|
-
* - `manyToMany` - Controls whether many-to-many fields are generated
|
|
32
|
-
* - `connection` - Controls whether connection fields are generated
|
|
33
|
-
* - `list` - Controls whether list fields are generated
|
|
34
|
-
*
|
|
35
|
-
* By default, the plugin's entityBehavior for pgManyToMany includes:
|
|
36
|
-
* `["manyToMany", "connection", "list", behavior]`
|
|
37
|
-
*
|
|
38
|
-
* We override this to be `-manyToMany` by default, requiring explicit opt-in.
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* Plugin that makes many-to-many fields opt-in by default.
|
|
42
|
-
*
|
|
43
|
-
* This overrides the default behavior from @graphile-contrib/pg-many-to-many
|
|
44
|
-
* to require explicit `@behavior +manyToMany` smart tags.
|
|
45
|
-
*/
|
|
46
|
-
export declare const ManyToManyOptInPlugin: GraphileConfig.Plugin;
|
|
47
|
-
/**
|
|
48
|
-
* Preset that includes the many-to-many plugin with opt-in behavior.
|
|
49
|
-
*
|
|
50
|
-
* Use this in your main preset's `extends` array:
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const preset: GraphileConfig.Preset = {
|
|
53
|
-
* extends: [
|
|
54
|
-
* MinimalPreset,
|
|
55
|
-
* ManyToManyOptInPreset,
|
|
56
|
-
* // ... other presets
|
|
57
|
-
* ],
|
|
58
|
-
* };
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare const ManyToManyOptInPreset: GraphileConfig.Preset;
|
|
62
|
-
export default ManyToManyOptInPreset;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { PgManyToManyPreset } from '@graphile-contrib/pg-many-to-many';
|
|
2
|
-
/**
|
|
3
|
-
* Many-to-Many Preset with OPT-IN behavior (disabled by default).
|
|
4
|
-
*
|
|
5
|
-
* WHY THIS EXISTS:
|
|
6
|
-
* The default @graphile-contrib/pg-many-to-many plugin adds many-to-many connection
|
|
7
|
-
* fields to EVERY junction table automatically. This can bloat the API with fields
|
|
8
|
-
* that may never be used.
|
|
9
|
-
*
|
|
10
|
-
* OUR FIX:
|
|
11
|
-
* We override the default behavior to be OPT-IN instead of OPT-OUT:
|
|
12
|
-
* - By default, NO many-to-many fields are generated
|
|
13
|
-
* - To enable for a specific junction table, use: @behavior +manyToMany
|
|
14
|
-
*
|
|
15
|
-
* USAGE:
|
|
16
|
-
* To enable many-to-many for a specific junction table, add a smart comment:
|
|
17
|
-
*
|
|
18
|
-
* ```sql
|
|
19
|
-
* -- Enable many-to-many through this junction table
|
|
20
|
-
* COMMENT ON TABLE post_tags IS E'@behavior +manyToMany';
|
|
21
|
-
*
|
|
22
|
-
* -- Or enable on a specific constraint
|
|
23
|
-
* COMMENT ON CONSTRAINT post_tags_tag_id_fkey ON post_tags IS E'@behavior +manyToMany';
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* SOURCE CODE REFERENCE:
|
|
27
|
-
* The many-to-many plugin uses the behavior system to control field generation:
|
|
28
|
-
* https://github.com/graphile-contrib/pg-many-to-many/blob/v2.0.0-rc.1/src/PgManyToManyRelationPlugin.ts#L478-L503
|
|
29
|
-
*
|
|
30
|
-
* The plugin defines these behaviors:
|
|
31
|
-
* - `manyToMany` - Controls whether many-to-many fields are generated
|
|
32
|
-
* - `connection` - Controls whether connection fields are generated
|
|
33
|
-
* - `list` - Controls whether list fields are generated
|
|
34
|
-
*
|
|
35
|
-
* By default, the plugin's entityBehavior for pgManyToMany includes:
|
|
36
|
-
* `["manyToMany", "connection", "list", behavior]`
|
|
37
|
-
*
|
|
38
|
-
* We override this to be `-manyToMany` by default, requiring explicit opt-in.
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* Plugin that makes many-to-many fields opt-in by default.
|
|
42
|
-
*
|
|
43
|
-
* This overrides the default behavior from @graphile-contrib/pg-many-to-many
|
|
44
|
-
* to require explicit `@behavior +manyToMany` smart tags.
|
|
45
|
-
*/
|
|
46
|
-
export const ManyToManyOptInPlugin = {
|
|
47
|
-
name: 'ManyToManyOptInPlugin',
|
|
48
|
-
version: '1.0.0',
|
|
49
|
-
description: 'Makes many-to-many fields opt-in by default (disabled unless explicitly enabled)',
|
|
50
|
-
schema: {
|
|
51
|
-
entityBehavior: {
|
|
52
|
-
pgManyToMany: {
|
|
53
|
-
// Override the default behavior to be opt-out (disabled by default)
|
|
54
|
-
// The 'inferred' phase runs before 'override', so we use 'inferred'
|
|
55
|
-
// to set the default before any smart tags are processed.
|
|
56
|
-
inferred: {
|
|
57
|
-
provides: ['manyToManyOptIn'],
|
|
58
|
-
before: ['default'],
|
|
59
|
-
callback(behavior) {
|
|
60
|
-
// Default to disabled - require explicit @behavior +manyToMany
|
|
61
|
-
return ['-manyToMany', behavior];
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Preset that includes the many-to-many plugin with opt-in behavior.
|
|
70
|
-
*
|
|
71
|
-
* Use this in your main preset's `extends` array:
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const preset: GraphileConfig.Preset = {
|
|
74
|
-
* extends: [
|
|
75
|
-
* MinimalPreset,
|
|
76
|
-
* ManyToManyOptInPreset,
|
|
77
|
-
* // ... other presets
|
|
78
|
-
* ],
|
|
79
|
-
* };
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export const ManyToManyOptInPreset = {
|
|
83
|
-
extends: [PgManyToManyPreset],
|
|
84
|
-
plugins: [ManyToManyOptInPlugin],
|
|
85
|
-
};
|
|
86
|
-
export default ManyToManyOptInPreset;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type BuildContext } from './table-meta-context';
|
|
2
|
-
import type { ForeignKeyConstraintMeta, PgAttribute, PgCodec, PgRelation, PgUnique, PrimaryKeyConstraintMeta, UniqueConstraintMeta } from './types';
|
|
3
|
-
export declare function buildForeignKeyConstraint(constraintName: string, localCodec: PgCodec, localAttributes: Record<string, PgAttribute>, localAttributeNames: string[], remoteCodec: PgCodec | undefined, remoteAttributes: Record<string, PgAttribute>, remoteAttributeNames: string[], context: BuildContext): ForeignKeyConstraintMeta;
|
|
4
|
-
export declare function buildIndexes(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): {
|
|
5
|
-
name: string;
|
|
6
|
-
isUnique: boolean;
|
|
7
|
-
isPrimary: boolean;
|
|
8
|
-
columns: string[];
|
|
9
|
-
fields: import("./types").FieldMeta[];
|
|
10
|
-
}[];
|
|
11
|
-
export declare function buildPrimaryKey(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): PrimaryKeyConstraintMeta | null;
|
|
12
|
-
export declare function buildUniqueConstraints(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): UniqueConstraintMeta[];
|
|
13
|
-
export declare function buildForeignKeyConstraints(codec: PgCodec, attributes: Record<string, PgAttribute>, relations: Record<string, PgRelation>, context: BuildContext): ForeignKeyConstraintMeta[];
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { buildFieldMeta } from './type-mappings';
|
|
2
|
-
import { buildFieldList } from './table-meta-context';
|
|
3
|
-
export function buildForeignKeyConstraint(constraintName, localCodec, localAttributes, localAttributeNames, remoteCodec, remoteAttributes, remoteAttributeNames, context) {
|
|
4
|
-
const referencedTable = remoteCodec?.name || 'unknown';
|
|
5
|
-
const referencedFields = remoteAttributeNames.map((attrName) => remoteCodec ? context.inflectAttr(attrName, remoteCodec) : attrName);
|
|
6
|
-
return {
|
|
7
|
-
name: constraintName,
|
|
8
|
-
fields: buildFieldList(localAttributeNames, localCodec, localAttributes, context),
|
|
9
|
-
referencedTable,
|
|
10
|
-
referencedFields,
|
|
11
|
-
refFields: remoteAttributeNames.map((attrName) => buildFieldMeta(remoteCodec ? context.inflectAttr(attrName, remoteCodec) : attrName, remoteAttributes[attrName], context.build)),
|
|
12
|
-
refTable: { name: referencedTable },
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function buildIndexes(codec, attributes, uniques, context) {
|
|
16
|
-
return uniques.map((unique) => ({
|
|
17
|
-
name: unique.tags?.name || `${codec.name}_${unique.attributes.join('_')}_idx`,
|
|
18
|
-
isUnique: true,
|
|
19
|
-
isPrimary: !!unique.isPrimary,
|
|
20
|
-
columns: unique.attributes.map((attrName) => context.inflectAttr(attrName, codec)),
|
|
21
|
-
fields: buildFieldList(unique.attributes, codec, attributes, context),
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
export function buildPrimaryKey(codec, attributes, uniques, context) {
|
|
25
|
-
const primaryUnique = uniques.find((unique) => unique.isPrimary);
|
|
26
|
-
if (!primaryUnique)
|
|
27
|
-
return null;
|
|
28
|
-
return {
|
|
29
|
-
name: primaryUnique.tags?.name || `${codec.name}_pkey`,
|
|
30
|
-
fields: buildFieldList(primaryUnique.attributes, codec, attributes, context),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export function buildUniqueConstraints(codec, attributes, uniques, context) {
|
|
34
|
-
return uniques
|
|
35
|
-
.filter((unique) => !unique.isPrimary)
|
|
36
|
-
.map((unique) => ({
|
|
37
|
-
name: unique.tags?.name || `${codec.name}_${unique.attributes.join('_')}_key`,
|
|
38
|
-
fields: buildFieldList(unique.attributes, codec, attributes, context),
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
export function buildForeignKeyConstraints(codec, attributes, relations, context) {
|
|
42
|
-
const constraints = [];
|
|
43
|
-
for (const [relationName, relation] of Object.entries(relations)) {
|
|
44
|
-
if (relation.isReferencee !== false)
|
|
45
|
-
continue;
|
|
46
|
-
const remoteCodec = relation.remoteResource?.codec;
|
|
47
|
-
const remoteAttributes = remoteCodec?.attributes || {};
|
|
48
|
-
constraints.push(buildForeignKeyConstraint(relationName, codec, attributes, relation.localAttributes || [], remoteCodec, remoteAttributes, relation.remoteAttributes || [], context));
|
|
49
|
-
}
|
|
50
|
-
return constraints;
|
|
51
|
-
}
|