@aws-amplify/graphql-model-transformer 0.15.6-alpha.0 → 0.15.6
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/CHANGELOG.md +11 -0
- package/lib/graphql-model-transformer.d.ts +1 -1
- package/lib/graphql-model-transformer.d.ts.map +1 -1
- package/lib/graphql-model-transformer.js +8 -38
- package/lib/graphql-model-transformer.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/__snapshots__/model-transformer.test.ts.snap +30 -109
- package/src/__tests__/model-transformer.test.ts +21 -7
- package/src/graphql-model-transformer.ts +18 -61
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DirectiveWrapper,
|
|
3
|
-
FieldWrapper,
|
|
4
|
-
getFieldNameFor,
|
|
5
|
-
InputObjectDefinitionWrapper,
|
|
6
3
|
InvalidDirectiveError,
|
|
7
4
|
MappingTemplate,
|
|
8
|
-
ObjectDefinitionWrapper,
|
|
9
5
|
SyncConfig,
|
|
10
6
|
SyncUtils,
|
|
11
7
|
TransformerModelBase,
|
|
12
8
|
TransformerNestedStack,
|
|
9
|
+
FieldWrapper,
|
|
10
|
+
InputObjectDefinitionWrapper,
|
|
11
|
+
ObjectDefinitionWrapper,
|
|
12
|
+
getFieldNameFor,
|
|
13
13
|
} from '@aws-amplify/graphql-transformer-core';
|
|
14
14
|
import {
|
|
15
15
|
AppSyncDataSourceType,
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
MutationFieldType,
|
|
19
19
|
QueryFieldType,
|
|
20
20
|
SubscriptionFieldType,
|
|
21
|
-
TransformerBeforeStepContextProvider,
|
|
22
21
|
TransformerContextProvider,
|
|
23
22
|
TransformerModelProvider,
|
|
24
23
|
TransformerPrepareStepContextProvider,
|
|
@@ -26,17 +25,12 @@ import {
|
|
|
26
25
|
TransformerSchemaVisitStepContextProvider,
|
|
27
26
|
TransformerTransformSchemaStepContextProvider,
|
|
28
27
|
TransformerValidationStepContextProvider,
|
|
28
|
+
TransformerBeforeStepContextProvider,
|
|
29
29
|
} from '@aws-amplify/graphql-transformer-interfaces';
|
|
30
30
|
import {
|
|
31
|
-
AttributeType,
|
|
32
|
-
CfnTable,
|
|
33
|
-
ITable,
|
|
34
|
-
StreamViewType,
|
|
35
|
-
Table,
|
|
36
|
-
TableEncryption,
|
|
31
|
+
AttributeType, CfnTable, ITable, StreamViewType, Table, TableEncryption,
|
|
37
32
|
} from '@aws-cdk/aws-dynamodb';
|
|
38
33
|
import * as iam from '@aws-cdk/aws-iam';
|
|
39
|
-
import { CfnRole } from '@aws-cdk/aws-iam';
|
|
40
34
|
import * as cdk from '@aws-cdk/core';
|
|
41
35
|
import { CfnDataSource } from '@aws-cdk/aws-appsync';
|
|
42
36
|
import {
|
|
@@ -63,6 +57,7 @@ import {
|
|
|
63
57
|
toCamelCase,
|
|
64
58
|
toPascalCase,
|
|
65
59
|
} from 'graphql-transformer-common';
|
|
60
|
+
import { CfnRole } from '@aws-cdk/aws-iam';
|
|
66
61
|
import {
|
|
67
62
|
addDirectivesToOperation,
|
|
68
63
|
addModelConditionInputs,
|
|
@@ -97,7 +92,7 @@ import {
|
|
|
97
92
|
generateSyncRequestTemplate,
|
|
98
93
|
} from './resolvers/query';
|
|
99
94
|
import { API_KEY_DIRECTIVE } from './definitions';
|
|
100
|
-
import {
|
|
95
|
+
import { SubscriptionLevel, ModelDirectiveConfiguration } from './directive';
|
|
101
96
|
|
|
102
97
|
/**
|
|
103
98
|
* Nullable
|
|
@@ -230,31 +225,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
230
225
|
createdAt: 'createdAt',
|
|
231
226
|
updatedAt: 'updatedAt',
|
|
232
227
|
},
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// This property override is specifically to address parity between V1 and V2 when the FF is disabled
|
|
236
|
-
// If one subscription is defined, just let the others go to null without FF. But if public and none defined, default all subs
|
|
237
|
-
if (!ctx.featureFlags.getBoolean('shouldDeepMergeDirectiveConfigDefaults', false)) {
|
|
238
|
-
const publicSubscriptionDefaults = {
|
|
239
|
-
onCreate: [getFieldNameFor('onCreate', typeName)],
|
|
240
|
-
onDelete: [getFieldNameFor('onDelete', typeName)],
|
|
241
|
-
onUpdate: [getFieldNameFor('onUpdate', typeName)],
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const baseArgs = directiveWrapped.getArguments(
|
|
245
|
-
{
|
|
246
|
-
subscriptions: {
|
|
247
|
-
level: SubscriptionLevel.on,
|
|
248
|
-
...publicSubscriptionDefaults,
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
ctx.featureFlags,
|
|
252
|
-
);
|
|
253
|
-
if (baseArgs?.subscriptions?.level === SubscriptionLevel.public
|
|
254
|
-
&& !(baseArgs?.subscriptions?.onCreate || baseArgs?.subscriptions?.onDelete || baseArgs?.subscriptions?.onUpdate)) {
|
|
255
|
-
options.subscriptions = { level: SubscriptionLevel.public, ...publicSubscriptionDefaults };
|
|
256
|
-
}
|
|
257
|
-
}
|
|
228
|
+
});
|
|
258
229
|
|
|
259
230
|
if (options.subscriptions?.onCreate && !Array.isArray(options.subscriptions.onCreate)) {
|
|
260
231
|
options.subscriptions.onCreate = [options.subscriptions.onCreate];
|
|
@@ -395,7 +366,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
395
366
|
|
|
396
367
|
const subscriptionLevel = this.modelDirectiveConfig.get(def.name.value)?.subscriptions?.level;
|
|
397
368
|
// in order to create subscription resolvers the level needs to be on
|
|
398
|
-
if (subscriptionLevel
|
|
369
|
+
if (subscriptionLevel === SubscriptionLevel.on) {
|
|
399
370
|
const subscriptionFields = this.getSubscriptionFieldNames(def!);
|
|
400
371
|
subscriptionFields.forEach(subscription => {
|
|
401
372
|
let resolver;
|
|
@@ -427,15 +398,13 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
427
398
|
default:
|
|
428
399
|
throw new Error('Unknown subscription field type');
|
|
429
400
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
);
|
|
438
|
-
}
|
|
401
|
+
resolver.addToSlot(
|
|
402
|
+
'postAuth',
|
|
403
|
+
MappingTemplate.s3MappingTemplateFromString(
|
|
404
|
+
generateAuthExpressionForSandboxMode(context.sandboxModeEnabled),
|
|
405
|
+
`${subscription.typeName}.${subscription.fieldName}.{slotName}.{slotIndex}.req.vtl`,
|
|
406
|
+
),
|
|
407
|
+
);
|
|
439
408
|
resolver.mapToStack(context.stackManager.getStackFor(subscription.resolverLogicalId, def!.name.value));
|
|
440
409
|
context.resolvers.addResolver(subscription.typeName, subscription.fieldName, resolver);
|
|
441
410
|
});
|
|
@@ -1010,19 +979,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
|
|
|
1010
979
|
case SubscriptionFieldType.ON_CREATE:
|
|
1011
980
|
case SubscriptionFieldType.ON_DELETE:
|
|
1012
981
|
case SubscriptionFieldType.ON_UPDATE:
|
|
1013
|
-
|
|
1014
|
-
const filterInputs = createEnumModelFilters(ctx, type);
|
|
1015
|
-
filterInputs.push(makeSubscriptionQueryFilterInput(ctx, filterInputName, type));
|
|
1016
|
-
filterInputs.forEach(input => {
|
|
1017
|
-
const conditionInputName = input.name.value;
|
|
1018
|
-
if (!ctx.output.getType(conditionInputName)) {
|
|
1019
|
-
ctx.output.addInput(input);
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
|
|
1023
|
-
return [
|
|
1024
|
-
makeInputValueDefinition('filter', makeNamedType(filterInputName)),
|
|
1025
|
-
];
|
|
982
|
+
return [];
|
|
1026
983
|
|
|
1027
984
|
default:
|
|
1028
985
|
throw new Error('Unknown operation type');
|