@constructive-io/graphql-query 3.21.2 → 3.22.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.js +1 -1
- package/esm/introspect/infer-tables.js +4 -1
- package/esm/utils.js +26 -0
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/introspect/infer-tables.js +3 -0
- package/package.json +3 -3
- package/types/schema.d.ts +2 -0
- package/utils.d.ts +9 -0
- package/utils.js +27 -0
package/esm/index.js
CHANGED
|
@@ -30,4 +30,4 @@ export * from './client';
|
|
|
30
30
|
// Introspection utilities (infer-tables, transform, transform-schema, schema-query)
|
|
31
31
|
export * from './introspect';
|
|
32
32
|
// Utility functions
|
|
33
|
-
export { stripSmartComments } from './utils';
|
|
33
|
+
export { parseSmartTags, stripSmartComments } from './utils';
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - Mutation operations: create{Name}, update{Name}, delete{Name}
|
|
14
14
|
*/
|
|
15
15
|
import { lcFirst, pluralize, singularize, ucFirst } from 'inflekt';
|
|
16
|
-
import { stripSmartComments } from '../utils';
|
|
16
|
+
import { parseSmartTags, stripSmartComments } from '../utils';
|
|
17
17
|
import { getBaseTypeName, isList, isNonNull, unwrapType } from '../types/introspection';
|
|
18
18
|
// ============================================================================
|
|
19
19
|
// Pattern Matching Constants
|
|
@@ -203,6 +203,8 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
|
|
|
203
203
|
};
|
|
204
204
|
// Extract description from entity type (PostgreSQL COMMENT), strip smart comments
|
|
205
205
|
const description = commentsEnabled ? stripSmartComments(entityType.description) : undefined;
|
|
206
|
+
// Parse smart tags from raw description before they are stripped
|
|
207
|
+
const smartTags = parseSmartTags(entityType.description);
|
|
206
208
|
return {
|
|
207
209
|
table: {
|
|
208
210
|
name: entityName,
|
|
@@ -212,6 +214,7 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
|
|
|
212
214
|
inflection,
|
|
213
215
|
query,
|
|
214
216
|
constraints,
|
|
217
|
+
...(smartTags ? { smartTags } : {}),
|
|
215
218
|
},
|
|
216
219
|
hasRealOperation,
|
|
217
220
|
};
|
package/esm/utils.js
CHANGED
|
@@ -67,3 +67,29 @@ export function stripSmartComments(description, enabled = true) {
|
|
|
67
67
|
return undefined;
|
|
68
68
|
return result;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse PostGraphile smart tags from a description string.
|
|
72
|
+
*
|
|
73
|
+
* Smart tags are lines starting with `@` in PostgreSQL COMMENTs.
|
|
74
|
+
* Each line is parsed as `@tagName` (boolean true) or `@tagName value`.
|
|
75
|
+
*
|
|
76
|
+
* Returns undefined if no smart tags are found.
|
|
77
|
+
*/
|
|
78
|
+
export function parseSmartTags(description) {
|
|
79
|
+
if (!description)
|
|
80
|
+
return undefined;
|
|
81
|
+
const lines = description.split('\n');
|
|
82
|
+
let tags;
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
const trimmed = line.trim();
|
|
85
|
+
if (!trimmed.startsWith('@'))
|
|
86
|
+
continue;
|
|
87
|
+
const spaceIdx = trimmed.indexOf(' ');
|
|
88
|
+
const tagName = spaceIdx === -1 ? trimmed : trimmed.slice(0, spaceIdx);
|
|
89
|
+
const tagValue = spaceIdx === -1 ? true : trimmed.slice(spaceIdx + 1).trim();
|
|
90
|
+
if (!tags)
|
|
91
|
+
tags = {};
|
|
92
|
+
tags[tagName] = tagValue || true;
|
|
93
|
+
}
|
|
94
|
+
return tags;
|
|
95
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -20,4 +20,4 @@ export { validateMetaObject, type ValidationResult } from './meta-object/validat
|
|
|
20
20
|
export * from './generators';
|
|
21
21
|
export * from './client';
|
|
22
22
|
export * from './introspect';
|
|
23
|
-
export { stripSmartComments } from './utils';
|
|
23
|
+
export { parseSmartTags, stripSmartComments } from './utils';
|
package/index.js
CHANGED
|
@@ -47,7 +47,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
47
|
};
|
|
48
48
|
})();
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.stripSmartComments = exports.validateMetaObject = exports.convertFromMetaSchema = exports.MetaObject = exports.createExecutor = exports.QueryExecutor = exports.QueryBuilder = void 0;
|
|
50
|
+
exports.stripSmartComments = exports.parseSmartTags = exports.validateMetaObject = exports.convertFromMetaSchema = exports.MetaObject = exports.createExecutor = exports.QueryExecutor = exports.QueryBuilder = void 0;
|
|
51
51
|
// QueryBuilder class (runtime query builder)
|
|
52
52
|
var query_builder_1 = require("./query-builder");
|
|
53
53
|
Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return query_builder_1.QueryBuilder; } });
|
|
@@ -75,4 +75,5 @@ __exportStar(require("./client"), exports);
|
|
|
75
75
|
__exportStar(require("./introspect"), exports);
|
|
76
76
|
// Utility functions
|
|
77
77
|
var utils_1 = require("./utils");
|
|
78
|
+
Object.defineProperty(exports, "parseSmartTags", { enumerable: true, get: function () { return utils_1.parseSmartTags; } });
|
|
78
79
|
Object.defineProperty(exports, "stripSmartComments", { enumerable: true, get: function () { return utils_1.stripSmartComments; } });
|
|
@@ -206,6 +206,8 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
|
|
|
206
206
|
};
|
|
207
207
|
// Extract description from entity type (PostgreSQL COMMENT), strip smart comments
|
|
208
208
|
const description = commentsEnabled ? (0, utils_1.stripSmartComments)(entityType.description) : undefined;
|
|
209
|
+
// Parse smart tags from raw description before they are stripped
|
|
210
|
+
const smartTags = (0, utils_1.parseSmartTags)(entityType.description);
|
|
209
211
|
return {
|
|
210
212
|
table: {
|
|
211
213
|
name: entityName,
|
|
@@ -215,6 +217,7 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
|
|
|
215
217
|
inflection,
|
|
216
218
|
query,
|
|
217
219
|
constraints,
|
|
220
|
+
...(smartTags ? { smartTags } : {}),
|
|
218
221
|
},
|
|
219
222
|
hasRealOperation,
|
|
220
223
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-query",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "Constructive GraphQL Query",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"grafast": "1.0.0",
|
|
37
37
|
"graphile-build-pg": "5.0.0",
|
|
38
38
|
"graphile-config": "1.0.0",
|
|
39
|
-
"graphile-settings": "^4.31.
|
|
39
|
+
"graphile-settings": "^4.31.1",
|
|
40
40
|
"graphql": "16.13.0",
|
|
41
41
|
"inflection": "^3.0.0",
|
|
42
42
|
"inflekt": "^0.7.1",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"makage": "^0.3.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "90016935b53d6fb84e0b83879377f0c2eb9abce6"
|
|
57
57
|
}
|
package/types/schema.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface Table {
|
|
|
17
17
|
query?: TableQueryNames;
|
|
18
18
|
/** Constraint information */
|
|
19
19
|
constraints?: TableConstraints;
|
|
20
|
+
/** Smart tags parsed from PostGraphile @-prefixed comment directives */
|
|
21
|
+
smartTags?: Record<string, string | true>;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* PostGraphile-generated names for this table
|
package/utils.d.ts
CHANGED
|
@@ -15,3 +15,12 @@
|
|
|
15
15
|
* @returns Cleaned description, or undefined if empty/boilerplate
|
|
16
16
|
*/
|
|
17
17
|
export declare function stripSmartComments(description: string | null | undefined, enabled?: boolean): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Parse PostGraphile smart tags from a description string.
|
|
20
|
+
*
|
|
21
|
+
* Smart tags are lines starting with `@` in PostgreSQL COMMENTs.
|
|
22
|
+
* Each line is parsed as `@tagName` (boolean true) or `@tagName value`.
|
|
23
|
+
*
|
|
24
|
+
* Returns undefined if no smart tags are found.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseSmartTags(description: string | null | undefined): Record<string, string | true> | undefined;
|
package/utils.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.stripSmartComments = stripSmartComments;
|
|
7
|
+
exports.parseSmartTags = parseSmartTags;
|
|
7
8
|
/**
|
|
8
9
|
* PostGraphile boilerplate description prefixes that should be suppressed
|
|
9
10
|
*/
|
|
@@ -70,3 +71,29 @@ function stripSmartComments(description, enabled = true) {
|
|
|
70
71
|
return undefined;
|
|
71
72
|
return result;
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Parse PostGraphile smart tags from a description string.
|
|
76
|
+
*
|
|
77
|
+
* Smart tags are lines starting with `@` in PostgreSQL COMMENTs.
|
|
78
|
+
* Each line is parsed as `@tagName` (boolean true) or `@tagName value`.
|
|
79
|
+
*
|
|
80
|
+
* Returns undefined if no smart tags are found.
|
|
81
|
+
*/
|
|
82
|
+
function parseSmartTags(description) {
|
|
83
|
+
if (!description)
|
|
84
|
+
return undefined;
|
|
85
|
+
const lines = description.split('\n');
|
|
86
|
+
let tags;
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const trimmed = line.trim();
|
|
89
|
+
if (!trimmed.startsWith('@'))
|
|
90
|
+
continue;
|
|
91
|
+
const spaceIdx = trimmed.indexOf(' ');
|
|
92
|
+
const tagName = spaceIdx === -1 ? trimmed : trimmed.slice(0, spaceIdx);
|
|
93
|
+
const tagValue = spaceIdx === -1 ? true : trimmed.slice(spaceIdx + 1).trim();
|
|
94
|
+
if (!tags)
|
|
95
|
+
tags = {};
|
|
96
|
+
tags[tagName] = tagValue || true;
|
|
97
|
+
}
|
|
98
|
+
return tags;
|
|
99
|
+
}
|