@ttoss/appsync-api 0.7.3 → 0.7.5
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/cli.d.ts +1 -0
- package/dist/cli.js +4 -0
- package/dist/esm/chunk-CXLYPHQJ.js +359 -0
- package/dist/esm/cli.js +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/server.js +0 -1
- package/dist/index.js +21 -482
- package/dist/server.js +4 -0
- package/package.json +5 -5
- package/dist/esm/chunk-5TOD5USB.js +0 -815
- package/dist/esm/chunk-NQOARNEJ.js +0 -27
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
18
22
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
19
23
|
mod
|
|
20
24
|
));
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
|
|
3
|
+
// src/createApiTemplate.ts
|
|
4
|
+
import { graphql } from "graphql-compose";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/tslib/tslib.es6.js
|
|
7
|
+
var __assign = function() {
|
|
8
|
+
__assign = Object.assign || function __assign2(t) {
|
|
9
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
10
|
+
s = arguments[i];
|
|
11
|
+
for (var p in s)
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// ../../node_modules/lower-case/dist.es2015/index.js
|
|
21
|
+
function lowerCase(str) {
|
|
22
|
+
return str.toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ../../node_modules/no-case/dist.es2015/index.js
|
|
26
|
+
var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
27
|
+
var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
28
|
+
function noCase(input, options) {
|
|
29
|
+
if (options === void 0) {
|
|
30
|
+
options = {};
|
|
31
|
+
}
|
|
32
|
+
var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
|
|
33
|
+
var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
|
|
34
|
+
var start = 0;
|
|
35
|
+
var end = result.length;
|
|
36
|
+
while (result.charAt(start) === "\0")
|
|
37
|
+
start++;
|
|
38
|
+
while (result.charAt(end - 1) === "\0")
|
|
39
|
+
end--;
|
|
40
|
+
return result.slice(start, end).split("\0").map(transform).join(delimiter);
|
|
41
|
+
}
|
|
42
|
+
function replace(input, re, value) {
|
|
43
|
+
if (re instanceof RegExp)
|
|
44
|
+
return input.replace(re, value);
|
|
45
|
+
return re.reduce(function(input2, re2) {
|
|
46
|
+
return input2.replace(re2, value);
|
|
47
|
+
}, input);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ../../node_modules/pascal-case/dist.es2015/index.js
|
|
51
|
+
function pascalCaseTransform(input, index) {
|
|
52
|
+
var firstChar = input.charAt(0);
|
|
53
|
+
var lowerChars = input.substr(1).toLowerCase();
|
|
54
|
+
if (index > 0 && firstChar >= "0" && firstChar <= "9") {
|
|
55
|
+
return "_" + firstChar + lowerChars;
|
|
56
|
+
}
|
|
57
|
+
return "" + firstChar.toUpperCase() + lowerChars;
|
|
58
|
+
}
|
|
59
|
+
function pascalCase(input, options) {
|
|
60
|
+
if (options === void 0) {
|
|
61
|
+
options = {};
|
|
62
|
+
}
|
|
63
|
+
return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ../carlin/src/deploy/lambdaLayer/getPackageLambdaLayerStackName.ts
|
|
67
|
+
var lambdaLayerStackNamePrefix = `LambdaLayer`;
|
|
68
|
+
var getPackageLambdaLayerStackName = (packageName) => {
|
|
69
|
+
const [scopedName, version] = packageName.split("@").filter((part) => {
|
|
70
|
+
return !!part;
|
|
71
|
+
});
|
|
72
|
+
return [
|
|
73
|
+
lambdaLayerStackNamePrefix,
|
|
74
|
+
pascalCase(scopedName),
|
|
75
|
+
version.replace(/[^0-9.]/g, "").replace(/\./g, "-")
|
|
76
|
+
].join("-");
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// package.json
|
|
80
|
+
var package_default = {
|
|
81
|
+
name: "@ttoss/appsync-api",
|
|
82
|
+
version: "0.7.5",
|
|
83
|
+
description: "A library for building GraphQL APIs for AWS AppSync.",
|
|
84
|
+
license: "UNLICENSED",
|
|
85
|
+
author: "ttoss",
|
|
86
|
+
contributors: [
|
|
87
|
+
"Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
|
|
88
|
+
],
|
|
89
|
+
exports: {
|
|
90
|
+
".": {
|
|
91
|
+
import: "./dist/esm/index.js",
|
|
92
|
+
require: "./dist/index.js"
|
|
93
|
+
},
|
|
94
|
+
"./server": {
|
|
95
|
+
import: "./dist/esm/server.js",
|
|
96
|
+
require: "./dist/server.js"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
main: "dist/index.js",
|
|
100
|
+
module: "dist/esm/index.js",
|
|
101
|
+
bin: {
|
|
102
|
+
"ttoss-appsync-api": "./bin/cli.js"
|
|
103
|
+
},
|
|
104
|
+
files: [
|
|
105
|
+
"dist",
|
|
106
|
+
"src"
|
|
107
|
+
],
|
|
108
|
+
scripts: {
|
|
109
|
+
build: "tsup",
|
|
110
|
+
test: "jest"
|
|
111
|
+
},
|
|
112
|
+
sideEffects: false,
|
|
113
|
+
typings: "dist/index.d.ts",
|
|
114
|
+
dependencies: {
|
|
115
|
+
"@ttoss/cloudformation": "^0.5.1",
|
|
116
|
+
express: "^4.18.2",
|
|
117
|
+
"graphql-helix": "^1.13.0",
|
|
118
|
+
minimist: "^1.2.7"
|
|
119
|
+
},
|
|
120
|
+
peerDependencies: {
|
|
121
|
+
graphql: "^16.6.0",
|
|
122
|
+
"graphql-compose": "^9.0.10"
|
|
123
|
+
},
|
|
124
|
+
devDependencies: {
|
|
125
|
+
"@ttoss/config": "^1.28.1",
|
|
126
|
+
"@types/aws-lambda": "^8.10.110",
|
|
127
|
+
carlin: "^1.23.2",
|
|
128
|
+
graphql: "^16.6.0",
|
|
129
|
+
"graphql-compose": "^9.0.10"
|
|
130
|
+
},
|
|
131
|
+
keywords: [
|
|
132
|
+
"api",
|
|
133
|
+
"appsync",
|
|
134
|
+
"aws",
|
|
135
|
+
"graphql"
|
|
136
|
+
],
|
|
137
|
+
publishConfig: {
|
|
138
|
+
access: "public"
|
|
139
|
+
},
|
|
140
|
+
typesVersions: {
|
|
141
|
+
"*": {
|
|
142
|
+
".": [
|
|
143
|
+
"./dist/index.d.ts"
|
|
144
|
+
],
|
|
145
|
+
server: [
|
|
146
|
+
"./dist/server.d.ts"
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/createApiTemplate.ts
|
|
153
|
+
var AppSyncGraphQLApiLogicalId = "AppSyncGraphQLApi";
|
|
154
|
+
var AppSyncGraphQLSchemaLogicalId = "AppSyncGraphQLSchema";
|
|
155
|
+
var AppSyncLambdaFunctionLogicalId = "AppSyncLambdaFunction";
|
|
156
|
+
var AppSyncLambdaFunctionAppSyncDataSourceLogicalId = "AppSyncLambdaFunctionAppSyncDataSource";
|
|
157
|
+
var AppSyncGraphQLApiKeyLogicalId = "AppSyncGraphQLApiKey";
|
|
158
|
+
var createApiTemplate = ({
|
|
159
|
+
additionalAuthenticationProviders,
|
|
160
|
+
authenticationType = "AMAZON_COGNITO_USER_POOLS",
|
|
161
|
+
schemaComposer,
|
|
162
|
+
dataSource,
|
|
163
|
+
lambdaFunction,
|
|
164
|
+
userPoolConfig
|
|
165
|
+
}) => {
|
|
166
|
+
const sdl = schemaComposer.toSDL();
|
|
167
|
+
graphql.validateSchema(schemaComposer.buildSchema());
|
|
168
|
+
const resolveMethods = schemaComposer.getResolveMethods();
|
|
169
|
+
const resolveMethodsEntries = Object.entries(resolveMethods).flatMap(
|
|
170
|
+
([typeName, fieldResolvers]) => {
|
|
171
|
+
return Object.entries(fieldResolvers).map(([fieldName]) => {
|
|
172
|
+
return {
|
|
173
|
+
fieldName,
|
|
174
|
+
typeName
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
const getGraphQLComposeDependenciesLambdaLayers = () => {
|
|
180
|
+
const { peerDependencies } = package_default;
|
|
181
|
+
const lambdaLayerStackNames = Object.entries(peerDependencies).map(
|
|
182
|
+
([dependencyName, dependencyVersion]) => {
|
|
183
|
+
return getPackageLambdaLayerStackName(
|
|
184
|
+
[dependencyName, dependencyVersion].join("@")
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
return lambdaLayerStackNames.map((lambdaLayerStackName) => {
|
|
189
|
+
return {
|
|
190
|
+
"Fn::ImportValue": lambdaLayerStackName
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
const template = {
|
|
195
|
+
AWSTemplateFormatVersion: "2010-09-09",
|
|
196
|
+
Parameters: {
|
|
197
|
+
Environment: {
|
|
198
|
+
Default: "Staging",
|
|
199
|
+
Type: "String",
|
|
200
|
+
AllowedValues: ["Staging", "Production"]
|
|
201
|
+
},
|
|
202
|
+
LambdaS3Bucket: {
|
|
203
|
+
Type: "String"
|
|
204
|
+
},
|
|
205
|
+
LambdaS3Key: {
|
|
206
|
+
Type: "String"
|
|
207
|
+
},
|
|
208
|
+
LambdaS3ObjectVersion: {
|
|
209
|
+
Type: "String"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
Resources: {
|
|
213
|
+
[AppSyncGraphQLApiLogicalId]: {
|
|
214
|
+
Type: "AWS::AppSync::GraphQLApi",
|
|
215
|
+
Properties: {
|
|
216
|
+
AuthenticationType: authenticationType,
|
|
217
|
+
Name: {
|
|
218
|
+
"Fn::Join": [
|
|
219
|
+
":",
|
|
220
|
+
[{ Ref: "AWS::StackName" }, AppSyncGraphQLApiLogicalId]
|
|
221
|
+
]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
[AppSyncGraphQLSchemaLogicalId]: {
|
|
226
|
+
Type: "AWS::AppSync::GraphQLSchema",
|
|
227
|
+
Properties: {
|
|
228
|
+
ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
|
|
229
|
+
Definition: sdl
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
[AppSyncLambdaFunctionLogicalId]: {
|
|
233
|
+
Type: "AWS::Lambda::Function",
|
|
234
|
+
Properties: {
|
|
235
|
+
Code: {
|
|
236
|
+
S3Bucket: { Ref: "LambdaS3Bucket" },
|
|
237
|
+
S3Key: { Ref: "LambdaS3Key" },
|
|
238
|
+
S3ObjectVersion: { Ref: "LambdaS3ObjectVersion" }
|
|
239
|
+
},
|
|
240
|
+
Handler: "index.handler",
|
|
241
|
+
Layers: getGraphQLComposeDependenciesLambdaLayers(),
|
|
242
|
+
MemorySize: 512,
|
|
243
|
+
Role: lambdaFunction.roleArn,
|
|
244
|
+
Runtime: "nodejs18.x",
|
|
245
|
+
/**
|
|
246
|
+
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
247
|
+
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
248
|
+
*/
|
|
249
|
+
Timeout: 29
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
[AppSyncLambdaFunctionAppSyncDataSourceLogicalId]: {
|
|
253
|
+
Type: "AWS::AppSync::DataSource",
|
|
254
|
+
Properties: {
|
|
255
|
+
ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
|
|
256
|
+
LambdaConfig: {
|
|
257
|
+
LambdaFunctionArn: {
|
|
258
|
+
"Fn::GetAtt": [AppSyncLambdaFunctionLogicalId, "Arn"]
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
Name: "AppSyncLambdaFunctionAppSyncDataSource",
|
|
262
|
+
ServiceRoleArn: dataSource.roleArn,
|
|
263
|
+
Type: "AWS_LAMBDA"
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
Outputs: {
|
|
268
|
+
AppSyncApiGraphQLUrl: {
|
|
269
|
+
Export: {
|
|
270
|
+
Name: {
|
|
271
|
+
"Fn::Join": [
|
|
272
|
+
":",
|
|
273
|
+
[{ Ref: "AWS::StackName" }, "AppSyncApiGraphQLUrl"]
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
Value: {
|
|
278
|
+
"Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "GraphQLUrl"]
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
AppSyncApiArn: {
|
|
282
|
+
Export: {
|
|
283
|
+
Name: {
|
|
284
|
+
"Fn::Join": [":", [{ Ref: "AWS::StackName" }, "AppSyncApiArn"]]
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
Value: {
|
|
288
|
+
"Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "Arn"]
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
resolveMethodsEntries.forEach(({ fieldName, typeName }) => {
|
|
294
|
+
template.Resources[`${fieldName}${typeName}AppSyncResolver`] = {
|
|
295
|
+
Type: "AWS::AppSync::Resolver",
|
|
296
|
+
DependsOn: AppSyncGraphQLSchemaLogicalId,
|
|
297
|
+
Properties: {
|
|
298
|
+
ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
|
|
299
|
+
FieldName: fieldName,
|
|
300
|
+
TypeName: typeName,
|
|
301
|
+
DataSourceName: {
|
|
302
|
+
"Fn::GetAtt": [
|
|
303
|
+
AppSyncLambdaFunctionAppSyncDataSourceLogicalId,
|
|
304
|
+
"Name"
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
const apiKey = additionalAuthenticationProviders?.includes("API_KEY") || authenticationType === "API_KEY";
|
|
311
|
+
const cognitoUserPoolAuth = additionalAuthenticationProviders?.includes("AMAZON_COGNITO_USER_POOLS") || authenticationType === "AMAZON_COGNITO_USER_POOLS";
|
|
312
|
+
if (additionalAuthenticationProviders) {
|
|
313
|
+
template.Resources[AppSyncGraphQLApiLogicalId].Properties.AdditionalAuthenticationProviders = additionalAuthenticationProviders?.map((provider) => {
|
|
314
|
+
return {
|
|
315
|
+
AuthenticationType: provider
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (apiKey) {
|
|
320
|
+
template.Resources[AppSyncGraphQLApiKeyLogicalId] = {
|
|
321
|
+
Type: "AWS::AppSync::ApiKey",
|
|
322
|
+
Properties: {
|
|
323
|
+
ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] }
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
if (!template.Outputs) {
|
|
327
|
+
template.Outputs = {};
|
|
328
|
+
}
|
|
329
|
+
template.Outputs[AppSyncGraphQLApiKeyLogicalId] = {
|
|
330
|
+
Value: {
|
|
331
|
+
"Fn::GetAtt": [AppSyncGraphQLApiKeyLogicalId, "ApiKey"]
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
if (cognitoUserPoolAuth) {
|
|
336
|
+
if (!userPoolConfig) {
|
|
337
|
+
throw new Error(
|
|
338
|
+
"userPoolConfig is required when using AMAZON_COGNITO_USER_POOLS authentication."
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
template.Resources[AppSyncGraphQLApiLogicalId].Properties.UserPoolConfig = {
|
|
342
|
+
AppIdClientRegex: userPoolConfig.appIdClientRegex,
|
|
343
|
+
AwsRegion: userPoolConfig.awsRegion,
|
|
344
|
+
DefaultAction: userPoolConfig.defaultAction,
|
|
345
|
+
UserPoolId: userPoolConfig.userPoolId
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (lambdaFunction.environment?.variables) {
|
|
349
|
+
template.Resources[AppSyncLambdaFunctionLogicalId].Properties.Environment = {
|
|
350
|
+
Variables: lambdaFunction.environment.variables
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return template;
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
AppSyncGraphQLSchemaLogicalId,
|
|
358
|
+
createApiTemplate
|
|
359
|
+
};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
import {
|
|
3
3
|
AppSyncGraphQLSchemaLogicalId
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-NQOARNEJ.js";
|
|
4
|
+
} from "./chunk-CXLYPHQJ.js";
|
|
6
5
|
|
|
7
6
|
// src/cli.ts
|
|
8
7
|
import * as fs from "fs";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
import {
|
|
3
3
|
createApiTemplate
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-NQOARNEJ.js";
|
|
4
|
+
} from "./chunk-CXLYPHQJ.js";
|
|
6
5
|
|
|
7
6
|
// src/createAppSyncResolverHandler.ts
|
|
8
7
|
var createAppSyncResolverHandler = ({
|