@constructive-io/graphql-server 2.19.2 → 2.19.3
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/codegen/orm/index.d.ts +7 -603
- package/codegen/orm/index.js +4 -127
- package/codegen/orm/input-types.d.ts +14682 -7790
- package/codegen/orm/input-types.js +0 -5
- package/codegen/orm/models/api.d.ts +6 -6
- package/codegen/orm/models/api.js +3 -4
- package/codegen/orm/models/domain.d.ts +6 -6
- package/codegen/orm/models/domain.js +3 -4
- package/codegen/orm/models/index.d.ts +1 -58
- package/codegen/orm/models/index.js +3 -118
- package/codegen/orm/mutation/index.d.ts +1 -525
- package/codegen/orm/mutation/index.js +2 -591
- package/codegen/orm/query/index.d.ts +3 -257
- package/codegen/orm/query/index.js +8 -274
- package/codegen/orm/query-builder.d.ts +2 -1
- package/codegen/orm/query-builder.js +376 -129
- package/codegen/orm/select-types.d.ts +33 -0
- package/esm/codegen/orm/index.js +4 -127
- package/esm/codegen/orm/input-types.js +0 -5
- package/esm/codegen/orm/models/api.js +3 -4
- package/esm/codegen/orm/models/domain.js +3 -4
- package/esm/codegen/orm/models/index.js +1 -58
- package/esm/codegen/orm/mutation/index.js +2 -591
- package/esm/codegen/orm/query/index.js +8 -274
- package/esm/codegen/orm/query-builder.js +343 -129
- package/esm/middleware/api.js +145 -173
- package/esm/middleware/gql.js +72 -71
- package/middleware/api.d.ts +16 -3
- package/middleware/api.js +148 -173
- package/middleware/gql.d.ts +174 -24
- package/middleware/gql.js +76 -76
- package/middleware/types.d.ts +3 -19
- package/package.json +7 -4
- package/types.d.ts +17 -44
- package/codegen/orm/models/apiExtension.d.ts +0 -42
- package/codegen/orm/models/apiExtension.js +0 -77
- package/codegen/orm/models/apiModule.d.ts +0 -42
- package/codegen/orm/models/apiModule.js +0 -77
- package/codegen/orm/models/apiSchema.d.ts +0 -42
- package/codegen/orm/models/apiSchema.js +0 -77
- package/codegen/orm/models/app.d.ts +0 -42
- package/codegen/orm/models/app.js +0 -77
- package/codegen/orm/models/checkConstraint.d.ts +0 -42
- package/codegen/orm/models/checkConstraint.js +0 -77
- package/codegen/orm/models/connectedAccountsModule.d.ts +0 -42
- package/codegen/orm/models/connectedAccountsModule.js +0 -77
- package/codegen/orm/models/cryptoAddressesModule.d.ts +0 -42
- package/codegen/orm/models/cryptoAddressesModule.js +0 -77
- package/codegen/orm/models/cryptoAuthModule.d.ts +0 -42
- package/codegen/orm/models/cryptoAuthModule.js +0 -77
- package/codegen/orm/models/database.d.ts +0 -42
- package/codegen/orm/models/database.js +0 -77
- package/codegen/orm/models/databaseExtension.d.ts +0 -42
- package/codegen/orm/models/databaseExtension.js +0 -77
- package/codegen/orm/models/databaseProvision.d.ts +0 -42
- package/codegen/orm/models/databaseProvision.js +0 -77
- package/codegen/orm/models/defaultIdsModule.d.ts +0 -42
- package/codegen/orm/models/defaultIdsModule.js +0 -77
- package/codegen/orm/models/denormalizedTableField.d.ts +0 -42
- package/codegen/orm/models/denormalizedTableField.js +0 -77
- package/codegen/orm/models/emailsModule.d.ts +0 -42
- package/codegen/orm/models/emailsModule.js +0 -77
- package/codegen/orm/models/encryptedSecretsModule.d.ts +0 -42
- package/codegen/orm/models/encryptedSecretsModule.js +0 -77
- package/codegen/orm/models/extension.d.ts +0 -42
- package/codegen/orm/models/extension.js +0 -77
- package/codegen/orm/models/field.d.ts +0 -42
- package/codegen/orm/models/field.js +0 -77
- package/codegen/orm/models/fieldModule.d.ts +0 -42
- package/codegen/orm/models/fieldModule.js +0 -77
- package/codegen/orm/models/foreignKeyConstraint.d.ts +0 -42
- package/codegen/orm/models/foreignKeyConstraint.js +0 -77
- package/codegen/orm/models/fullTextSearch.d.ts +0 -42
- package/codegen/orm/models/fullTextSearch.js +0 -77
- package/codegen/orm/models/hierarchyModule.d.ts +0 -42
- package/codegen/orm/models/hierarchyModule.js +0 -77
- package/codegen/orm/models/indexModel.d.ts +0 -42
- package/codegen/orm/models/indexModel.js +0 -77
- package/codegen/orm/models/invitesModule.d.ts +0 -42
- package/codegen/orm/models/invitesModule.js +0 -77
- package/codegen/orm/models/levelsModule.d.ts +0 -42
- package/codegen/orm/models/levelsModule.js +0 -77
- package/codegen/orm/models/limitFunction.d.ts +0 -42
- package/codegen/orm/models/limitFunction.js +0 -77
- package/codegen/orm/models/limitsModule.d.ts +0 -42
- package/codegen/orm/models/limitsModule.js +0 -77
- package/codegen/orm/models/membershipTypesModule.d.ts +0 -42
- package/codegen/orm/models/membershipTypesModule.js +0 -77
- package/codegen/orm/models/membershipsModule.d.ts +0 -42
- package/codegen/orm/models/membershipsModule.js +0 -77
- package/codegen/orm/models/module.d.ts +0 -42
- package/codegen/orm/models/module.js +0 -77
- package/codegen/orm/models/moduleDefinition.d.ts +0 -42
- package/codegen/orm/models/moduleDefinition.js +0 -77
- package/codegen/orm/models/moduleField.d.ts +0 -42
- package/codegen/orm/models/moduleField.js +0 -77
- package/codegen/orm/models/moduleInputRecord.d.ts +0 -42
- package/codegen/orm/models/moduleInputRecord.js +0 -77
- package/codegen/orm/models/moduleOutput.d.ts +0 -42
- package/codegen/orm/models/moduleOutput.js +0 -77
- package/codegen/orm/models/permissionsModule.d.ts +0 -42
- package/codegen/orm/models/permissionsModule.js +0 -77
- package/codegen/orm/models/phoneNumbersModule.d.ts +0 -42
- package/codegen/orm/models/phoneNumbersModule.js +0 -77
- package/codegen/orm/models/policy.d.ts +0 -42
- package/codegen/orm/models/policy.js +0 -77
- package/codegen/orm/models/primaryKeyConstraint.d.ts +0 -42
- package/codegen/orm/models/primaryKeyConstraint.js +0 -77
- package/codegen/orm/models/procedure.d.ts +0 -42
- package/codegen/orm/models/procedure.js +0 -77
- package/codegen/orm/models/profilesModule.d.ts +0 -42
- package/codegen/orm/models/profilesModule.js +0 -77
- package/codegen/orm/models/rlsFunction.d.ts +0 -42
- package/codegen/orm/models/rlsFunction.js +0 -77
- package/codegen/orm/models/rlsModule.d.ts +0 -42
- package/codegen/orm/models/rlsModule.js +0 -77
- package/codegen/orm/models/schema.d.ts +0 -42
- package/codegen/orm/models/schema.js +0 -77
- package/codegen/orm/models/schemaGrant.d.ts +0 -42
- package/codegen/orm/models/schemaGrant.js +0 -77
- package/codegen/orm/models/secretsModule.d.ts +0 -42
- package/codegen/orm/models/secretsModule.js +0 -77
- package/codegen/orm/models/site.d.ts +0 -42
- package/codegen/orm/models/site.js +0 -77
- package/codegen/orm/models/siteMetadatum.d.ts +0 -42
- package/codegen/orm/models/siteMetadatum.js +0 -77
- package/codegen/orm/models/siteModule.d.ts +0 -42
- package/codegen/orm/models/siteModule.js +0 -77
- package/codegen/orm/models/siteTheme.d.ts +0 -42
- package/codegen/orm/models/siteTheme.js +0 -77
- package/codegen/orm/models/table.d.ts +0 -42
- package/codegen/orm/models/table.js +0 -77
- package/codegen/orm/models/tableGrant.d.ts +0 -42
- package/codegen/orm/models/tableGrant.js +0 -77
- package/codegen/orm/models/tokensModule.d.ts +0 -42
- package/codegen/orm/models/tokensModule.js +0 -77
- package/codegen/orm/models/trigger.d.ts +0 -42
- package/codegen/orm/models/trigger.js +0 -77
- package/codegen/orm/models/triggerFunction.d.ts +0 -42
- package/codegen/orm/models/triggerFunction.js +0 -77
- package/codegen/orm/models/uniqueConstraint.d.ts +0 -42
- package/codegen/orm/models/uniqueConstraint.js +0 -77
- package/codegen/orm/models/userAuthModule.d.ts +0 -42
- package/codegen/orm/models/userAuthModule.js +0 -77
- package/codegen/orm/models/usersModule.d.ts +0 -42
- package/codegen/orm/models/usersModule.js +0 -77
- package/codegen/orm/models/uuidModule.d.ts +0 -42
- package/codegen/orm/models/uuidModule.js +0 -77
- package/esm/codegen/orm/models/apiExtension.js +0 -73
- package/esm/codegen/orm/models/apiModule.js +0 -73
- package/esm/codegen/orm/models/apiSchema.js +0 -73
- package/esm/codegen/orm/models/app.js +0 -73
- package/esm/codegen/orm/models/checkConstraint.js +0 -73
- package/esm/codegen/orm/models/connectedAccountsModule.js +0 -73
- package/esm/codegen/orm/models/cryptoAddressesModule.js +0 -73
- package/esm/codegen/orm/models/cryptoAuthModule.js +0 -73
- package/esm/codegen/orm/models/database.js +0 -73
- package/esm/codegen/orm/models/databaseExtension.js +0 -73
- package/esm/codegen/orm/models/databaseProvision.js +0 -73
- package/esm/codegen/orm/models/defaultIdsModule.js +0 -73
- package/esm/codegen/orm/models/denormalizedTableField.js +0 -73
- package/esm/codegen/orm/models/emailsModule.js +0 -73
- package/esm/codegen/orm/models/encryptedSecretsModule.js +0 -73
- package/esm/codegen/orm/models/extension.js +0 -73
- package/esm/codegen/orm/models/field.js +0 -73
- package/esm/codegen/orm/models/fieldModule.js +0 -73
- package/esm/codegen/orm/models/foreignKeyConstraint.js +0 -73
- package/esm/codegen/orm/models/fullTextSearch.js +0 -73
- package/esm/codegen/orm/models/hierarchyModule.js +0 -73
- package/esm/codegen/orm/models/indexModel.js +0 -73
- package/esm/codegen/orm/models/invitesModule.js +0 -73
- package/esm/codegen/orm/models/levelsModule.js +0 -73
- package/esm/codegen/orm/models/limitFunction.js +0 -73
- package/esm/codegen/orm/models/limitsModule.js +0 -73
- package/esm/codegen/orm/models/membershipTypesModule.js +0 -73
- package/esm/codegen/orm/models/membershipsModule.js +0 -73
- package/esm/codegen/orm/models/module.js +0 -73
- package/esm/codegen/orm/models/moduleDefinition.js +0 -73
- package/esm/codegen/orm/models/moduleField.js +0 -73
- package/esm/codegen/orm/models/moduleInputRecord.js +0 -73
- package/esm/codegen/orm/models/moduleOutput.js +0 -73
- package/esm/codegen/orm/models/permissionsModule.js +0 -73
- package/esm/codegen/orm/models/phoneNumbersModule.js +0 -73
- package/esm/codegen/orm/models/policy.js +0 -73
- package/esm/codegen/orm/models/primaryKeyConstraint.js +0 -73
- package/esm/codegen/orm/models/procedure.js +0 -73
- package/esm/codegen/orm/models/profilesModule.js +0 -73
- package/esm/codegen/orm/models/rlsFunction.js +0 -73
- package/esm/codegen/orm/models/rlsModule.js +0 -73
- package/esm/codegen/orm/models/schema.js +0 -73
- package/esm/codegen/orm/models/schemaGrant.js +0 -73
- package/esm/codegen/orm/models/secretsModule.js +0 -73
- package/esm/codegen/orm/models/site.js +0 -73
- package/esm/codegen/orm/models/siteMetadatum.js +0 -73
- package/esm/codegen/orm/models/siteModule.js +0 -73
- package/esm/codegen/orm/models/siteTheme.js +0 -73
- package/esm/codegen/orm/models/table.js +0 -73
- package/esm/codegen/orm/models/tableGrant.js +0 -73
- package/esm/codegen/orm/models/tokensModule.js +0 -73
- package/esm/codegen/orm/models/trigger.js +0 -73
- package/esm/codegen/orm/models/triggerFunction.js +0 -73
- package/esm/codegen/orm/models/uniqueConstraint.js +0 -73
- package/esm/codegen/orm/models/userAuthModule.js +0 -73
- package/esm/codegen/orm/models/usersModule.js +0 -73
- package/esm/codegen/orm/models/uuidModule.js +0 -73
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* @generated by @constructive-io/graphql-codegen
|
|
4
4
|
* DO NOT EDIT - changes will be overwritten
|
|
5
5
|
*/
|
|
6
|
+
import * as t from 'gql-ast';
|
|
7
|
+
import { parseType, print } from 'graphql';
|
|
6
8
|
import { GraphQLRequestError } from './client';
|
|
7
9
|
export class QueryBuilder {
|
|
8
10
|
config;
|
|
@@ -55,155 +57,221 @@ export class QueryBuilder {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
// ============================================================================
|
|
58
|
-
//
|
|
60
|
+
// Selection Builders
|
|
59
61
|
// ============================================================================
|
|
60
62
|
export function buildSelections(select) {
|
|
61
|
-
if (!select)
|
|
62
|
-
return
|
|
63
|
+
if (!select) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
63
66
|
const fields = [];
|
|
64
67
|
for (const [key, value] of Object.entries(select)) {
|
|
65
|
-
if (value === false || value === undefined)
|
|
68
|
+
if (value === false || value === undefined) {
|
|
66
69
|
continue;
|
|
70
|
+
}
|
|
67
71
|
if (value === true) {
|
|
68
|
-
fields.push(key);
|
|
72
|
+
fields.push(t.field({ name: key }));
|
|
69
73
|
continue;
|
|
70
74
|
}
|
|
71
75
|
if (typeof value === 'object' && value !== null) {
|
|
72
76
|
const nested = value;
|
|
73
77
|
if (nested.select) {
|
|
74
78
|
const nestedSelections = buildSelections(nested.select);
|
|
75
|
-
// Check if this is a connection type (has pagination args or explicit connection flag)
|
|
76
79
|
const isConnection = nested.connection === true ||
|
|
77
80
|
nested.first !== undefined ||
|
|
78
81
|
nested.filter !== undefined;
|
|
82
|
+
const args = buildArgs([
|
|
83
|
+
buildOptionalArg('first', nested.first),
|
|
84
|
+
nested.filter
|
|
85
|
+
? t.argument({
|
|
86
|
+
name: 'filter',
|
|
87
|
+
value: buildValueAst(nested.filter),
|
|
88
|
+
})
|
|
89
|
+
: null,
|
|
90
|
+
buildEnumListArg('orderBy', nested.orderBy),
|
|
91
|
+
]);
|
|
79
92
|
if (isConnection) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
fields.push(`${key}${argsStr} {
|
|
88
|
-
nodes { ${nestedSelections} }
|
|
89
|
-
totalCount
|
|
90
|
-
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
91
|
-
}`);
|
|
93
|
+
fields.push(t.field({
|
|
94
|
+
name: key,
|
|
95
|
+
args,
|
|
96
|
+
selectionSet: t.selectionSet({
|
|
97
|
+
selections: buildConnectionSelections(nestedSelections),
|
|
98
|
+
}),
|
|
99
|
+
}));
|
|
92
100
|
}
|
|
93
101
|
else {
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
fields.push(t.field({
|
|
103
|
+
name: key,
|
|
104
|
+
args,
|
|
105
|
+
selectionSet: t.selectionSet({ selections: nestedSelections }),
|
|
106
|
+
}));
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
|
-
return fields
|
|
111
|
+
return fields;
|
|
101
112
|
}
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// Document Builders
|
|
115
|
+
// ============================================================================
|
|
102
116
|
export function buildFindManyDocument(operationName, queryField, select, args, filterTypeName, orderByTypeName) {
|
|
103
|
-
const selections = select
|
|
104
|
-
|
|
117
|
+
const selections = select
|
|
118
|
+
? buildSelections(select)
|
|
119
|
+
: [t.field({ name: 'id' })];
|
|
120
|
+
const variableDefinitions = [];
|
|
105
121
|
const queryArgs = [];
|
|
106
122
|
const variables = {};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
nodes { ${selections} }
|
|
147
|
-
totalCount
|
|
148
|
-
pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
|
|
149
|
-
}
|
|
150
|
-
}`;
|
|
151
|
-
return { document, variables };
|
|
123
|
+
addVariable({
|
|
124
|
+
varName: 'where',
|
|
125
|
+
argName: 'filter',
|
|
126
|
+
typeName: filterTypeName,
|
|
127
|
+
value: args.where,
|
|
128
|
+
}, variableDefinitions, queryArgs, variables);
|
|
129
|
+
addVariable({
|
|
130
|
+
varName: 'orderBy',
|
|
131
|
+
typeName: '[' + orderByTypeName + '!]',
|
|
132
|
+
value: args.orderBy?.length ? args.orderBy : undefined,
|
|
133
|
+
}, variableDefinitions, queryArgs, variables);
|
|
134
|
+
addVariable({ varName: 'first', typeName: 'Int', value: args.first }, variableDefinitions, queryArgs, variables);
|
|
135
|
+
addVariable({ varName: 'last', typeName: 'Int', value: args.last }, variableDefinitions, queryArgs, variables);
|
|
136
|
+
addVariable({ varName: 'after', typeName: 'Cursor', value: args.after }, variableDefinitions, queryArgs, variables);
|
|
137
|
+
addVariable({ varName: 'before', typeName: 'Cursor', value: args.before }, variableDefinitions, queryArgs, variables);
|
|
138
|
+
addVariable({ varName: 'offset', typeName: 'Int', value: args.offset }, variableDefinitions, queryArgs, variables);
|
|
139
|
+
const document = t.document({
|
|
140
|
+
definitions: [
|
|
141
|
+
t.operationDefinition({
|
|
142
|
+
operation: 'query',
|
|
143
|
+
name: operationName + 'Query',
|
|
144
|
+
variableDefinitions: variableDefinitions.length
|
|
145
|
+
? variableDefinitions
|
|
146
|
+
: undefined,
|
|
147
|
+
selectionSet: t.selectionSet({
|
|
148
|
+
selections: [
|
|
149
|
+
t.field({
|
|
150
|
+
name: queryField,
|
|
151
|
+
args: queryArgs.length ? queryArgs : undefined,
|
|
152
|
+
selectionSet: t.selectionSet({
|
|
153
|
+
selections: buildConnectionSelections(selections),
|
|
154
|
+
}),
|
|
155
|
+
}),
|
|
156
|
+
],
|
|
157
|
+
}),
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
return { document: print(document), variables };
|
|
152
162
|
}
|
|
153
163
|
export function buildFindFirstDocument(operationName, queryField, select, args, filterTypeName) {
|
|
154
|
-
const selections = select
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
164
|
+
const selections = select
|
|
165
|
+
? buildSelections(select)
|
|
166
|
+
: [t.field({ name: 'id' })];
|
|
167
|
+
const variableDefinitions = [];
|
|
168
|
+
const queryArgs = [];
|
|
169
|
+
const variables = {};
|
|
170
|
+
// Always add first: 1 for findFirst
|
|
171
|
+
addVariable({ varName: 'first', typeName: 'Int', value: 1 }, variableDefinitions, queryArgs, variables);
|
|
172
|
+
addVariable({
|
|
173
|
+
varName: 'where',
|
|
174
|
+
argName: 'filter',
|
|
175
|
+
typeName: filterTypeName,
|
|
176
|
+
value: args.where,
|
|
177
|
+
}, variableDefinitions, queryArgs, variables);
|
|
178
|
+
const document = t.document({
|
|
179
|
+
definitions: [
|
|
180
|
+
t.operationDefinition({
|
|
181
|
+
operation: 'query',
|
|
182
|
+
name: operationName + 'Query',
|
|
183
|
+
variableDefinitions,
|
|
184
|
+
selectionSet: t.selectionSet({
|
|
185
|
+
selections: [
|
|
186
|
+
t.field({
|
|
187
|
+
name: queryField,
|
|
188
|
+
args: queryArgs,
|
|
189
|
+
selectionSet: t.selectionSet({
|
|
190
|
+
selections: [
|
|
191
|
+
t.field({
|
|
192
|
+
name: 'nodes',
|
|
193
|
+
selectionSet: t.selectionSet({ selections }),
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
}),
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
}),
|
|
200
|
+
}),
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
return { document: print(document), variables };
|
|
169
204
|
}
|
|
170
205
|
export function buildCreateDocument(operationName, mutationField, entityField, select, data, inputTypeName) {
|
|
171
|
-
const selections = select
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
${entityField} { ${selections} }
|
|
175
|
-
}
|
|
176
|
-
}`;
|
|
206
|
+
const selections = select
|
|
207
|
+
? buildSelections(select)
|
|
208
|
+
: [t.field({ name: 'id' })];
|
|
177
209
|
return {
|
|
178
|
-
document
|
|
179
|
-
|
|
210
|
+
document: buildInputMutationDocument({
|
|
211
|
+
operationName,
|
|
212
|
+
mutationField,
|
|
213
|
+
inputTypeName,
|
|
214
|
+
resultSelections: [
|
|
215
|
+
t.field({
|
|
216
|
+
name: entityField,
|
|
217
|
+
selectionSet: t.selectionSet({ selections }),
|
|
218
|
+
}),
|
|
219
|
+
],
|
|
220
|
+
}),
|
|
221
|
+
variables: {
|
|
222
|
+
input: {
|
|
223
|
+
[entityField]: data,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
180
226
|
};
|
|
181
227
|
}
|
|
182
228
|
export function buildUpdateDocument(operationName, mutationField, entityField, select, where, data, inputTypeName) {
|
|
183
|
-
const selections = select
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
${entityField} { ${selections} }
|
|
187
|
-
}
|
|
188
|
-
}`;
|
|
229
|
+
const selections = select
|
|
230
|
+
? buildSelections(select)
|
|
231
|
+
: [t.field({ name: 'id' })];
|
|
189
232
|
return {
|
|
190
|
-
document
|
|
191
|
-
|
|
233
|
+
document: buildInputMutationDocument({
|
|
234
|
+
operationName,
|
|
235
|
+
mutationField,
|
|
236
|
+
inputTypeName,
|
|
237
|
+
resultSelections: [
|
|
238
|
+
t.field({
|
|
239
|
+
name: entityField,
|
|
240
|
+
selectionSet: t.selectionSet({ selections }),
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
variables: {
|
|
245
|
+
input: {
|
|
246
|
+
id: where.id,
|
|
247
|
+
patch: data,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
192
250
|
};
|
|
193
251
|
}
|
|
194
252
|
export function buildDeleteDocument(operationName, mutationField, entityField, where, inputTypeName) {
|
|
195
|
-
const document = `mutation ${operationName}Mutation($input: ${inputTypeName}!) {
|
|
196
|
-
${mutationField}(input: $input) {
|
|
197
|
-
${entityField} { id }
|
|
198
|
-
}
|
|
199
|
-
}`;
|
|
200
253
|
return {
|
|
201
|
-
document
|
|
202
|
-
|
|
254
|
+
document: buildInputMutationDocument({
|
|
255
|
+
operationName,
|
|
256
|
+
mutationField,
|
|
257
|
+
inputTypeName,
|
|
258
|
+
resultSelections: [
|
|
259
|
+
t.field({
|
|
260
|
+
name: entityField,
|
|
261
|
+
selectionSet: t.selectionSet({
|
|
262
|
+
selections: [t.field({ name: 'id' })],
|
|
263
|
+
}),
|
|
264
|
+
}),
|
|
265
|
+
],
|
|
266
|
+
}),
|
|
267
|
+
variables: {
|
|
268
|
+
input: {
|
|
269
|
+
id: where.id,
|
|
270
|
+
},
|
|
271
|
+
},
|
|
203
272
|
};
|
|
204
273
|
}
|
|
205
274
|
export function buildCustomDocument(operationType, operationName, fieldName, select, args, variableDefinitions) {
|
|
206
|
-
// Check if select is wrapped with connection metadata
|
|
207
275
|
let actualSelect = select;
|
|
208
276
|
let isConnection = false;
|
|
209
277
|
if (select && typeof select === 'object' && 'select' in select) {
|
|
@@ -213,26 +281,172 @@ export function buildCustomDocument(operationType, operationName, fieldName, sel
|
|
|
213
281
|
isConnection = wrapper.connection === true;
|
|
214
282
|
}
|
|
215
283
|
}
|
|
216
|
-
const selections = actualSelect
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
284
|
+
const selections = actualSelect
|
|
285
|
+
? buildSelections(actualSelect)
|
|
286
|
+
: [];
|
|
287
|
+
const variableDefs = variableDefinitions.map((definition) => t.variableDefinition({
|
|
288
|
+
variable: t.variable({ name: definition.name }),
|
|
289
|
+
type: parseType(definition.type),
|
|
290
|
+
}));
|
|
291
|
+
const fieldArgs = variableDefinitions.map((definition) => t.argument({
|
|
292
|
+
name: definition.name,
|
|
293
|
+
value: t.variable({ name: definition.name }),
|
|
294
|
+
}));
|
|
295
|
+
const fieldSelections = isConnection
|
|
296
|
+
? buildConnectionSelections(selections)
|
|
297
|
+
: selections;
|
|
298
|
+
const document = t.document({
|
|
299
|
+
definitions: [
|
|
300
|
+
t.operationDefinition({
|
|
301
|
+
operation: operationType,
|
|
302
|
+
name: operationName,
|
|
303
|
+
variableDefinitions: variableDefs.length ? variableDefs : undefined,
|
|
304
|
+
selectionSet: t.selectionSet({
|
|
305
|
+
selections: [
|
|
306
|
+
t.field({
|
|
307
|
+
name: fieldName,
|
|
308
|
+
args: fieldArgs.length ? fieldArgs : undefined,
|
|
309
|
+
selectionSet: fieldSelections.length
|
|
310
|
+
? t.selectionSet({ selections: fieldSelections })
|
|
311
|
+
: undefined,
|
|
312
|
+
}),
|
|
313
|
+
],
|
|
314
|
+
}),
|
|
315
|
+
}),
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
document: print(document),
|
|
320
|
+
variables: (args ?? {}),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
// ============================================================================
|
|
324
|
+
// Helper Functions
|
|
325
|
+
// ============================================================================
|
|
326
|
+
function buildArgs(args) {
|
|
327
|
+
return args.filter((arg) => arg !== null);
|
|
328
|
+
}
|
|
329
|
+
function buildOptionalArg(name, value) {
|
|
330
|
+
if (value === undefined) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const valueNode = typeof value === 'number'
|
|
334
|
+
? t.intValue({ value: value.toString() })
|
|
335
|
+
: t.stringValue({ value });
|
|
336
|
+
return t.argument({ name, value: valueNode });
|
|
337
|
+
}
|
|
338
|
+
function buildEnumListArg(name, values) {
|
|
339
|
+
if (!values || values.length === 0) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return t.argument({
|
|
343
|
+
name,
|
|
344
|
+
value: t.listValue({
|
|
345
|
+
values: values.map((value) => buildEnumValue(value)),
|
|
346
|
+
}),
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function buildEnumValue(value) {
|
|
350
|
+
return {
|
|
351
|
+
kind: 'EnumValue',
|
|
352
|
+
value,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function buildPageInfoSelections() {
|
|
356
|
+
return [
|
|
357
|
+
t.field({ name: 'hasNextPage' }),
|
|
358
|
+
t.field({ name: 'hasPreviousPage' }),
|
|
359
|
+
t.field({ name: 'startCursor' }),
|
|
360
|
+
t.field({ name: 'endCursor' }),
|
|
361
|
+
];
|
|
362
|
+
}
|
|
363
|
+
function buildConnectionSelections(nodeSelections) {
|
|
364
|
+
return [
|
|
365
|
+
t.field({
|
|
366
|
+
name: 'nodes',
|
|
367
|
+
selectionSet: t.selectionSet({ selections: nodeSelections }),
|
|
368
|
+
}),
|
|
369
|
+
t.field({ name: 'totalCount' }),
|
|
370
|
+
t.field({
|
|
371
|
+
name: 'pageInfo',
|
|
372
|
+
selectionSet: t.selectionSet({ selections: buildPageInfoSelections() }),
|
|
373
|
+
}),
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
function buildInputMutationDocument(config) {
|
|
377
|
+
const document = t.document({
|
|
378
|
+
definitions: [
|
|
379
|
+
t.operationDefinition({
|
|
380
|
+
operation: 'mutation',
|
|
381
|
+
name: config.operationName + 'Mutation',
|
|
382
|
+
variableDefinitions: [
|
|
383
|
+
t.variableDefinition({
|
|
384
|
+
variable: t.variable({ name: 'input' }),
|
|
385
|
+
type: parseType(config.inputTypeName + '!'),
|
|
386
|
+
}),
|
|
387
|
+
],
|
|
388
|
+
selectionSet: t.selectionSet({
|
|
389
|
+
selections: [
|
|
390
|
+
t.field({
|
|
391
|
+
name: config.mutationField,
|
|
392
|
+
args: [
|
|
393
|
+
t.argument({
|
|
394
|
+
name: 'input',
|
|
395
|
+
value: t.variable({ name: 'input' }),
|
|
396
|
+
}),
|
|
397
|
+
],
|
|
398
|
+
selectionSet: t.selectionSet({
|
|
399
|
+
selections: config.resultSelections,
|
|
400
|
+
}),
|
|
401
|
+
}),
|
|
402
|
+
],
|
|
403
|
+
}),
|
|
404
|
+
}),
|
|
405
|
+
],
|
|
406
|
+
});
|
|
407
|
+
return print(document);
|
|
408
|
+
}
|
|
409
|
+
function addVariable(spec, definitions, args, variables) {
|
|
410
|
+
if (spec.value === undefined)
|
|
411
|
+
return;
|
|
412
|
+
definitions.push(t.variableDefinition({
|
|
413
|
+
variable: t.variable({ name: spec.varName }),
|
|
414
|
+
type: parseType(spec.typeName),
|
|
415
|
+
}));
|
|
416
|
+
args.push(t.argument({
|
|
417
|
+
name: spec.argName ?? spec.varName,
|
|
418
|
+
value: t.variable({ name: spec.varName }),
|
|
419
|
+
}));
|
|
420
|
+
variables[spec.varName] = spec.value;
|
|
421
|
+
}
|
|
422
|
+
function buildValueAst(value) {
|
|
423
|
+
if (value === null) {
|
|
424
|
+
return t.nullValue();
|
|
425
|
+
}
|
|
426
|
+
if (typeof value === 'boolean') {
|
|
427
|
+
return t.booleanValue({ value });
|
|
428
|
+
}
|
|
429
|
+
if (typeof value === 'number') {
|
|
430
|
+
return Number.isInteger(value)
|
|
431
|
+
? t.intValue({ value: value.toString() })
|
|
432
|
+
: t.floatValue({ value: value.toString() });
|
|
433
|
+
}
|
|
434
|
+
if (typeof value === 'string') {
|
|
435
|
+
return t.stringValue({ value });
|
|
436
|
+
}
|
|
437
|
+
if (Array.isArray(value)) {
|
|
438
|
+
return t.listValue({
|
|
439
|
+
values: value.map((item) => buildValueAst(item)),
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (typeof value === 'object' && value !== null) {
|
|
443
|
+
const obj = value;
|
|
444
|
+
return t.objectValue({
|
|
445
|
+
fields: Object.entries(obj).map(([key, val]) => t.objectField({
|
|
446
|
+
name: key,
|
|
447
|
+
value: buildValueAst(val),
|
|
448
|
+
})),
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
throw new Error('Unsupported value type: ' + typeof value);
|
|
238
452
|
}
|