@ttoss/appsync-api 0.17.11 → 0.17.12
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/esm/index.js +31 -3
- package/dist/index.js +31 -3
- package/package.json +2 -2
- package/src/createApiTemplate.ts +1 -1
- package/src/createAppSyncResolverHandler.ts +40 -2
package/dist/esm/index.js
CHANGED
|
@@ -80,7 +80,7 @@ var getPackageLambdaLayerStackName = packageName => {
|
|
|
80
80
|
// package.json
|
|
81
81
|
var package_default = {
|
|
82
82
|
name: "@ttoss/appsync-api",
|
|
83
|
-
version: "0.17.
|
|
83
|
+
version: "0.17.12",
|
|
84
84
|
description: "A library for building GraphQL APIs for AWS AppSync.",
|
|
85
85
|
author: "ttoss",
|
|
86
86
|
contributors: ["Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"],
|
|
@@ -231,7 +231,7 @@ var createApiTemplate = ({
|
|
|
231
231
|
Layers: getPeerDependenciesLambdaLayers(),
|
|
232
232
|
MemorySize: 512,
|
|
233
233
|
Role: lambdaFunction.roleArn,
|
|
234
|
-
Runtime: "
|
|
234
|
+
Runtime: "nodejs20.x",
|
|
235
235
|
/**
|
|
236
236
|
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
237
237
|
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
@@ -361,6 +361,9 @@ var createAppSyncResolverHandler = ({
|
|
|
361
361
|
...buildSchemaInput
|
|
362
362
|
}) => {
|
|
363
363
|
return async (event, context) => {
|
|
364
|
+
const {
|
|
365
|
+
schemaComposer
|
|
366
|
+
} = buildSchemaInput;
|
|
364
367
|
const {
|
|
365
368
|
info,
|
|
366
369
|
arguments: args,
|
|
@@ -389,7 +392,32 @@ var createAppSyncResolverHandler = ({
|
|
|
389
392
|
if (!resolver) {
|
|
390
393
|
throw new Error(`Resolver for ${parentTypeName}.${fieldName} not found`);
|
|
391
394
|
}
|
|
392
|
-
const
|
|
395
|
+
const argsWithEnumValues = (() => {
|
|
396
|
+
const fieldsArgsIsEnumType = field.args.filter(arg => {
|
|
397
|
+
return schemaComposer.isEnumType(arg.type);
|
|
398
|
+
});
|
|
399
|
+
const enumArgs = fieldsArgsIsEnumType.map(enumArg => {
|
|
400
|
+
if (!args[enumArg.name]) {
|
|
401
|
+
return {
|
|
402
|
+
[enumArg.name]: enumArg.defaultValue
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const values = schemaComposer.getETC(enumArg.type).getFields();
|
|
406
|
+
return {
|
|
407
|
+
[enumArg.name]: values[args[enumArg.name]].value
|
|
408
|
+
};
|
|
409
|
+
}).reduce((acc, curr) => {
|
|
410
|
+
return {
|
|
411
|
+
...acc,
|
|
412
|
+
...curr
|
|
413
|
+
};
|
|
414
|
+
}, {});
|
|
415
|
+
return {
|
|
416
|
+
...args,
|
|
417
|
+
...enumArgs
|
|
418
|
+
};
|
|
419
|
+
})();
|
|
420
|
+
const response = await resolver(source, argsWithEnumValues, {
|
|
393
421
|
...context,
|
|
394
422
|
identity: event.identity,
|
|
395
423
|
credentials,
|
package/dist/index.js
CHANGED
|
@@ -112,7 +112,7 @@ var getPackageLambdaLayerStackName = packageName => {
|
|
|
112
112
|
// package.json
|
|
113
113
|
var package_default = {
|
|
114
114
|
name: "@ttoss/appsync-api",
|
|
115
|
-
version: "0.17.
|
|
115
|
+
version: "0.17.12",
|
|
116
116
|
description: "A library for building GraphQL APIs for AWS AppSync.",
|
|
117
117
|
author: "ttoss",
|
|
118
118
|
contributors: ["Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"],
|
|
@@ -263,7 +263,7 @@ var createApiTemplate = ({
|
|
|
263
263
|
Layers: getPeerDependenciesLambdaLayers(),
|
|
264
264
|
MemorySize: 512,
|
|
265
265
|
Role: lambdaFunction.roleArn,
|
|
266
|
-
Runtime: "
|
|
266
|
+
Runtime: "nodejs20.x",
|
|
267
267
|
/**
|
|
268
268
|
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
269
269
|
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
@@ -393,6 +393,9 @@ var createAppSyncResolverHandler = ({
|
|
|
393
393
|
...buildSchemaInput
|
|
394
394
|
}) => {
|
|
395
395
|
return async (event, context) => {
|
|
396
|
+
const {
|
|
397
|
+
schemaComposer
|
|
398
|
+
} = buildSchemaInput;
|
|
396
399
|
const {
|
|
397
400
|
info,
|
|
398
401
|
arguments: args,
|
|
@@ -421,7 +424,32 @@ var createAppSyncResolverHandler = ({
|
|
|
421
424
|
if (!resolver) {
|
|
422
425
|
throw new Error(`Resolver for ${parentTypeName}.${fieldName} not found`);
|
|
423
426
|
}
|
|
424
|
-
const
|
|
427
|
+
const argsWithEnumValues = (() => {
|
|
428
|
+
const fieldsArgsIsEnumType = field.args.filter(arg => {
|
|
429
|
+
return schemaComposer.isEnumType(arg.type);
|
|
430
|
+
});
|
|
431
|
+
const enumArgs = fieldsArgsIsEnumType.map(enumArg => {
|
|
432
|
+
if (!args[enumArg.name]) {
|
|
433
|
+
return {
|
|
434
|
+
[enumArg.name]: enumArg.defaultValue
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
const values = schemaComposer.getETC(enumArg.type).getFields();
|
|
438
|
+
return {
|
|
439
|
+
[enumArg.name]: values[args[enumArg.name]].value
|
|
440
|
+
};
|
|
441
|
+
}).reduce((acc, curr) => {
|
|
442
|
+
return {
|
|
443
|
+
...acc,
|
|
444
|
+
...curr
|
|
445
|
+
};
|
|
446
|
+
}, {});
|
|
447
|
+
return {
|
|
448
|
+
...args,
|
|
449
|
+
...enumArgs
|
|
450
|
+
};
|
|
451
|
+
})();
|
|
452
|
+
const response = await resolver(source, argsWithEnumValues, {
|
|
425
453
|
...context,
|
|
426
454
|
identity: event.identity,
|
|
427
455
|
credentials,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/appsync-api",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.12",
|
|
4
4
|
"description": "A library for building GraphQL APIs for AWS AppSync.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@ttoss/config": "^1.31.4",
|
|
36
36
|
"@ttoss/graphql-api": "^0.5.0",
|
|
37
37
|
"@ttoss/relay-amplify": "^0.5.4",
|
|
38
|
-
"carlin": "^1.31.
|
|
38
|
+
"carlin": "^1.31.8"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"api",
|
package/src/createApiTemplate.ts
CHANGED
|
@@ -172,7 +172,7 @@ export const createApiTemplate = ({
|
|
|
172
172
|
Layers: getPeerDependenciesLambdaLayers(),
|
|
173
173
|
MemorySize: 512,
|
|
174
174
|
Role: lambdaFunction.roleArn,
|
|
175
|
-
Runtime: '
|
|
175
|
+
Runtime: 'nodejs20.x',
|
|
176
176
|
/**
|
|
177
177
|
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
178
178
|
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { BuildSchemaInput, buildSchema } from '@ttoss/graphql-api';
|
|
2
3
|
import { type GraphQLObjectType } from 'graphql';
|
|
3
4
|
import { decodeCredentials } from '@ttoss/relay-amplify/src/encodeCredentials';
|
|
@@ -6,13 +7,15 @@ import type { AppSyncResolverHandler as AwsAppSyncResolverHandler } from 'aws-la
|
|
|
6
7
|
export type AppSyncResolverHandler<
|
|
7
8
|
TArguments,
|
|
8
9
|
TResult,
|
|
9
|
-
TSource = Record<string, any> | null
|
|
10
|
+
TSource = Record<string, any> | null,
|
|
10
11
|
> = AwsAppSyncResolverHandler<TArguments, TResult, TSource>;
|
|
11
12
|
|
|
12
13
|
export const createAppSyncResolverHandler = ({
|
|
13
14
|
...buildSchemaInput
|
|
14
15
|
}: BuildSchemaInput): AppSyncResolverHandler<any, any, any> => {
|
|
15
16
|
return async (event, context) => {
|
|
17
|
+
const { schemaComposer } = buildSchemaInput;
|
|
18
|
+
|
|
16
19
|
const { info, arguments: args, source, request } = event;
|
|
17
20
|
|
|
18
21
|
const { parentTypeName, fieldName } = info;
|
|
@@ -45,9 +48,44 @@ export const createAppSyncResolverHandler = ({
|
|
|
45
48
|
throw new Error(`Resolver for ${parentTypeName}.${fieldName} not found`);
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/**
|
|
52
|
+
* `composeWithConnection` findMany resolver needs sort to be the enum
|
|
53
|
+
* value defined in the enum instead the enum name.
|
|
54
|
+
* For example, if the config `sort.ID_ASC.value` is `{ order : 'ASC' }`,
|
|
55
|
+
* then the value of the argument `sort` enm should be
|
|
56
|
+
* `{ order : 'ASC' }` instead of `'ID_ASC'`.
|
|
57
|
+
*/
|
|
58
|
+
const argsWithEnumValues = (() => {
|
|
59
|
+
const fieldsArgsIsEnumType = field.args.filter((arg) => {
|
|
60
|
+
return schemaComposer.isEnumType(arg.type);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const enumArgs = fieldsArgsIsEnumType
|
|
64
|
+
.map((enumArg) => {
|
|
65
|
+
if (!args[enumArg.name]) {
|
|
66
|
+
return { [enumArg.name]: enumArg.defaultValue };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const values = schemaComposer.getETC(enumArg.type).getFields();
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
[enumArg.name]: values[args[enumArg.name]].value,
|
|
73
|
+
};
|
|
74
|
+
})
|
|
75
|
+
.reduce((acc, curr) => {
|
|
76
|
+
return { ...acc, ...curr };
|
|
77
|
+
}, {});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* If `args.sort` has sort name, i.e. `ID_ASC`, then `enumArgs` will
|
|
81
|
+
* replace it with the value of the enum, i.e. `{ order : 'ASC' }`.
|
|
82
|
+
*/
|
|
83
|
+
return { ...args, ...enumArgs };
|
|
84
|
+
})();
|
|
85
|
+
|
|
48
86
|
const response = await resolver(
|
|
49
87
|
source,
|
|
50
|
-
|
|
88
|
+
argsWithEnumValues,
|
|
51
89
|
{ ...context, identity: event.identity, credentials, headers },
|
|
52
90
|
info as any
|
|
53
91
|
);
|