@ttoss/appsync-api 0.3.0 → 0.3.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/esm/cli.js CHANGED
@@ -1,11 +1,13 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import {
3
+ AppSyncGraphQLSchemaLogicalId
4
+ } from "./chunk-ZDHV6GQI.js";
2
5
 
3
6
  // src/cli.ts
4
7
  import * as fs from "fs";
5
8
  import { findAndReadCloudFormationTemplate } from "@ttoss/cloudformation";
6
9
  import minimist from "minimist";
7
10
  var argv = minimist(process.argv.slice(2));
8
- var AppSyncGraphQLSchemaLogicalId = "AppSyncGraphQLSchema";
9
11
  if (argv._.includes("build-schema")) {
10
12
  const template = findAndReadCloudFormationTemplate({});
11
13
  const sdl = template.Resources[AppSyncGraphQLSchemaLogicalId].Properties.Definition;
package/dist/esm/index.js CHANGED
@@ -1,252 +1,11 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import {
3
+ createApiTemplate
4
+ } from "./chunk-ZDHV6GQI.js";
2
5
 
3
6
  // src/index.ts
4
7
  import { schemaComposer } from "graphql-compose";
5
8
 
6
- // src/createApiTemplate.ts
7
- import { getPackageLambdaLayerStackName } from "carlin/src/deploy/lambdaLayer/getPackageLambdaLayerStackName";
8
- import { readPackageJson } from "carlin/src/utils/packageJson";
9
-
10
- // package.json
11
- var package_default = {
12
- name: "@ttoss/appsync-api",
13
- version: "0.3.0",
14
- description: "",
15
- license: "UNLICENSED",
16
- author: "ttoss",
17
- contributors: [
18
- "Pedro Arantes <pedro@arantespp.com> (https://arantespp.com)"
19
- ],
20
- main: "dist/index.js",
21
- module: "dist/esm/index.js",
22
- bin: {
23
- "ttoss-appsync-api": "./bin/cli.js"
24
- },
25
- files: [
26
- "dist",
27
- "src"
28
- ],
29
- scripts: {
30
- build: "tsup",
31
- test: "jest"
32
- },
33
- typings: "dist/index.d.ts",
34
- dependencies: {
35
- "@ttoss/cloudformation": "^0.2.0",
36
- graphql: "^16.6.0",
37
- "graphql-compose": "^9.0.10",
38
- minimist: "^1.2.7"
39
- },
40
- devDependencies: {
41
- "@ttoss/config": "^1.25.0",
42
- "@types/aws-lambda": "^8.10.109"
43
- },
44
- keywords: [],
45
- publishConfig: {
46
- access: "public"
47
- }
48
- };
49
-
50
- // src/createApiTemplate.ts
51
- var AppSyncGraphQLApiLogicalId = "AppSyncGraphQLApi";
52
- var AppSyncGraphQLSchemaLogicalId = "AppSyncGraphQLSchema";
53
- var AppSyncLambdaFunctionIAMRoleLogicalId = "AppSyncLambdaFunctionIAMRole";
54
- var AppSyncLambdaFunctionLogicalId = "AppSyncLambdaFunction";
55
- var AppSyncLambdaFunctionAppSyncDataSourceIAMRoleLogicalId = "AppSyncLambdaFunctionAppSyncDataSourceIAMRole";
56
- var AppSyncLambdaFunctionAppSyncDataSourceLogicalId = "AppSyncLambdaFunctionAppSyncDataSource";
57
- var createApiTemplate = ({
58
- schemaComposer: schemaComposer2
59
- }) => {
60
- const sdl = schemaComposer2.toSDL();
61
- const resolveMethods = schemaComposer2.getResolveMethods();
62
- const resolveMethodsEntries = Object.entries(resolveMethods).flatMap(
63
- ([typeName, fieldResolvers]) => {
64
- return Object.entries(fieldResolvers).map(([fieldName]) => {
65
- return {
66
- fieldName,
67
- typeName
68
- };
69
- });
70
- }
71
- );
72
- const { name } = package_default;
73
- const { dependencies } = readPackageJson();
74
- const dependencyVersion = dependencies[name];
75
- if (!dependencyVersion) {
76
- throw new Error(
77
- `The package ${name} is not installed in the project. Please install it with "yarn add ${name}".`
78
- );
79
- }
80
- const lambdaLayerStackName = getPackageLambdaLayerStackName(
81
- [name, dependencyVersion].join("@")
82
- );
83
- const template = {
84
- AWSTemplateFormatVersion: "2010-09-09",
85
- Parameters: {
86
- Environment: {
87
- Default: "Staging",
88
- Type: "String",
89
- AllowedValues: ["Staging", "Production"]
90
- },
91
- LambdaS3Bucket: {
92
- Type: "String"
93
- },
94
- LambdaS3Key: {
95
- Type: "String"
96
- },
97
- LambdaS3ObjectVersion: {
98
- Type: "String"
99
- }
100
- },
101
- Resources: {
102
- [AppSyncGraphQLApiLogicalId]: {
103
- Type: "AWS::AppSync::GraphQLApi",
104
- Properties: {
105
- AuthenticationType: "API_KEY",
106
- Name: {
107
- "Fn::Join": [
108
- ":",
109
- [{ Ref: "AWS::StackName" }, AppSyncGraphQLApiLogicalId]
110
- ]
111
- }
112
- }
113
- },
114
- [AppSyncGraphQLSchemaLogicalId]: {
115
- Type: "AWS::AppSync::GraphQLSchema",
116
- Properties: {
117
- ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
118
- Definition: sdl
119
- }
120
- },
121
- [AppSyncLambdaFunctionIAMRoleLogicalId]: {
122
- Type: "AWS::IAM::Role",
123
- Properties: {
124
- AssumeRolePolicyDocument: {
125
- Version: "2012-10-17",
126
- Statement: [
127
- {
128
- Effect: "Allow",
129
- Action: "sts:AssumeRole",
130
- Principal: {
131
- Service: "lambda.amazonaws.com"
132
- }
133
- }
134
- ]
135
- },
136
- ManagedPolicyArns: [
137
- "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
138
- ],
139
- Path: "/custom-iam/"
140
- }
141
- },
142
- [AppSyncLambdaFunctionLogicalId]: {
143
- Type: "AWS::Lambda::Function",
144
- Properties: {
145
- Code: {
146
- S3Bucket: { Ref: "LambdaS3Bucket" },
147
- S3Key: { Ref: "LambdaS3Key" },
148
- S3ObjectVersion: { Ref: "LambdaS3ObjectVersion" }
149
- },
150
- Handler: "index.handler",
151
- Layers: [
152
- {
153
- "Fn::ImportValue": lambdaLayerStackName
154
- }
155
- ],
156
- MemorySize: 512,
157
- Role: {
158
- "Fn::GetAtt": [AppSyncLambdaFunctionIAMRoleLogicalId, "Arn"]
159
- },
160
- Runtime: "nodejs18.x",
161
- Timeout: 29
162
- }
163
- },
164
- [AppSyncLambdaFunctionAppSyncDataSourceIAMRoleLogicalId]: {
165
- Type: "AWS::IAM::Role",
166
- Properties: {
167
- AssumeRolePolicyDocument: {
168
- Version: "2012-10-17",
169
- Statement: [
170
- {
171
- Effect: "Allow",
172
- Action: "sts:AssumeRole",
173
- Principal: {
174
- Service: "appsync.amazonaws.com"
175
- }
176
- }
177
- ]
178
- },
179
- ManagedPolicyArns: [
180
- "arn:aws:iam::aws:policy/service-role/AWSAppSyncPushToCloudWatchLogs"
181
- ],
182
- Path: "/custom-iam/",
183
- Policies: [
184
- {
185
- PolicyName: "AppSyncGraphQLApiIAMRolePolicyName",
186
- PolicyDocument: {
187
- Version: "2012-10-17",
188
- Statement: [
189
- {
190
- Effect: "Allow",
191
- Action: ["lambda:InvokeFunction"],
192
- Resource: [
193
- { "Fn::GetAtt": [AppSyncLambdaFunctionLogicalId, "Arn"] }
194
- ]
195
- }
196
- ]
197
- }
198
- }
199
- ]
200
- }
201
- },
202
- [AppSyncLambdaFunctionAppSyncDataSourceLogicalId]: {
203
- Type: "AWS::AppSync::DataSource",
204
- Properties: {
205
- ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
206
- LambdaConfig: {
207
- LambdaFunctionArn: {
208
- "Fn::GetAtt": [AppSyncLambdaFunctionLogicalId, "Arn"]
209
- }
210
- },
211
- Name: "AppSyncLambdaFunctionAppSyncDataSource",
212
- ServiceRoleArn: {
213
- "Fn::GetAtt": [
214
- AppSyncLambdaFunctionAppSyncDataSourceIAMRoleLogicalId,
215
- "Arn"
216
- ]
217
- },
218
- Type: "AWS_LAMBDA"
219
- }
220
- }
221
- },
222
- Outputs: {
223
- [AppSyncGraphQLApiLogicalId]: {
224
- Value: {
225
- "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "GraphQLUrl"]
226
- }
227
- }
228
- }
229
- };
230
- resolveMethodsEntries.forEach(({ fieldName, typeName }) => {
231
- template.Resources[`${fieldName}${typeName}AppSyncResolver`] = {
232
- Type: "AWS::AppSync::Resolver",
233
- DependsOn: AppSyncGraphQLSchemaLogicalId,
234
- Properties: {
235
- ApiId: { "Fn::GetAtt": [AppSyncGraphQLApiLogicalId, "ApiId"] },
236
- FieldName: fieldName,
237
- TypeName: typeName,
238
- DataSourceName: {
239
- "Fn::GetAtt": [
240
- AppSyncLambdaFunctionAppSyncDataSourceLogicalId,
241
- "Name"
242
- ]
243
- }
244
- }
245
- };
246
- });
247
- return template;
248
- };
249
-
250
9
  // src/appSyncResolverHandler.ts
251
10
  var appSyncResolverHandler = ({
252
11
  schemaComposer: schemaComposer2