@aws-amplify/data-schema 1.26.0 → 1.26.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/dist/cjs/runtime/internals/operations/custom.js +31 -3
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/esm/runtime/internals/operations/custom.mjs +31 -3
- package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/runtime/internals/operations/custom.ts +36 -3
package/package.json
CHANGED
|
@@ -212,8 +212,12 @@ function isInputType(type: InputFieldType): type is InputType {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
|
+
* For a list argument this is the *element* type, so `isRequired` — which is
|
|
216
|
+
* element-level for lists — is the correct source for the `!`. The list's own
|
|
217
|
+
* nullability is applied by the caller. See {@link isArgumentRequired}.
|
|
218
|
+
*
|
|
215
219
|
* @param argDef A single argument definition from a custom operation
|
|
216
|
-
* @returns A string naming the base type including the `!` if
|
|
220
|
+
* @returns A string naming the base type including the `!` if that type is non-null.
|
|
217
221
|
*/
|
|
218
222
|
function argumentBaseTypeString({ type, isRequired }: CustomOperationArgument) {
|
|
219
223
|
const requiredFlag = isRequired ? '!' : '';
|
|
@@ -226,6 +230,35 @@ function argumentBaseTypeString({ type, isRequired }: CustomOperationArgument) {
|
|
|
226
230
|
return `${type}${requiredFlag}`;
|
|
227
231
|
}
|
|
228
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Determines whether a value must be provided for a custom operation argument,
|
|
235
|
+
* i.e. whether the argument itself is non-null in the GraphQL schema.
|
|
236
|
+
*
|
|
237
|
+
* For list arguments, the model introspection schema encodes *element* nullability
|
|
238
|
+
* in `isRequired` and *list* nullability in `isArrayNullable`. For example, an
|
|
239
|
+
* argument declared as `a.ref('Color').required().array()` is emitted as `[Color!]`
|
|
240
|
+
* and introspected as `{ isArray: true, isRequired: true, isArrayNullable: true }`
|
|
241
|
+
* — a nullable list of non-null elements, so the argument itself is optional. Only
|
|
242
|
+
* the outermost nullability determines whether the caller has to supply a value.
|
|
243
|
+
*
|
|
244
|
+
* `isArrayNullable` is optional in the introspection schema. The generator we
|
|
245
|
+
* build against always emits it for list arguments (`getTypeInfo()` sets
|
|
246
|
+
* `isListNullable` on every list branch), but when it is absent we treat the list
|
|
247
|
+
* as non-null to stay consistent with the `[T]!` that `outerArguments()` renders
|
|
248
|
+
* for the same input — a request declaring a non-null variable with no value
|
|
249
|
+
* would be rejected by the server anyway.
|
|
250
|
+
*
|
|
251
|
+
* @param argDef A single argument definition from a custom operation
|
|
252
|
+
* @returns Boolean: `true` if the argument itself is non-null
|
|
253
|
+
*/
|
|
254
|
+
function isArgumentRequired({
|
|
255
|
+
isArray,
|
|
256
|
+
isRequired,
|
|
257
|
+
isArrayNullable,
|
|
258
|
+
}: CustomOperationArgument): boolean {
|
|
259
|
+
return isArray ? !isArrayNullable : isRequired;
|
|
260
|
+
}
|
|
261
|
+
|
|
229
262
|
/**
|
|
230
263
|
* Generates "outer" arguments string for a custom operation. For example,
|
|
231
264
|
* in this operation:
|
|
@@ -253,7 +286,7 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
253
286
|
.map(([k, argument]) => {
|
|
254
287
|
const baseType = argumentBaseTypeString(argument);
|
|
255
288
|
const finalType = argument.isArray
|
|
256
|
-
? `[${baseType}]${argument
|
|
289
|
+
? `[${baseType}]${isArgumentRequired(argument) ? '!' : ''}`
|
|
257
290
|
: baseType;
|
|
258
291
|
|
|
259
292
|
return `$${k}: ${finalType}`;
|
|
@@ -357,7 +390,7 @@ function operationVariables(
|
|
|
357
390
|
for (const argDef of Object.values(operation.arguments)) {
|
|
358
391
|
if (typeof args[argDef.name] !== 'undefined') {
|
|
359
392
|
variables[argDef.name] = args[argDef.name];
|
|
360
|
-
} else if (argDef
|
|
393
|
+
} else if (isArgumentRequired(argDef)) {
|
|
361
394
|
// At this point, the variable is both required and missing: We don't need
|
|
362
395
|
// to continue. The operation is expected to fail.
|
|
363
396
|
throw new Error(`${operation.name} requires arguments '${argDef.name}'`);
|