graphile-build-pg 4.13.0 → 4.14.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/README.md +4 -13
- package/node8plus/GraphQLJSON.js +0 -11
- package/node8plus/GraphQLJSON.js.map +1 -1
- package/node8plus/PgLiveProvider.js +4 -11
- package/node8plus/PgLiveProvider.js.map +1 -1
- package/node8plus/QueryBuilder.js +42 -176
- package/node8plus/QueryBuilder.js.map +1 -1
- package/node8plus/index.js +8 -47
- package/node8plus/index.js.map +1 -1
- package/node8plus/inflections.js +9 -61
- package/node8plus/inflections.js.map +1 -1
- package/node8plus/omit.js +7 -22
- package/node8plus/omit.js.map +1 -1
- package/node8plus/parseIdentifier.js +0 -1
- package/node8plus/parseIdentifier.js.map +1 -1
- package/node8plus/pgPrepareAndRun.js +2 -14
- package/node8plus/pgPrepareAndRun.js.map +1 -1
- package/node8plus/plugins/PageInfoStartEndCursor.js +0 -4
- package/node8plus/plugins/PageInfoStartEndCursor.js.map +1 -1
- package/node8plus/plugins/PgAllRows.js +0 -29
- package/node8plus/plugins/PgAllRows.js.map +1 -1
- package/node8plus/plugins/PgBackwardRelationPlugin.js +2 -41
- package/node8plus/plugins/PgBackwardRelationPlugin.js.map +1 -1
- package/node8plus/plugins/PgBasicsPlugin.js +20 -147
- package/node8plus/plugins/PgBasicsPlugin.js.map +1 -1
- package/node8plus/plugins/PgColumnDeprecationPlugin.js +2 -5
- package/node8plus/plugins/PgColumnDeprecationPlugin.js.map +1 -1
- package/node8plus/plugins/PgColumnsPlugin.js +4 -17
- package/node8plus/plugins/PgColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgComputedColumnsPlugin.js +4 -19
- package/node8plus/plugins/PgComputedColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgConditionComputedColumnPlugin.js +12 -23
- package/node8plus/plugins/PgConditionComputedColumnPlugin.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgCondition.js +1 -9
- package/node8plus/plugins/PgConnectionArgCondition.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js +0 -12
- package/node8plus/plugins/PgConnectionArgFirstLastBeforeAfter.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgOrderBy.js +2 -19
- package/node8plus/plugins/PgConnectionArgOrderBy.js.map +1 -1
- package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js +0 -6
- package/node8plus/plugins/PgConnectionArgOrderByDefaultValue.js.map +1 -1
- package/node8plus/plugins/PgConnectionTotalCount.js +0 -8
- package/node8plus/plugins/PgConnectionTotalCount.js.map +1 -1
- package/node8plus/plugins/PgForwardRelationPlugin.js +2 -25
- package/node8plus/plugins/PgForwardRelationPlugin.js.map +1 -1
- package/node8plus/plugins/PgIntrospectionPlugin.js +91 -180
- package/node8plus/plugins/PgIntrospectionPlugin.js.flow +30 -2
- package/node8plus/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgJWTPlugin.js +2 -18
- package/node8plus/plugins/PgJWTPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationCreatePlugin.js +0 -18
- package/node8plus/plugins/PgMutationCreatePlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationPayloadEdgePlugin.js +4 -25
- package/node8plus/plugins/PgMutationPayloadEdgePlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationProceduresPlugin.js +0 -6
- package/node8plus/plugins/PgMutationProceduresPlugin.js.map +1 -1
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js +14 -49
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.flow +5 -2
- package/node8plus/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
- package/node8plus/plugins/PgNodeAliasPostGraphile.js +0 -6
- package/node8plus/plugins/PgNodeAliasPostGraphile.js.map +1 -1
- package/node8plus/plugins/PgOrderAllColumnsPlugin.js +0 -4
- package/node8plus/plugins/PgOrderAllColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js +0 -6
- package/node8plus/plugins/PgOrderByPrimaryKeyPlugin.js.map +1 -1
- package/node8plus/plugins/PgOrderComputedColumnsPlugin.js +10 -14
- package/node8plus/plugins/PgOrderComputedColumnsPlugin.js.map +1 -1
- package/node8plus/plugins/PgQueryProceduresPlugin.js +4 -16
- package/node8plus/plugins/PgQueryProceduresPlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js +3 -20
- package/node8plus/plugins/PgRecordFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js +11 -16
- package/node8plus/plugins/PgRecordReturnTypesPlugin.js.map +1 -1
- package/node8plus/plugins/PgRowByUniqueConstraint.js +4 -25
- package/node8plus/plugins/PgRowByUniqueConstraint.js.map +1 -1
- package/node8plus/plugins/PgRowNode.js +0 -32
- package/node8plus/plugins/PgRowNode.js.map +1 -1
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js +3 -17
- package/node8plus/plugins/PgScalarFunctionConnectionPlugin.js.map +1 -1
- package/node8plus/plugins/PgTablesPlugin.js +7 -59
- package/node8plus/plugins/PgTablesPlugin.js.map +1 -1
- package/node8plus/plugins/PgTypesPlugin.js +140 -240
- package/node8plus/plugins/PgTypesPlugin.js.flow +76 -23
- package/node8plus/plugins/PgTypesPlugin.js.map +1 -1
- package/node8plus/plugins/addStartEndCursor.js +2 -5
- package/node8plus/plugins/addStartEndCursor.js.map +1 -1
- package/node8plus/plugins/debugSql.js +1 -16
- package/node8plus/plugins/debugSql.js.map +1 -1
- package/node8plus/plugins/introspectionQuery.js +3 -4
- package/node8plus/plugins/introspectionQuery.js.flow +11 -3
- package/node8plus/plugins/introspectionQuery.js.map +1 -1
- package/node8plus/plugins/makeProcField.js +40 -90
- package/node8plus/plugins/makeProcField.js.map +1 -1
- package/node8plus/plugins/pgField.js +2 -7
- package/node8plus/plugins/pgField.js.map +1 -1
- package/node8plus/plugins/viaTemporaryTable.js +6 -12
- package/node8plus/plugins/viaTemporaryTable.js.map +1 -1
- package/node8plus/postgresInterval.js +4 -4
- package/node8plus/postgresInterval.js.map +1 -1
- package/node8plus/queryFromResolveDataFactory.js +33 -77
- package/node8plus/queryFromResolveDataFactory.js.map +1 -1
- package/node8plus/utils.js +8 -9
- package/node8plus/utils.js.map +1 -1
- package/node8plus/withPgClient.js +4 -26
- package/node8plus/withPgClient.js.map +1 -1
- package/package.json +4 -4
|
@@ -5,27 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = makeProcField;
|
|
7
7
|
exports.procFieldDetails = procFieldDetails;
|
|
8
|
-
|
|
9
8
|
var _debugSql = _interopRequireDefault(require("./debugSql"));
|
|
10
|
-
|
|
11
9
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
const nullableIf = (GraphQLNonNull, condition, Type) => condition ? Type : new GraphQLNonNull(Type);
|
|
16
|
-
|
|
17
12
|
const firstValue = obj => {
|
|
18
13
|
let firstKey;
|
|
19
|
-
|
|
20
14
|
for (const k in obj) {
|
|
21
15
|
if (k[0] !== "_" && k[1] !== "_") {
|
|
22
16
|
firstKey = k;
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
return obj[firstKey];
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
function procFieldDetails(proc, build, options) {
|
|
30
22
|
const {
|
|
31
23
|
computed = false,
|
|
@@ -44,93 +36,88 @@ function procFieldDetails(proc, build, options) {
|
|
|
44
36
|
describePgEntity,
|
|
45
37
|
sqlCommentByAddingTags
|
|
46
38
|
} = build;
|
|
47
|
-
|
|
48
39
|
if (computed && isMutation) {
|
|
49
40
|
throw new Error("Mutation procedure cannot be computed");
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
const sliceAmount = computed ? 1 : 0;
|
|
53
43
|
const argNames = proc.argTypeIds.reduce((prev, _, idx) => {
|
|
54
|
-
if (idx >= sliceAmount && (
|
|
55
|
-
|
|
56
|
-
proc.argModes
|
|
44
|
+
if (idx >= sliceAmount && (
|
|
45
|
+
// Was a .slice() call
|
|
46
|
+
proc.argModes.length === 0 ||
|
|
47
|
+
// all args are `in`
|
|
48
|
+
proc.argModes[idx] === "i" ||
|
|
49
|
+
// this arg is `in`
|
|
57
50
|
proc.argModes[idx] === "b") // this arg is `inout`
|
|
58
51
|
) {
|
|
59
52
|
prev.push(proc.argNames[idx] || "");
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
return prev;
|
|
63
55
|
}, []);
|
|
64
56
|
const argTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {
|
|
65
|
-
if (idx >= sliceAmount && (
|
|
66
|
-
|
|
67
|
-
proc.argModes
|
|
57
|
+
if (idx >= sliceAmount && (
|
|
58
|
+
// Was a .slice() call
|
|
59
|
+
proc.argModes.length === 0 ||
|
|
60
|
+
// all args are `in`
|
|
61
|
+
proc.argModes[idx] === "i" ||
|
|
62
|
+
// this arg is `in`
|
|
68
63
|
proc.argModes[idx] === "b") // this arg is `inout`
|
|
69
64
|
) {
|
|
70
65
|
prev.push(introspectionResultsByKind.typeById[typeId]);
|
|
71
66
|
}
|
|
72
|
-
|
|
73
67
|
return prev;
|
|
74
68
|
}, []);
|
|
75
|
-
const argModesWithOutput = ["o",
|
|
76
|
-
|
|
69
|
+
const argModesWithOutput = ["o",
|
|
70
|
+
// OUT,
|
|
71
|
+
"b",
|
|
72
|
+
// INOUT
|
|
77
73
|
"t" // TABLE
|
|
78
74
|
];
|
|
75
|
+
|
|
79
76
|
const outputArgNames = proc.argTypeIds.reduce((prev, _, idx) => {
|
|
80
77
|
if (argModesWithOutput.includes(proc.argModes[idx])) {
|
|
81
78
|
prev.push(proc.argNames[idx] || "");
|
|
82
79
|
}
|
|
83
|
-
|
|
84
80
|
return prev;
|
|
85
81
|
}, []);
|
|
86
82
|
const outputArgTypes = proc.argTypeIds.reduce((prev, typeId, idx) => {
|
|
87
83
|
if (argModesWithOutput.includes(proc.argModes[idx])) {
|
|
88
84
|
prev.push(introspectionResultsByKind.typeById[typeId]);
|
|
89
85
|
}
|
|
90
|
-
|
|
91
86
|
return prev;
|
|
92
87
|
}, []);
|
|
93
88
|
const requiredArgCount = Math.max(0, argNames.length - proc.argDefaultsNum);
|
|
94
|
-
|
|
95
89
|
const variantFromName = name => {
|
|
96
90
|
if (name.match(/(_p|P)atch$/)) {
|
|
97
91
|
return "patch";
|
|
98
92
|
}
|
|
99
|
-
|
|
100
93
|
return null;
|
|
101
94
|
};
|
|
102
|
-
|
|
103
95
|
const variantFromTags = (tags, idx) => {
|
|
104
96
|
const variant = tags[`arg${idx}variant`];
|
|
105
|
-
|
|
106
97
|
if (variant && variant.match && variant.match(/^[0-9]+$/)) {
|
|
107
98
|
return parseInt(variant, 10);
|
|
108
99
|
}
|
|
109
|
-
|
|
110
100
|
return variant;
|
|
111
101
|
};
|
|
112
|
-
|
|
113
102
|
const notNullArgCount = proc.isStrict || strictFunctions ? requiredArgCount : 0;
|
|
114
103
|
const argGqlTypes = argTypes.map((type, idx) => {
|
|
115
104
|
// TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod on function return values, but maybe a later version might
|
|
116
105
|
const variant = variantFromTags(proc.tags, idx) || variantFromName(argNames[idx]);
|
|
117
106
|
const Type = pgGetGqlInputTypeByTypeIdAndModifier(type.id, variant);
|
|
118
|
-
|
|
119
107
|
if (!Type) {
|
|
120
108
|
const hint = type.class ? `; this might be because no INSERT column privileges are granted on ${describePgEntity(type.class)}. You can use 'Smart Comments' to tell PostGraphile to instead use the "${_chalk.default.bold.green("base")}" input type which includes all columns:\n\n ${sqlCommentByAddingTags(proc, {
|
|
121
109
|
[`arg${idx}variant`]: "base"
|
|
122
110
|
})}\n` : "";
|
|
123
111
|
throw new Error(`Could not determine type for argument ${idx} ('${argNames[idx]}') of function ${describePgEntity(proc)}${hint}`);
|
|
124
112
|
}
|
|
125
|
-
|
|
126
113
|
if (idx >= notNullArgCount) {
|
|
127
114
|
return Type;
|
|
128
115
|
} else {
|
|
129
116
|
return new GraphQLNonNull(Type);
|
|
130
117
|
}
|
|
131
|
-
});
|
|
118
|
+
});
|
|
119
|
+
// This wants to be compatible with both being field arguments and being
|
|
132
120
|
// input object fields (e.g. for the aggregates plugin).
|
|
133
|
-
|
|
134
121
|
const inputs = argNames.reduce((memo, argName, argIndex) => {
|
|
135
122
|
const gqlArgName = inflection.argument(argName, argIndex);
|
|
136
123
|
memo[gqlArgName] = {
|
|
@@ -138,7 +125,6 @@ function procFieldDetails(proc, build, options) {
|
|
|
138
125
|
};
|
|
139
126
|
return memo;
|
|
140
127
|
}, {});
|
|
141
|
-
|
|
142
128
|
function makeSqlFunctionCall(rawArgs = {}, {
|
|
143
129
|
implicitArgs = [],
|
|
144
130
|
unnest = false
|
|
@@ -146,20 +132,17 @@ function procFieldDetails(proc, build, options) {
|
|
|
146
132
|
const args = isMutation ? rawArgs.input : rawArgs;
|
|
147
133
|
const sqlArgValues = [];
|
|
148
134
|
let haveNames = true;
|
|
149
|
-
|
|
150
135
|
for (let argIndex = argNames.length - 1; argIndex >= 0; argIndex--) {
|
|
151
136
|
const argName = argNames[argIndex];
|
|
152
137
|
const gqlArgName = inflection.argument(argName, argIndex);
|
|
153
138
|
const value = args[gqlArgName];
|
|
154
139
|
const variant = variantFromTags(proc.tags, argIndex) || variantFromName(argNames[argIndex]);
|
|
155
140
|
const sqlValue = gql2pg(value, argTypes[argIndex], variant);
|
|
156
|
-
|
|
157
141
|
if (argIndex + 1 > requiredArgCount && haveNames && value == null) {
|
|
158
142
|
// No need to pass argument to function
|
|
159
143
|
continue;
|
|
160
144
|
} else if (argIndex + 1 > requiredArgCount && haveNames) {
|
|
161
145
|
const sqlArgName = argName ? sql.identifier(argName) : null;
|
|
162
|
-
|
|
163
146
|
if (sqlArgName) {
|
|
164
147
|
sqlArgValues.unshift(sql.fragment`${sqlArgName} := ${sqlValue}`);
|
|
165
148
|
} else {
|
|
@@ -170,11 +153,9 @@ function procFieldDetails(proc, build, options) {
|
|
|
170
153
|
sqlArgValues.unshift(sqlValue);
|
|
171
154
|
}
|
|
172
155
|
}
|
|
173
|
-
|
|
174
156
|
const functionCall = sql.fragment`${sql.identifier(proc.namespace.name, proc.name)}(${sql.join([...implicitArgs, ...sqlArgValues], ", ")})`;
|
|
175
157
|
return unnest ? sql.fragment`unnest(${functionCall})` : functionCall;
|
|
176
158
|
}
|
|
177
|
-
|
|
178
159
|
return {
|
|
179
160
|
inputs,
|
|
180
161
|
makeSqlFunctionCall,
|
|
@@ -182,7 +163,6 @@ function procFieldDetails(proc, build, options) {
|
|
|
182
163
|
outputArgTypes
|
|
183
164
|
};
|
|
184
165
|
}
|
|
185
|
-
|
|
186
166
|
function makeProcField(fieldName, proc, build, options) {
|
|
187
167
|
const {
|
|
188
168
|
fieldWithHooks,
|
|
@@ -234,30 +214,28 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
234
214
|
outputArgTypes
|
|
235
215
|
} = procFieldDetails(proc, build, options);
|
|
236
216
|
let args = inputs;
|
|
217
|
+
|
|
237
218
|
/**
|
|
238
219
|
* This is the return type the function claims to have; we
|
|
239
220
|
* should not use it anywhere but these next few lines.
|
|
240
221
|
*/
|
|
241
|
-
|
|
242
222
|
const baseReturnType = introspectionResultsByKind.typeById[proc.returnTypeId];
|
|
223
|
+
|
|
243
224
|
/**
|
|
244
225
|
* This is the return type we treat it as having, e.g. in
|
|
245
226
|
* case it was modified by wrapping it in an aggregate or
|
|
246
227
|
* similar.
|
|
247
228
|
*/
|
|
248
|
-
|
|
249
229
|
const rawReturnType = pgTypeAndModifierModifier ? pgTypeAndModifierModifier(baseReturnType, null)[0] : baseReturnType;
|
|
230
|
+
|
|
250
231
|
/**
|
|
251
232
|
* This is the type without the array wrapper.
|
|
252
233
|
*/
|
|
253
|
-
|
|
254
234
|
const returnType = rawReturnType.isPgArray ? rawReturnType.arrayItemType : rawReturnType;
|
|
255
235
|
const returnTypeTable = introspectionResultsByKind.classById[returnType.classId];
|
|
256
|
-
|
|
257
236
|
if (!returnType) {
|
|
258
237
|
throw new Error(`Could not determine return type for function '${proc.name}'`);
|
|
259
238
|
}
|
|
260
|
-
|
|
261
239
|
let type;
|
|
262
240
|
const fieldScope = {};
|
|
263
241
|
const payloadTypeScope = {};
|
|
@@ -267,7 +245,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
267
245
|
const TableType = returnTypeTable && pgGetGqlTypeByTypeIdAndModifier(returnTypeTable.type.id, null);
|
|
268
246
|
const isTableLike = TableType && isCompositeType(TableType) || false;
|
|
269
247
|
const isRecordLike = returnType.id === "2249";
|
|
270
|
-
|
|
271
248
|
if (isTableLike) {
|
|
272
249
|
if (proc.returnsSet) {
|
|
273
250
|
if (isMutation) {
|
|
@@ -279,35 +256,28 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
279
256
|
fieldScope.isPgFieldSimpleCollection = true;
|
|
280
257
|
} else {
|
|
281
258
|
const ConnectionType = getTypeByName(inflection.connection(TableType.name));
|
|
282
|
-
|
|
283
259
|
if (!ConnectionType) {
|
|
284
260
|
throw new Error(`Do not have a connection type '${inflection.connection(TableType.name)}' for '${TableType.name}' so cannot create procedure field`);
|
|
285
261
|
}
|
|
286
|
-
|
|
287
262
|
type = ConnectionType;
|
|
288
263
|
fieldScope.isPgFieldConnection = true;
|
|
289
264
|
}
|
|
290
|
-
|
|
291
265
|
fieldScope.pgFieldIntrospectionTable = returnTypeTable;
|
|
292
266
|
payloadTypeScope.pgIntrospectionTable = returnTypeTable;
|
|
293
267
|
} else {
|
|
294
268
|
type = TableType;
|
|
295
|
-
|
|
296
269
|
if (rawReturnType.isPgArray) {
|
|
297
270
|
// Not implementing pgForbidSetofFunctionsToReturnNull here because it's not a set
|
|
298
271
|
type = new GraphQLList(type);
|
|
299
272
|
}
|
|
300
|
-
|
|
301
273
|
fieldScope.pgFieldIntrospectionTable = returnTypeTable;
|
|
302
274
|
payloadTypeScope.pgIntrospectionTable = returnTypeTable;
|
|
303
275
|
}
|
|
304
276
|
} else if (isRecordLike) {
|
|
305
277
|
const RecordType = getTypeByName(inflection.recordFunctionReturnType(proc));
|
|
306
|
-
|
|
307
278
|
if (!RecordType) {
|
|
308
279
|
throw new Error(`Do not have a record type '${inflection.recordFunctionReturnType(proc)}' for '${proc.name}' so cannot create procedure field`);
|
|
309
280
|
}
|
|
310
|
-
|
|
311
281
|
if (proc.returnsSet) {
|
|
312
282
|
if (isMutation) {
|
|
313
283
|
type = new GraphQLList(RecordType);
|
|
@@ -316,17 +286,14 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
316
286
|
fieldScope.isPgFieldSimpleCollection = true;
|
|
317
287
|
} else {
|
|
318
288
|
const ConnectionType = getTypeByName(inflection.recordFunctionConnection(proc));
|
|
319
|
-
|
|
320
289
|
if (!ConnectionType) {
|
|
321
290
|
throw new Error(`Do not have a connection type '${inflection.recordFunctionConnection(proc)}' for '${RecordType.name}' so cannot create procedure field`);
|
|
322
291
|
}
|
|
323
|
-
|
|
324
292
|
type = ConnectionType;
|
|
325
293
|
fieldScope.isPgFieldConnection = true;
|
|
326
294
|
}
|
|
327
295
|
} else {
|
|
328
296
|
type = RecordType;
|
|
329
|
-
|
|
330
297
|
if (rawReturnType.isPgArray) {
|
|
331
298
|
type = new GraphQLList(type);
|
|
332
299
|
}
|
|
@@ -334,11 +301,9 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
334
301
|
} else {
|
|
335
302
|
// TODO: PG10 doesn't support the equivalent of pg_attribute.atttypemod on function return values, but maybe a later version might
|
|
336
303
|
const Type = pgGetGqlTypeByTypeIdAndModifier(returnType.id, null) || GraphQLString;
|
|
337
|
-
|
|
338
304
|
if (proc.returnsSet) {
|
|
339
305
|
const connectionTypeName = inflection.scalarFunctionConnection(proc);
|
|
340
306
|
const ConnectionType = getTypeByName(connectionTypeName);
|
|
341
|
-
|
|
342
307
|
if (isMutation) {
|
|
343
308
|
// Cannot return a connection because it would have to run the mutation again
|
|
344
309
|
type = new GraphQLList(Type);
|
|
@@ -349,7 +314,8 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
349
314
|
fieldScope.isPgFieldSimpleCollection = true;
|
|
350
315
|
} else {
|
|
351
316
|
type = ConnectionType;
|
|
352
|
-
fieldScope.isPgFieldConnection = true;
|
|
317
|
+
fieldScope.isPgFieldConnection = true;
|
|
318
|
+
// We don't return the first value as the value here because it gets
|
|
353
319
|
// sent down into PgScalarFunctionConnectionPlugin so the relevant
|
|
354
320
|
// EdgeType can return cursor / node; i.e. we might want to add an
|
|
355
321
|
// `__cursor` field so we can't just use a scalar.
|
|
@@ -357,13 +323,11 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
357
323
|
} else {
|
|
358
324
|
returnFirstValueAsValue = true;
|
|
359
325
|
type = Type;
|
|
360
|
-
|
|
361
326
|
if (rawReturnType.isPgArray) {
|
|
362
327
|
type = new GraphQLList(type);
|
|
363
328
|
}
|
|
364
329
|
}
|
|
365
330
|
}
|
|
366
|
-
|
|
367
331
|
return fieldWithHooks(fieldName, ({
|
|
368
332
|
addDataGenerator,
|
|
369
333
|
getDataFromParsedResolveInfoFragment,
|
|
@@ -377,12 +341,12 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
377
341
|
};
|
|
378
342
|
});
|
|
379
343
|
}
|
|
380
|
-
|
|
381
344
|
function makeQuery(parsedResolveInfoFragment, ReturnType, sqlMutationQuery, functionAlias, parentQueryBuilder, resolveContext, resolveInfo) {
|
|
382
345
|
const resolveData = getDataFromParsedResolveInfoFragment(parsedResolveInfoFragment, ReturnType);
|
|
383
346
|
const isConnection = !forceList && !isMutation && proc.returnsSet;
|
|
384
347
|
const query = queryFromResolveData(sqlMutationQuery, functionAlias, resolveData, {
|
|
385
|
-
useAsterisk: !isMutation && (isTableLike || isRecordLike) && (forceList || proc.returnsSet || rawReturnType.isPgArray) &&
|
|
348
|
+
useAsterisk: !isMutation && (isTableLike || isRecordLike) && (forceList || proc.returnsSet || rawReturnType.isPgArray) &&
|
|
349
|
+
// only bother with lists
|
|
386
350
|
proc.language !== "sql",
|
|
387
351
|
// sql functions can be inlined, so GRANTs still apply
|
|
388
352
|
withPagination: isConnection,
|
|
@@ -392,12 +356,12 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
392
356
|
addNullCase: !proc.returnsSet && !rawReturnType.isPgArray && (isTableLike || isRecordLike)
|
|
393
357
|
}, innerQueryBuilder => {
|
|
394
358
|
innerQueryBuilder.parentQueryBuilder = parentQueryBuilder;
|
|
395
|
-
|
|
396
359
|
if (!isTableLike) {
|
|
397
360
|
if (returnTypeTable) {
|
|
398
361
|
innerQueryBuilder.select(pgTweakFragmentForTypeAndModifier(sql.fragment`${functionAlias}`, returnTypeTable.type, null, resolveData), "value");
|
|
399
362
|
} else {
|
|
400
|
-
innerQueryBuilder.select(pgTweakFragmentForTypeAndModifier(sql.fragment`${functionAlias}`, returnType, null,
|
|
363
|
+
innerQueryBuilder.select(pgTweakFragmentForTypeAndModifier(sql.fragment`${functionAlias}`, returnType, null,
|
|
364
|
+
// We can't determine a type modifier for functions
|
|
401
365
|
resolveData), "value");
|
|
402
366
|
}
|
|
403
367
|
} else if (subscriptions && returnTypeTable && !isConnection && returnTypeTable.primaryKeyConstraint) {
|
|
@@ -406,7 +370,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
406
370
|
}, parentQueryBuilder ? parentQueryBuilder.context : resolveContext, parentQueryBuilder ? parentQueryBuilder.rootValue : resolveInfo && resolveInfo.rootValue);
|
|
407
371
|
return query;
|
|
408
372
|
}
|
|
409
|
-
|
|
410
373
|
if (computed) {
|
|
411
374
|
addDataGenerator((parsedResolveInfoFragment, ReturnType) => {
|
|
412
375
|
return {
|
|
@@ -418,7 +381,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
418
381
|
implicitArgs: [parentTableAlias],
|
|
419
382
|
unnest: rawReturnType.isPgArray
|
|
420
383
|
});
|
|
421
|
-
|
|
422
384
|
if (aggregateWrapper) {
|
|
423
385
|
return aggregateWrapper(sqlFunctionCall);
|
|
424
386
|
} else {
|
|
@@ -430,14 +392,12 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
430
392
|
};
|
|
431
393
|
});
|
|
432
394
|
}
|
|
433
|
-
|
|
434
395
|
let ReturnType = type;
|
|
435
396
|
let PayloadType;
|
|
436
|
-
|
|
437
397
|
if (isMutation) {
|
|
438
398
|
const resultFieldName = inflection.functionMutationResultFieldName(proc, getNamedType(type), proc.returnsSet || rawReturnType.isPgArray, outputArgNames);
|
|
439
|
-
const isNotVoid = String(returnType.id) !== "2278";
|
|
440
|
-
|
|
399
|
+
const isNotVoid = String(returnType.id) !== "2278";
|
|
400
|
+
// If set then plural name
|
|
441
401
|
PayloadType = newWithHooks(GraphQLObjectType, {
|
|
442
402
|
name: inflection.functionPayloadType(proc),
|
|
443
403
|
description: build.wrapDescription(`The output of our \`${inflection.functionMutationName(proc)}\` mutation.`, "type"),
|
|
@@ -455,12 +415,11 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
455
415
|
resolve(data) {
|
|
456
416
|
return data.data;
|
|
457
417
|
}
|
|
458
|
-
|
|
459
418
|
} : null)
|
|
460
419
|
}, {}, false, {
|
|
461
420
|
pgType: returnType
|
|
462
|
-
})
|
|
463
|
-
|
|
421
|
+
})
|
|
422
|
+
// Result
|
|
464
423
|
} : null);
|
|
465
424
|
}
|
|
466
425
|
}, {
|
|
@@ -491,16 +450,15 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
491
450
|
type: new GraphQLNonNull(InputType)
|
|
492
451
|
}
|
|
493
452
|
};
|
|
494
|
-
}
|
|
453
|
+
}
|
|
454
|
+
// If this is a table we can process it directly; but if it's a scalar
|
|
495
455
|
// setof function we must dereference '.value' from it, because this
|
|
496
456
|
// makes space for '__cursor' to exist alongside it (whereas on a table
|
|
497
457
|
// the '__cursor' can just be on the table object itself)
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const scalarAwarePg2gql = v => isTableLike ? pg2gql(v, returnType) : { ...v,
|
|
458
|
+
const scalarAwarePg2gql = v => isTableLike ? pg2gql(v, returnType) : {
|
|
459
|
+
...v,
|
|
501
460
|
value: pg2gql(v.value, returnType)
|
|
502
461
|
};
|
|
503
|
-
|
|
504
462
|
return {
|
|
505
463
|
description: overrideDescription ? overrideDescription : proc.description ? proc.description : isMutation ? null : isTableLike && proc.returnsSet ? build.wrapDescription(`Reads and enables pagination through a set of \`${TableType.name}\`.`, "field") : null,
|
|
506
464
|
type: nullableIf(GraphQLNonNull, !proc.tags.notNull && (!fieldScope.isPgFieldConnection || isMutation || isRootQuery), ReturnType),
|
|
@@ -509,7 +467,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
509
467
|
const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
|
|
510
468
|
const safeAlias = getSafeAliasFromResolveInfo(resolveInfo);
|
|
511
469
|
const value = data[safeAlias];
|
|
512
|
-
|
|
513
470
|
if (returnFirstValueAsValue) {
|
|
514
471
|
// Is not table like; is not record like.
|
|
515
472
|
if (proc.returnsSet && !forceList) {
|
|
@@ -527,10 +484,10 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
527
484
|
liveRecord("pg", returnTypeTable, record.__identifiers);
|
|
528
485
|
}
|
|
529
486
|
} : _record => {};
|
|
530
|
-
|
|
531
487
|
if (proc.returnsSet && !isMutation && !forceList) {
|
|
532
488
|
// Connection - do not make live (the connection will handle this)
|
|
533
|
-
return addStartEndCursor({
|
|
489
|
+
return addStartEndCursor({
|
|
490
|
+
...value,
|
|
534
491
|
data: value.data ? value.data.map(scalarAwarePg2gql) : null
|
|
535
492
|
});
|
|
536
493
|
} else if (proc.returnsSet || rawReturnType.isPgArray) {
|
|
@@ -545,7 +502,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
545
502
|
if (value) {
|
|
546
503
|
makeRecordLive(value);
|
|
547
504
|
}
|
|
548
|
-
|
|
549
505
|
return pg2gql(value, returnType);
|
|
550
506
|
}
|
|
551
507
|
}
|
|
@@ -556,20 +512,17 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
556
512
|
const liveRecord = resolveInfo.rootValue && resolveInfo.rootValue.liveRecord;
|
|
557
513
|
const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);
|
|
558
514
|
parsedResolveInfoFragment.args = args; // Allow overriding via makeWrapResolversPlugin
|
|
559
|
-
|
|
560
515
|
const functionAlias = sql.identifier(Symbol());
|
|
561
516
|
const sqlFunctionCall = makeSqlFunctionCall(parsedResolveInfoFragment.args, {
|
|
562
517
|
unnest: rawReturnType.isPgArray
|
|
563
518
|
});
|
|
564
519
|
let queryResultRows;
|
|
565
|
-
|
|
566
520
|
if (isMutation) {
|
|
567
521
|
const query = makeQuery(parsedResolveInfoFragment, resolveInfo.returnType, functionAlias, functionAlias, null, resolveContext, resolveInfo);
|
|
568
522
|
const intermediateIdentifier = sql.identifier(Symbol());
|
|
569
523
|
const isVoid = returnType.id === "2278";
|
|
570
524
|
const isPgRecord = returnType.id === "2249";
|
|
571
525
|
const isPgClass = !isPgRecord && (!returnFirstValueAsValue || returnTypeTable || false);
|
|
572
|
-
|
|
573
526
|
try {
|
|
574
527
|
await pgClient.query("SAVEPOINT graphql_mutation");
|
|
575
528
|
queryResultRows = await viaTemporaryTable(pgClient, isVoid ? null : sql.identifier(returnType.namespaceName, returnType.name), sql.query`select ${isPgClass ? sql.query`${intermediateIdentifier}.*` : isPgRecord ? sql.query`${intermediateIdentifier}.*` : sql.query`${intermediateIdentifier} as ${functionAlias}`} from ${sqlFunctionCall} ${intermediateIdentifier}`, functionAlias, query, isPgClass, isPgRecord ? {
|
|
@@ -591,17 +544,14 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
591
544
|
const queryResult = await pgPrepareAndRun(pgClient, text, values);
|
|
592
545
|
queryResultRows = queryResult.rows;
|
|
593
546
|
}
|
|
594
|
-
|
|
595
547
|
const rows = queryResultRows;
|
|
596
548
|
const [row] = rows;
|
|
597
|
-
|
|
598
549
|
const result = (() => {
|
|
599
550
|
const makeRecordLive = subscriptions && isTableLike && returnTypeTable && liveRecord ? record => {
|
|
600
551
|
if (record) {
|
|
601
552
|
liveRecord("pg", returnTypeTable, record.__identifiers);
|
|
602
553
|
}
|
|
603
554
|
} : _record => {};
|
|
604
|
-
|
|
605
555
|
if (returnFirstValueAsValue) {
|
|
606
556
|
// `returnFirstValueAsValue` implies either `isMutation` is
|
|
607
557
|
// true, or `ConnectionType` does not exist - either way,
|
|
@@ -628,7 +578,8 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
628
578
|
if (proc.returnsSet && !isMutation && !forceList) {
|
|
629
579
|
// Connection
|
|
630
580
|
const data = row.data ? row.data.map(scalarAwarePg2gql) : null;
|
|
631
|
-
return addStartEndCursor({
|
|
581
|
+
return addStartEndCursor({
|
|
582
|
+
...row,
|
|
632
583
|
data
|
|
633
584
|
});
|
|
634
585
|
} else if (proc.returnsSet || rawReturnType.isPgArray) {
|
|
@@ -644,7 +595,6 @@ function makeProcField(fieldName, proc, build, options) {
|
|
|
644
595
|
}
|
|
645
596
|
}
|
|
646
597
|
})();
|
|
647
|
-
|
|
648
598
|
if (isMutation) {
|
|
649
599
|
return {
|
|
650
600
|
clientMutationId: args.input.clientMutationId,
|