@aws-amplify/data-schema 1.3.5 → 1.3.7
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/SchemaProcessor.js +38 -8
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/custom.js +15 -2
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +2 -1
- package/dist/esm/SchemaProcessor.mjs +39 -9
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/custom.mjs +15 -2
- 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/ClientSchema/Core/ClientCustomOperations.ts +4 -1
- package/src/SchemaProcessor.ts +48 -10
- package/src/runtime/internals/operations/custom.ts +17 -2
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import type { AppSyncResolverHandler } from 'aws-lambda';
|
|
|
6
6
|
import type { CustomType } from '../../CustomType';
|
|
7
7
|
import type { FieldTypesOfCustomType } from '../../MappedTypes/ResolveSchema';
|
|
8
8
|
import type { ResolveRef } from '../utilities/ResolveRef';
|
|
9
|
+
import type { EnumType } from '../../EnumType';
|
|
9
10
|
import { ClientSchemaProperty } from './ClientSchemaProperty';
|
|
10
11
|
|
|
11
12
|
type CustomOperationSubType<Op extends CustomOperationParamShape> =
|
|
@@ -83,7 +84,9 @@ type CustomOpArguments<Shape extends CustomOperationParamShape> =
|
|
|
83
84
|
infer R
|
|
84
85
|
>
|
|
85
86
|
? R
|
|
86
|
-
:
|
|
87
|
+
: Shape['arguments'][FieldName] extends EnumType<infer Values>
|
|
88
|
+
? Values[number] | null
|
|
89
|
+
: never;
|
|
87
90
|
}>;
|
|
88
91
|
|
|
89
92
|
/**
|
package/src/SchemaProcessor.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type InternalField,
|
|
5
5
|
string,
|
|
6
6
|
type BaseModelField,
|
|
7
|
+
ModelFieldType,
|
|
7
8
|
} from './ModelField';
|
|
8
9
|
import { type InternalRelationalField } from './ModelRelationalField';
|
|
9
10
|
import type { InternalModel } from './ModelType';
|
|
@@ -397,14 +398,14 @@ function customOperationToGql(
|
|
|
397
398
|
}
|
|
398
399
|
|
|
399
400
|
if (Object.keys(fieldArgs).length > 0) {
|
|
400
|
-
const { gqlFields, implicitTypes } = processFields(
|
|
401
|
+
const { gqlFields, implicitTypes: implied } = processFields(
|
|
401
402
|
typeName,
|
|
402
403
|
fieldArgs,
|
|
403
404
|
{},
|
|
404
405
|
{},
|
|
405
406
|
);
|
|
406
407
|
callSignature += `(${gqlFields.join(', ')})`;
|
|
407
|
-
implicitTypes.push(...
|
|
408
|
+
implicitTypes.push(...implied);
|
|
408
409
|
}
|
|
409
410
|
|
|
410
411
|
const handler = handlers && handlers[0];
|
|
@@ -484,6 +485,34 @@ function escapeGraphQlString(str: string) {
|
|
|
484
485
|
return JSON.stringify(str);
|
|
485
486
|
}
|
|
486
487
|
|
|
488
|
+
/**
|
|
489
|
+
* AWS AppSync scalars that are stored as strings in the data source
|
|
490
|
+
*/
|
|
491
|
+
const stringFieldTypes = {
|
|
492
|
+
ID: true,
|
|
493
|
+
String: true,
|
|
494
|
+
AWSDate: true,
|
|
495
|
+
AWSTime: true,
|
|
496
|
+
AWSDateTime: true,
|
|
497
|
+
AWSEmail: true,
|
|
498
|
+
AWSPhone: true,
|
|
499
|
+
AWSURL: true,
|
|
500
|
+
AWSIPAddress: true,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Normalize string-compatible field types for comparison
|
|
505
|
+
*/
|
|
506
|
+
const normalizeStringFieldTypes = (
|
|
507
|
+
fieldType: ModelFieldType,
|
|
508
|
+
): ModelFieldType => {
|
|
509
|
+
if (fieldType in stringFieldTypes) {
|
|
510
|
+
return ModelFieldType.String;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return fieldType;
|
|
514
|
+
};
|
|
515
|
+
|
|
487
516
|
/**
|
|
488
517
|
* Tests whether two ModelField definitions are in conflict.
|
|
489
518
|
*
|
|
@@ -496,15 +525,24 @@ function escapeGraphQlString(str: string) {
|
|
|
496
525
|
* @returns
|
|
497
526
|
*/
|
|
498
527
|
function areConflicting(left: BaseModelField, right: BaseModelField): boolean {
|
|
499
|
-
|
|
528
|
+
const leftData = (left as InternalField).data;
|
|
529
|
+
const rightData = (right as InternalField).data;
|
|
530
|
+
|
|
531
|
+
// `array` and `fieldType` are the only props we care about for this comparison, because the others
|
|
500
532
|
// (required, arrayRequired, etc) are not specified on auth or FK directives.
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
533
|
+
if (leftData.array !== rightData.array) {
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// Convert "string-compatible" field types to `String` for the sake of this comparison
|
|
538
|
+
//
|
|
539
|
+
// E.g. if a customer has an explicit a.id() field that they're referencing in an allow.ownerDefinedIn rule
|
|
540
|
+
// we treat ID and String as equivalent/non-conflicting
|
|
541
|
+
if (
|
|
542
|
+
normalizeStringFieldTypes(leftData.fieldType) !==
|
|
543
|
+
normalizeStringFieldTypes(rightData.fieldType)
|
|
544
|
+
) {
|
|
545
|
+
return true;
|
|
508
546
|
}
|
|
509
547
|
|
|
510
548
|
return false;
|
|
@@ -191,6 +191,21 @@ function hasStringField<Field extends string>(
|
|
|
191
191
|
return typeof o[field] === 'string';
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @param argDef A single argument definition from a custom operation
|
|
196
|
+
* @returns A string naming the base type including the `!` if the arg is required.
|
|
197
|
+
*/
|
|
198
|
+
function argumentBaseTypeString(
|
|
199
|
+
argDef: Exclude<CustomOperation['arguments'], undefined>[number],
|
|
200
|
+
) {
|
|
201
|
+
const requiredFlag = argDef.isRequired ? '!' : '';
|
|
202
|
+
if (argDef.type instanceof Object && 'enum' in argDef.type) {
|
|
203
|
+
return argDef.type.enum + requiredFlag;
|
|
204
|
+
} else {
|
|
205
|
+
return argDef.type + requiredFlag;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
194
209
|
/**
|
|
195
210
|
* Generates "outer" arguments string for a custom operation. For example,
|
|
196
211
|
* in this operation:
|
|
@@ -216,7 +231,7 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
216
231
|
}
|
|
217
232
|
const args = Object.entries(operation.arguments)
|
|
218
233
|
.map(([k, v]) => {
|
|
219
|
-
const baseType =
|
|
234
|
+
const baseType = argumentBaseTypeString(v);
|
|
220
235
|
const finalType = v.isArray
|
|
221
236
|
? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
|
|
222
237
|
: baseType;
|
|
@@ -261,7 +276,7 @@ function innerArguments(operation: CustomOperation): string {
|
|
|
261
276
|
/**
|
|
262
277
|
* Generates the selection set string for a custom operation. This is slightly
|
|
263
278
|
* different than the selection set generation for models. If the custom op returns
|
|
264
|
-
* a primitive or enum types, it
|
|
279
|
+
* a primitive or enum types, it doesn't require a selection set at all.
|
|
265
280
|
*
|
|
266
281
|
* E.g., the graphql might look like this:
|
|
267
282
|
*
|