@constructive-io/graphql-codegen 3.2.1 → 3.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/cli/index.js +36 -43
- package/cli/shared.d.ts +15 -19
- package/cli/shared.js +104 -25
- package/client/error.js +31 -9
- package/client/execute.js +2 -2
- package/client/index.d.ts +3 -3
- package/client/index.js +6 -6
- package/core/ast.d.ts +1 -1
- package/core/ast.js +1 -1
- package/core/codegen/babel-ast.d.ts +1 -1
- package/core/codegen/babel-ast.js +2 -2
- package/core/codegen/barrel.d.ts +0 -6
- package/core/codegen/barrel.js +22 -19
- package/core/codegen/client.d.ts +2 -12
- package/core/codegen/client.js +7 -21
- package/core/codegen/custom-mutations.d.ts +0 -14
- package/core/codegen/custom-mutations.js +139 -88
- package/core/codegen/custom-queries.d.ts +0 -14
- package/core/codegen/custom-queries.js +483 -193
- package/core/codegen/hooks-ast.d.ts +75 -0
- package/core/codegen/hooks-ast.js +522 -0
- package/core/codegen/index.d.ts +16 -18
- package/core/codegen/index.js +42 -88
- package/core/codegen/invalidation.d.ts +1 -7
- package/core/codegen/invalidation.js +50 -16
- package/core/codegen/mutation-keys.d.ts +1 -10
- package/core/codegen/mutation-keys.js +22 -8
- package/core/codegen/mutations.d.ts +0 -13
- package/core/codegen/mutations.js +301 -366
- package/core/codegen/orm/barrel.d.ts +0 -5
- package/core/codegen/orm/barrel.js +5 -0
- package/core/codegen/orm/client-generator.d.ts +0 -5
- package/core/codegen/orm/client-generator.js +7 -2
- package/core/codegen/orm/client.js +3 -1
- package/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/core/codegen/orm/custom-ops-generator.js +104 -51
- package/core/codegen/orm/index.d.ts +4 -4
- package/core/codegen/orm/index.js +28 -15
- package/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/core/codegen/orm/input-types-generator.js +85 -23
- package/core/codegen/orm/model-generator.d.ts +0 -5
- package/core/codegen/orm/model-generator.js +309 -131
- package/core/codegen/orm/select-types.d.ts +19 -14
- package/core/codegen/queries.d.ts +0 -8
- package/core/codegen/queries.js +360 -559
- package/core/codegen/query-keys.d.ts +1 -1
- package/core/codegen/query-keys.js +37 -23
- package/core/codegen/scalars.js +3 -1
- package/core/codegen/schema-types-generator.d.ts +1 -1
- package/core/codegen/schema-types-generator.js +17 -2
- package/core/codegen/select-helpers.d.ts +19 -0
- package/core/codegen/select-helpers.js +40 -0
- package/core/codegen/selection.d.ts +4 -0
- package/core/codegen/selection.js +65 -0
- package/core/codegen/shared/index.d.ts +2 -15
- package/core/codegen/shared/index.js +17 -4
- package/core/codegen/templates/hooks-client.ts +49 -0
- package/core/codegen/templates/hooks-selection.ts +58 -0
- package/core/codegen/templates/orm-client.ts +8 -6
- package/core/codegen/templates/query-builder.ts +250 -46
- package/core/codegen/templates/select-types.ts +31 -14
- package/core/codegen/type-resolver.d.ts +1 -5
- package/core/codegen/type-resolver.js +0 -22
- package/core/codegen/types.d.ts +0 -3
- package/core/codegen/types.js +71 -14
- package/core/codegen/utils.d.ts +1 -4
- package/core/codegen/utils.js +4 -1
- package/core/config/index.d.ts +1 -1
- package/core/config/resolver.js +1 -3
- package/core/generate.js +38 -50
- package/core/index.d.ts +3 -3
- package/core/index.js +3 -4
- package/core/introspect/index.d.ts +6 -6
- package/core/introspect/index.js +5 -8
- package/core/introspect/infer-tables.d.ts +0 -14
- package/core/introspect/infer-tables.js +15 -1
- package/core/introspect/source/database.js +1 -1
- package/core/introspect/source/endpoint.d.ts +0 -6
- package/core/introspect/source/endpoint.js +7 -1
- package/core/introspect/source/index.d.ts +4 -4
- package/core/introspect/source/index.js +5 -9
- package/core/introspect/source/pgpm-module.js +3 -3
- package/core/introspect/transform-schema.d.ts +2 -2
- package/core/introspect/transform-schema.js +2 -2
- package/core/output/index.d.ts +1 -1
- package/core/output/index.js +2 -2
- package/core/output/writer.d.ts +3 -0
- package/core/output/writer.js +20 -1
- package/core/pipeline/index.d.ts +2 -2
- package/core/query-builder.d.ts +2 -2
- package/core/query-builder.js +1 -1
- package/core/watch/index.d.ts +4 -4
- package/core/watch/index.js +9 -9
- package/core/watch/orchestrator.js +5 -3
- package/esm/cli/index.js +37 -44
- package/esm/cli/shared.d.ts +15 -19
- package/esm/cli/shared.js +94 -23
- package/esm/client/error.js +31 -9
- package/esm/client/execute.js +2 -2
- package/esm/client/index.d.ts +3 -3
- package/esm/client/index.js +3 -3
- package/esm/core/ast.d.ts +1 -1
- package/esm/core/ast.js +1 -1
- package/esm/core/codegen/babel-ast.d.ts +1 -1
- package/esm/core/codegen/babel-ast.js +2 -2
- package/esm/core/codegen/barrel.d.ts +0 -6
- package/esm/core/codegen/barrel.js +23 -20
- package/esm/core/codegen/client.d.ts +2 -12
- package/esm/core/codegen/client.js +7 -21
- package/esm/core/codegen/custom-mutations.d.ts +0 -14
- package/esm/core/codegen/custom-mutations.js +141 -90
- package/esm/core/codegen/custom-queries.d.ts +0 -14
- package/esm/core/codegen/custom-queries.js +486 -196
- package/esm/core/codegen/hooks-ast.d.ts +75 -0
- package/esm/core/codegen/hooks-ast.js +424 -0
- package/esm/core/codegen/index.d.ts +16 -18
- package/esm/core/codegen/index.js +26 -71
- package/esm/core/codegen/invalidation.d.ts +1 -7
- package/esm/core/codegen/invalidation.js +51 -17
- package/esm/core/codegen/mutation-keys.d.ts +1 -10
- package/esm/core/codegen/mutation-keys.js +23 -9
- package/esm/core/codegen/mutations.d.ts +0 -13
- package/esm/core/codegen/mutations.js +302 -367
- package/esm/core/codegen/orm/barrel.d.ts +0 -5
- package/esm/core/codegen/orm/barrel.js +6 -1
- package/esm/core/codegen/orm/client-generator.d.ts +0 -5
- package/esm/core/codegen/orm/client-generator.js +7 -2
- package/esm/core/codegen/orm/client.js +3 -1
- package/esm/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/esm/core/codegen/orm/custom-ops-generator.js +103 -50
- package/esm/core/codegen/orm/index.d.ts +4 -4
- package/esm/core/codegen/orm/index.js +25 -12
- package/esm/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/esm/core/codegen/orm/input-types-generator.js +85 -23
- package/esm/core/codegen/orm/model-generator.d.ts +0 -5
- package/esm/core/codegen/orm/model-generator.js +310 -132
- package/esm/core/codegen/orm/select-types.d.ts +19 -14
- package/esm/core/codegen/queries.d.ts +0 -8
- package/esm/core/codegen/queries.js +362 -561
- package/esm/core/codegen/query-keys.d.ts +1 -1
- package/esm/core/codegen/query-keys.js +38 -24
- package/esm/core/codegen/scalars.js +3 -1
- package/esm/core/codegen/schema-types-generator.d.ts +1 -1
- package/esm/core/codegen/schema-types-generator.js +17 -2
- package/esm/core/codegen/select-helpers.d.ts +19 -0
- package/esm/core/codegen/select-helpers.js +35 -0
- package/esm/core/codegen/selection.d.ts +4 -0
- package/esm/core/codegen/selection.js +29 -0
- package/esm/core/codegen/shared/index.d.ts +2 -15
- package/esm/core/codegen/shared/index.js +16 -3
- package/esm/core/codegen/type-resolver.d.ts +1 -5
- package/esm/core/codegen/type-resolver.js +1 -22
- package/esm/core/codegen/types.d.ts +0 -3
- package/esm/core/codegen/types.js +72 -15
- package/esm/core/codegen/utils.d.ts +1 -4
- package/esm/core/codegen/utils.js +4 -1
- package/esm/core/config/index.d.ts +1 -1
- package/esm/core/config/resolver.js +2 -4
- package/esm/core/generate.js +38 -50
- package/esm/core/index.d.ts +3 -3
- package/esm/core/index.js +2 -3
- package/esm/core/introspect/index.d.ts +6 -6
- package/esm/core/introspect/index.js +3 -6
- package/esm/core/introspect/infer-tables.d.ts +0 -14
- package/esm/core/introspect/infer-tables.js +16 -2
- package/esm/core/introspect/source/database.js +2 -2
- package/esm/core/introspect/source/endpoint.d.ts +0 -6
- package/esm/core/introspect/source/endpoint.js +7 -1
- package/esm/core/introspect/source/index.d.ts +4 -4
- package/esm/core/introspect/source/index.js +6 -10
- package/esm/core/introspect/source/pgpm-module.js +3 -3
- package/esm/core/introspect/transform-schema.d.ts +2 -2
- package/esm/core/introspect/transform-schema.js +2 -2
- package/esm/core/output/index.d.ts +1 -1
- package/esm/core/output/index.js +1 -1
- package/esm/core/output/writer.d.ts +3 -0
- package/esm/core/output/writer.js +20 -1
- package/esm/core/pipeline/index.d.ts +2 -2
- package/esm/core/pipeline/index.js +2 -2
- package/esm/core/query-builder.d.ts +2 -2
- package/esm/core/query-builder.js +2 -2
- package/esm/core/watch/index.d.ts +4 -4
- package/esm/core/watch/index.js +3 -3
- package/esm/core/watch/orchestrator.js +5 -3
- package/esm/generators/index.d.ts +3 -3
- package/esm/generators/index.js +3 -3
- package/esm/generators/mutations.d.ts +1 -1
- package/esm/generators/select.d.ts +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js +1 -4
- package/esm/types/config.d.ts +0 -10
- package/esm/types/config.js +0 -2
- package/esm/types/index.d.ts +6 -6
- package/esm/types/index.js +1 -1
- package/generators/index.d.ts +3 -3
- package/generators/index.js +8 -8
- package/generators/mutations.d.ts +1 -1
- package/generators/select.d.ts +1 -1
- package/index.d.ts +3 -3
- package/index.js +11 -6
- package/package.json +10 -10
- package/types/config.d.ts +0 -10
- package/types/config.js +0 -2
- package/types/index.d.ts +6 -6
- package/types/index.js +2 -2
- package/core/codegen/gql-ast.d.ts +0 -41
- package/core/codegen/gql-ast.js +0 -353
- package/core/codegen/schema-gql-ast.d.ts +0 -51
- package/core/codegen/schema-gql-ast.js +0 -385
- package/core/codegen/templates/client.browser.ts +0 -271
- package/core/codegen/templates/client.node.ts +0 -337
- package/esm/core/codegen/gql-ast.d.ts +0 -41
- package/esm/core/codegen/gql-ast.js +0 -312
- package/esm/core/codegen/schema-gql-ast.d.ts +0 -51
- package/esm/core/codegen/schema-gql-ast.js +0 -343
package/core/codegen/gql-ast.js
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.buildListQueryAST = buildListQueryAST;
|
|
37
|
-
exports.buildSingleQueryAST = buildSingleQueryAST;
|
|
38
|
-
exports.buildCreateMutationAST = buildCreateMutationAST;
|
|
39
|
-
exports.buildUpdateMutationAST = buildUpdateMutationAST;
|
|
40
|
-
exports.buildDeleteMutationAST = buildDeleteMutationAST;
|
|
41
|
-
exports.printGraphQL = printGraphQL;
|
|
42
|
-
/**
|
|
43
|
-
* GraphQL AST builders using gql-ast
|
|
44
|
-
*
|
|
45
|
-
* Provides utilities for generating GraphQL queries and mutations via AST
|
|
46
|
-
* instead of string concatenation.
|
|
47
|
-
*/
|
|
48
|
-
const t = __importStar(require("gql-ast"));
|
|
49
|
-
const graphql_1 = require("graphql");
|
|
50
|
-
const utils_1 = require("./utils");
|
|
51
|
-
// ============================================================================
|
|
52
|
-
// Field selection builders
|
|
53
|
-
// ============================================================================
|
|
54
|
-
/**
|
|
55
|
-
* Create field selections from CleanField array
|
|
56
|
-
*/
|
|
57
|
-
function createFieldSelections(fields) {
|
|
58
|
-
return fields.map((field) => t.field({ name: field.name }));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Create pageInfo selection
|
|
62
|
-
*/
|
|
63
|
-
function createPageInfoSelection() {
|
|
64
|
-
return t.field({
|
|
65
|
-
name: 'pageInfo',
|
|
66
|
-
selectionSet: t.selectionSet({
|
|
67
|
-
selections: [
|
|
68
|
-
t.field({ name: 'hasNextPage' }),
|
|
69
|
-
t.field({ name: 'hasPreviousPage' }),
|
|
70
|
-
t.field({ name: 'startCursor' }),
|
|
71
|
-
t.field({ name: 'endCursor' }),
|
|
72
|
-
],
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Build a list query AST for a table
|
|
78
|
-
*/
|
|
79
|
-
function buildListQueryAST(config) {
|
|
80
|
-
const { table } = config;
|
|
81
|
-
const queryName = (0, utils_1.getAllRowsQueryName)(table);
|
|
82
|
-
const filterType = (0, utils_1.getFilterTypeName)(table);
|
|
83
|
-
const conditionType = (0, utils_1.getConditionTypeName)(table);
|
|
84
|
-
const orderByType = (0, utils_1.getOrderByTypeName)(table);
|
|
85
|
-
const scalarFields = (0, utils_1.getScalarFields)(table);
|
|
86
|
-
// Variable definitions - all pagination arguments from PostGraphile
|
|
87
|
-
const variableDefinitions = [
|
|
88
|
-
t.variableDefinition({
|
|
89
|
-
variable: t.variable({ name: 'first' }),
|
|
90
|
-
type: t.namedType({ type: 'Int' }),
|
|
91
|
-
}),
|
|
92
|
-
t.variableDefinition({
|
|
93
|
-
variable: t.variable({ name: 'last' }),
|
|
94
|
-
type: t.namedType({ type: 'Int' }),
|
|
95
|
-
}),
|
|
96
|
-
t.variableDefinition({
|
|
97
|
-
variable: t.variable({ name: 'offset' }),
|
|
98
|
-
type: t.namedType({ type: 'Int' }),
|
|
99
|
-
}),
|
|
100
|
-
t.variableDefinition({
|
|
101
|
-
variable: t.variable({ name: 'before' }),
|
|
102
|
-
type: t.namedType({ type: 'Cursor' }),
|
|
103
|
-
}),
|
|
104
|
-
t.variableDefinition({
|
|
105
|
-
variable: t.variable({ name: 'after' }),
|
|
106
|
-
type: t.namedType({ type: 'Cursor' }),
|
|
107
|
-
}),
|
|
108
|
-
t.variableDefinition({
|
|
109
|
-
variable: t.variable({ name: 'filter' }),
|
|
110
|
-
type: t.namedType({ type: filterType }),
|
|
111
|
-
}),
|
|
112
|
-
t.variableDefinition({
|
|
113
|
-
variable: t.variable({ name: 'condition' }),
|
|
114
|
-
type: t.namedType({ type: conditionType }),
|
|
115
|
-
}),
|
|
116
|
-
t.variableDefinition({
|
|
117
|
-
variable: t.variable({ name: 'orderBy' }),
|
|
118
|
-
type: t.listType({
|
|
119
|
-
type: t.nonNullType({ type: t.namedType({ type: orderByType }) }),
|
|
120
|
-
}),
|
|
121
|
-
}),
|
|
122
|
-
];
|
|
123
|
-
// Query arguments
|
|
124
|
-
const args = [
|
|
125
|
-
t.argument({ name: 'first', value: t.variable({ name: 'first' }) }),
|
|
126
|
-
t.argument({ name: 'last', value: t.variable({ name: 'last' }) }),
|
|
127
|
-
t.argument({ name: 'offset', value: t.variable({ name: 'offset' }) }),
|
|
128
|
-
t.argument({ name: 'before', value: t.variable({ name: 'before' }) }),
|
|
129
|
-
t.argument({ name: 'after', value: t.variable({ name: 'after' }) }),
|
|
130
|
-
t.argument({ name: 'filter', value: t.variable({ name: 'filter' }) }),
|
|
131
|
-
t.argument({ name: 'condition', value: t.variable({ name: 'condition' }) }),
|
|
132
|
-
t.argument({ name: 'orderBy', value: t.variable({ name: 'orderBy' }) }),
|
|
133
|
-
];
|
|
134
|
-
// Field selections
|
|
135
|
-
const fieldSelections = createFieldSelections(scalarFields);
|
|
136
|
-
// Connection fields
|
|
137
|
-
const connectionFields = [
|
|
138
|
-
t.field({ name: 'totalCount' }),
|
|
139
|
-
t.field({
|
|
140
|
-
name: 'nodes',
|
|
141
|
-
selectionSet: t.selectionSet({ selections: fieldSelections }),
|
|
142
|
-
}),
|
|
143
|
-
createPageInfoSelection(),
|
|
144
|
-
];
|
|
145
|
-
return t.document({
|
|
146
|
-
definitions: [
|
|
147
|
-
t.operationDefinition({
|
|
148
|
-
operation: 'query',
|
|
149
|
-
name: `${(0, utils_1.ucFirst)(queryName)}Query`,
|
|
150
|
-
variableDefinitions,
|
|
151
|
-
selectionSet: t.selectionSet({
|
|
152
|
-
selections: [
|
|
153
|
-
t.field({
|
|
154
|
-
name: queryName,
|
|
155
|
-
args,
|
|
156
|
-
selectionSet: t.selectionSet({ selections: connectionFields }),
|
|
157
|
-
}),
|
|
158
|
-
],
|
|
159
|
-
}),
|
|
160
|
-
}),
|
|
161
|
-
],
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Build a single item query AST for a table
|
|
166
|
-
*/
|
|
167
|
-
function buildSingleQueryAST(config) {
|
|
168
|
-
const { table } = config;
|
|
169
|
-
const queryName = (0, utils_1.getSingleRowQueryName)(table);
|
|
170
|
-
const scalarFields = (0, utils_1.getScalarFields)(table);
|
|
171
|
-
// Get primary key info dynamically from table constraints
|
|
172
|
-
const pkFields = (0, utils_1.getPrimaryKeyInfo)(table);
|
|
173
|
-
// For simplicity, use first PK field (most common case)
|
|
174
|
-
const pkField = pkFields[0];
|
|
175
|
-
// Variable definitions - use dynamic PK field name and type
|
|
176
|
-
const variableDefinitions = [
|
|
177
|
-
t.variableDefinition({
|
|
178
|
-
variable: t.variable({ name: pkField.name }),
|
|
179
|
-
type: t.nonNullType({ type: t.namedType({ type: pkField.gqlType }) }),
|
|
180
|
-
}),
|
|
181
|
-
];
|
|
182
|
-
// Query arguments - use dynamic PK field name
|
|
183
|
-
const args = [
|
|
184
|
-
t.argument({ name: pkField.name, value: t.variable({ name: pkField.name }) }),
|
|
185
|
-
];
|
|
186
|
-
// Field selections
|
|
187
|
-
const fieldSelections = createFieldSelections(scalarFields);
|
|
188
|
-
return t.document({
|
|
189
|
-
definitions: [
|
|
190
|
-
t.operationDefinition({
|
|
191
|
-
operation: 'query',
|
|
192
|
-
name: `${(0, utils_1.ucFirst)(queryName)}Query`,
|
|
193
|
-
variableDefinitions,
|
|
194
|
-
selectionSet: t.selectionSet({
|
|
195
|
-
selections: [
|
|
196
|
-
t.field({
|
|
197
|
-
name: queryName,
|
|
198
|
-
args,
|
|
199
|
-
selectionSet: t.selectionSet({ selections: fieldSelections }),
|
|
200
|
-
}),
|
|
201
|
-
],
|
|
202
|
-
}),
|
|
203
|
-
}),
|
|
204
|
-
],
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Build a create mutation AST for a table
|
|
209
|
-
*/
|
|
210
|
-
function buildCreateMutationAST(config) {
|
|
211
|
-
const { table } = config;
|
|
212
|
-
const { typeName, singularName } = (0, utils_1.getTableNames)(table);
|
|
213
|
-
const mutationName = (0, utils_1.getCreateMutationName)(table);
|
|
214
|
-
const inputTypeName = `Create${typeName}Input`;
|
|
215
|
-
const scalarFields = (0, utils_1.getScalarFields)(table);
|
|
216
|
-
// Variable definitions
|
|
217
|
-
const variableDefinitions = [
|
|
218
|
-
t.variableDefinition({
|
|
219
|
-
variable: t.variable({ name: 'input' }),
|
|
220
|
-
type: t.nonNullType({ type: t.namedType({ type: inputTypeName }) }),
|
|
221
|
-
}),
|
|
222
|
-
];
|
|
223
|
-
// Mutation arguments
|
|
224
|
-
const args = [
|
|
225
|
-
t.argument({ name: 'input', value: t.variable({ name: 'input' }) }),
|
|
226
|
-
];
|
|
227
|
-
// Field selections
|
|
228
|
-
const fieldSelections = createFieldSelections(scalarFields);
|
|
229
|
-
return t.document({
|
|
230
|
-
definitions: [
|
|
231
|
-
t.operationDefinition({
|
|
232
|
-
operation: 'mutation',
|
|
233
|
-
name: `${(0, utils_1.ucFirst)(mutationName)}Mutation`,
|
|
234
|
-
variableDefinitions,
|
|
235
|
-
selectionSet: t.selectionSet({
|
|
236
|
-
selections: [
|
|
237
|
-
t.field({
|
|
238
|
-
name: mutationName,
|
|
239
|
-
args,
|
|
240
|
-
selectionSet: t.selectionSet({
|
|
241
|
-
selections: [
|
|
242
|
-
t.field({
|
|
243
|
-
name: singularName,
|
|
244
|
-
selectionSet: t.selectionSet({ selections: fieldSelections }),
|
|
245
|
-
}),
|
|
246
|
-
],
|
|
247
|
-
}),
|
|
248
|
-
}),
|
|
249
|
-
],
|
|
250
|
-
}),
|
|
251
|
-
}),
|
|
252
|
-
],
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Build an update mutation AST for a table
|
|
257
|
-
*/
|
|
258
|
-
function buildUpdateMutationAST(config) {
|
|
259
|
-
const { table } = config;
|
|
260
|
-
const { typeName, singularName } = (0, utils_1.getTableNames)(table);
|
|
261
|
-
const mutationName = (0, utils_1.getUpdateMutationName)(table);
|
|
262
|
-
const inputTypeName = `Update${typeName}Input`;
|
|
263
|
-
const scalarFields = (0, utils_1.getScalarFields)(table);
|
|
264
|
-
// Variable definitions
|
|
265
|
-
const variableDefinitions = [
|
|
266
|
-
t.variableDefinition({
|
|
267
|
-
variable: t.variable({ name: 'input' }),
|
|
268
|
-
type: t.nonNullType({ type: t.namedType({ type: inputTypeName }) }),
|
|
269
|
-
}),
|
|
270
|
-
];
|
|
271
|
-
// Mutation arguments
|
|
272
|
-
const args = [
|
|
273
|
-
t.argument({ name: 'input', value: t.variable({ name: 'input' }) }),
|
|
274
|
-
];
|
|
275
|
-
// Field selections
|
|
276
|
-
const fieldSelections = createFieldSelections(scalarFields);
|
|
277
|
-
return t.document({
|
|
278
|
-
definitions: [
|
|
279
|
-
t.operationDefinition({
|
|
280
|
-
operation: 'mutation',
|
|
281
|
-
name: `${(0, utils_1.ucFirst)(mutationName)}Mutation`,
|
|
282
|
-
variableDefinitions,
|
|
283
|
-
selectionSet: t.selectionSet({
|
|
284
|
-
selections: [
|
|
285
|
-
t.field({
|
|
286
|
-
name: mutationName,
|
|
287
|
-
args,
|
|
288
|
-
selectionSet: t.selectionSet({
|
|
289
|
-
selections: [
|
|
290
|
-
t.field({
|
|
291
|
-
name: singularName,
|
|
292
|
-
selectionSet: t.selectionSet({ selections: fieldSelections }),
|
|
293
|
-
}),
|
|
294
|
-
],
|
|
295
|
-
}),
|
|
296
|
-
}),
|
|
297
|
-
],
|
|
298
|
-
}),
|
|
299
|
-
}),
|
|
300
|
-
],
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Build a delete mutation AST for a table
|
|
305
|
-
*/
|
|
306
|
-
function buildDeleteMutationAST(config) {
|
|
307
|
-
const { table } = config;
|
|
308
|
-
const { typeName } = (0, utils_1.getTableNames)(table);
|
|
309
|
-
const mutationName = (0, utils_1.getDeleteMutationName)(table);
|
|
310
|
-
const inputTypeName = `Delete${typeName}Input`;
|
|
311
|
-
// Variable definitions
|
|
312
|
-
const variableDefinitions = [
|
|
313
|
-
t.variableDefinition({
|
|
314
|
-
variable: t.variable({ name: 'input' }),
|
|
315
|
-
type: t.nonNullType({ type: t.namedType({ type: inputTypeName }) }),
|
|
316
|
-
}),
|
|
317
|
-
];
|
|
318
|
-
// Mutation arguments
|
|
319
|
-
const args = [
|
|
320
|
-
t.argument({ name: 'input', value: t.variable({ name: 'input' }) }),
|
|
321
|
-
];
|
|
322
|
-
return t.document({
|
|
323
|
-
definitions: [
|
|
324
|
-
t.operationDefinition({
|
|
325
|
-
operation: 'mutation',
|
|
326
|
-
name: `${(0, utils_1.ucFirst)(mutationName)}Mutation`,
|
|
327
|
-
variableDefinitions,
|
|
328
|
-
selectionSet: t.selectionSet({
|
|
329
|
-
selections: [
|
|
330
|
-
t.field({
|
|
331
|
-
name: mutationName,
|
|
332
|
-
args,
|
|
333
|
-
selectionSet: t.selectionSet({
|
|
334
|
-
selections: [
|
|
335
|
-
t.field({ name: 'clientMutationId' }),
|
|
336
|
-
],
|
|
337
|
-
}),
|
|
338
|
-
}),
|
|
339
|
-
],
|
|
340
|
-
}),
|
|
341
|
-
}),
|
|
342
|
-
],
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
// ============================================================================
|
|
346
|
-
// Print utilities
|
|
347
|
-
// ============================================================================
|
|
348
|
-
/**
|
|
349
|
-
* Print AST to GraphQL string
|
|
350
|
-
*/
|
|
351
|
-
function printGraphQL(ast) {
|
|
352
|
-
return (0, graphql_1.print)(ast);
|
|
353
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { DocumentNode, FieldNode, VariableDefinitionNode } from 'graphql';
|
|
2
|
-
import type { CleanOperation, CleanArgument, CleanTypeRef, TypeRegistry } from '../../types/schema';
|
|
3
|
-
export interface FieldSelectionConfig {
|
|
4
|
-
/** Max depth for nested object selections */
|
|
5
|
-
maxDepth: number;
|
|
6
|
-
/** Skip the 'query' field in payloads */
|
|
7
|
-
skipQueryField: boolean;
|
|
8
|
-
/** Type registry for resolving nested types */
|
|
9
|
-
typeRegistry?: TypeRegistry;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Build variable definitions from operation arguments
|
|
13
|
-
*/
|
|
14
|
-
export declare function buildVariableDefinitions(args: CleanArgument[]): VariableDefinitionNode[];
|
|
15
|
-
/**
|
|
16
|
-
* Build field selections for an object type
|
|
17
|
-
* Recursively handles nested objects up to maxDepth
|
|
18
|
-
*/
|
|
19
|
-
export declare function buildFieldSelections(typeRef: CleanTypeRef, config: FieldSelectionConfig, currentDepth?: number): FieldNode[];
|
|
20
|
-
export interface CustomQueryConfig {
|
|
21
|
-
operation: CleanOperation;
|
|
22
|
-
typeRegistry?: TypeRegistry;
|
|
23
|
-
maxDepth?: number;
|
|
24
|
-
skipQueryField?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Build a custom query AST from a CleanOperation
|
|
28
|
-
*/
|
|
29
|
-
export declare function buildCustomQueryAST(config: CustomQueryConfig): DocumentNode;
|
|
30
|
-
export interface CustomMutationConfig {
|
|
31
|
-
operation: CleanOperation;
|
|
32
|
-
typeRegistry?: TypeRegistry;
|
|
33
|
-
maxDepth?: number;
|
|
34
|
-
skipQueryField?: boolean;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Build a custom mutation AST from a CleanOperation
|
|
38
|
-
*/
|
|
39
|
-
export declare function buildCustomMutationAST(config: CustomMutationConfig): DocumentNode;
|
|
40
|
-
/**
|
|
41
|
-
* Print a document AST to GraphQL string
|
|
42
|
-
*/
|
|
43
|
-
export declare function printGraphQL(ast: DocumentNode): string;
|
|
44
|
-
/**
|
|
45
|
-
* Build and print a custom query in one call
|
|
46
|
-
*/
|
|
47
|
-
export declare function buildCustomQueryString(config: CustomQueryConfig): string;
|
|
48
|
-
/**
|
|
49
|
-
* Build and print a custom mutation in one call
|
|
50
|
-
*/
|
|
51
|
-
export declare function buildCustomMutationString(config: CustomMutationConfig): string;
|