@ttoss/appsync-api 0.22.14 → 0.23.0
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/README.md +52 -0
- package/dist/esm/index.js +31 -11
- package/dist/index.d.mts +54 -3
- package/dist/index.d.ts +54 -3
- package/dist/index.js +48 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -69,6 +69,58 @@ The `createAppSyncResolverHandler` function adds the `context` object to the res
|
|
|
69
69
|
- `request` - AppSync request object (see [Request section](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference-js.html)).
|
|
70
70
|
- `identity` - AppSync identity object (see [Identity section](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference-js.html)).
|
|
71
71
|
|
|
72
|
+
### createContext
|
|
73
|
+
|
|
74
|
+
Use `createContext` to enrich the resolver context once per request. Its return value is shallow-merged into the base context, making it available to every resolver. This is the recommended way to resolve per-request values like a `userId` from Cognito:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { createAppSyncResolverHandler } from '@ttoss/appsync-api';
|
|
78
|
+
import { schemaComposer } from './schemaComposer';
|
|
79
|
+
import { getUserIdFromCognitoSub } from './auth';
|
|
80
|
+
|
|
81
|
+
export const handler = createAppSyncResolverHandler({
|
|
82
|
+
schemaComposer,
|
|
83
|
+
createContext: async ({ identity }) => ({
|
|
84
|
+
userId: await getUserIdFromCognitoSub(identity?.sub),
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Every resolver then receives `context.userId` without having to derive it individually.
|
|
90
|
+
|
|
91
|
+
### Middlewares
|
|
92
|
+
|
|
93
|
+
You can use [`graphql-middleware`](https://github.com/dimatill/graphql-middleware)-compatible middlewares via the `middlewares` option. Each middleware wraps the resolver — code before `resolve()` runs **before** the resolver, code after runs **after**.
|
|
94
|
+
|
|
95
|
+
In AppSync, each Lambda invocation handles a single field, so a middleware runs exactly once per request.
|
|
96
|
+
Use `middlewares` for authorization rules or cross-cutting logic (logging, tracing). Combine with `createContext` for per-request context enrichment:
|
|
97
|
+
|
|
98
|
+
| | `createContext` | `middlewares` |
|
|
99
|
+
| ------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
100
|
+
| Runs | Once per request | Once per resolver call |
|
|
101
|
+
| Purpose | Enrich context (e.g. `userId`) | Auth rules, logging, before/after logic |
|
|
102
|
+
| Can block execution | On error (request fails if `createContext` rejects/throws) | Yes (can conditionally block by not calling `resolve` or throwing) |
|
|
103
|
+
|
|
104
|
+
#### Authorization with GraphQL Shield
|
|
105
|
+
|
|
106
|
+
Use [GraphQL Shield](https://the-guild.dev/graphql/shield) to add authorization rules:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { allow, deny, shield } from '@ttoss/graphql-api/shield';
|
|
110
|
+
|
|
111
|
+
const permissions = shield(
|
|
112
|
+
{
|
|
113
|
+
Query: { '*': deny, me: allow },
|
|
114
|
+
},
|
|
115
|
+
{ fallbackRule: deny }
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
export const handler = createAppSyncResolverHandler({
|
|
119
|
+
schemaComposer,
|
|
120
|
+
middlewares: [permissions],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
72
124
|
### Custom domain name
|
|
73
125
|
|
|
74
126
|
You can add a custom domain name to your API using the `customDomain` option.
|
package/dist/esm/index.js
CHANGED
|
@@ -15,19 +15,19 @@ var AppSyncGraphQLApiKeyLogicalId = "AppSyncGraphQLApiKey";
|
|
|
15
15
|
var createApiTemplate = /* @__PURE__ */__name(({
|
|
16
16
|
additionalAuthenticationProviders,
|
|
17
17
|
authenticationType = "AMAZON_COGNITO_USER_POOLS",
|
|
18
|
-
schemaComposer,
|
|
18
|
+
schemaComposer: schemaComposer2,
|
|
19
19
|
dataSource,
|
|
20
20
|
lambdaFunction,
|
|
21
21
|
userPoolConfig,
|
|
22
22
|
customDomain
|
|
23
23
|
}) => {
|
|
24
|
-
const sdlWithoutComments =
|
|
24
|
+
const sdlWithoutComments = schemaComposer2.toSDL({
|
|
25
25
|
commentDescriptions: false,
|
|
26
26
|
omitDescriptions: true,
|
|
27
27
|
omitScalars: true
|
|
28
28
|
});
|
|
29
|
-
graphql.validateSchema(
|
|
30
|
-
const resolveMethods =
|
|
29
|
+
graphql.validateSchema(schemaComposer2.buildSchema());
|
|
30
|
+
const resolveMethods = schemaComposer2.getResolveMethods();
|
|
31
31
|
const resolveMethodsEntries = Object.entries(resolveMethods).flatMap(([typeName, fieldResolvers]) => {
|
|
32
32
|
return Object.entries(fieldResolvers).map(([fieldName, resolver]) => {
|
|
33
33
|
if (typeof resolver !== "function") {
|
|
@@ -100,12 +100,15 @@ var createApiTemplate = /* @__PURE__ */__name(({
|
|
|
100
100
|
Layers: lambdaFunction.layers,
|
|
101
101
|
MemorySize: 512,
|
|
102
102
|
Role: lambdaFunction.roleArn,
|
|
103
|
-
|
|
103
|
+
/**
|
|
104
|
+
* https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtimes-supported
|
|
105
|
+
*/
|
|
106
|
+
Runtime: "nodejs24.x",
|
|
104
107
|
/**
|
|
105
108
|
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
106
109
|
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
107
110
|
*/
|
|
108
|
-
Timeout:
|
|
111
|
+
Timeout: 30
|
|
109
112
|
}
|
|
110
113
|
},
|
|
111
114
|
[AppSyncLambdaFunctionAppSyncDataSourceLogicalId]: {
|
|
@@ -281,11 +284,12 @@ var createApiTemplate = /* @__PURE__ */__name(({
|
|
|
281
284
|
// src/createAppSyncResolverHandler.ts
|
|
282
285
|
import { buildSchema } from "@ttoss/graphql-api";
|
|
283
286
|
var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
287
|
+
createContext,
|
|
284
288
|
...buildSchemaInput
|
|
285
289
|
}) => {
|
|
286
290
|
return async (event, appSyncHandlerContext) => {
|
|
287
291
|
const {
|
|
288
|
-
schemaComposer
|
|
292
|
+
schemaComposer: schemaComposer2
|
|
289
293
|
} = buildSchemaInput;
|
|
290
294
|
const {
|
|
291
295
|
info,
|
|
@@ -297,11 +301,15 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
297
301
|
parentTypeName,
|
|
298
302
|
fieldName
|
|
299
303
|
} = info;
|
|
300
|
-
const
|
|
304
|
+
const baseContext = {
|
|
301
305
|
handler: appSyncHandlerContext,
|
|
302
306
|
request,
|
|
303
307
|
identity: event.identity
|
|
304
308
|
};
|
|
309
|
+
const context = createContext ? {
|
|
310
|
+
...baseContext,
|
|
311
|
+
...(await createContext(baseContext))
|
|
312
|
+
} : baseContext;
|
|
305
313
|
const schema = buildSchema(buildSchemaInput);
|
|
306
314
|
const parentType = schema.getType(parentTypeName);
|
|
307
315
|
if (!parentType) {
|
|
@@ -314,7 +322,7 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
314
322
|
}
|
|
315
323
|
const argsWithEnumValues = (() => {
|
|
316
324
|
const fieldsArgsIsEnumType = field.args.filter(arg => {
|
|
317
|
-
return
|
|
325
|
+
return schemaComposer2.isEnumType(arg.type);
|
|
318
326
|
});
|
|
319
327
|
const enumArgs = fieldsArgsIsEnumType.map(enumArg => {
|
|
320
328
|
if (!args[enumArg.name]) {
|
|
@@ -322,7 +330,7 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
322
330
|
[enumArg.name]: enumArg.defaultValue
|
|
323
331
|
};
|
|
324
332
|
}
|
|
325
|
-
const values =
|
|
333
|
+
const values = schemaComposer2.getETC(enumArg.type).getFields();
|
|
326
334
|
return {
|
|
327
335
|
[enumArg.name]: values[args[enumArg.name]].value
|
|
328
336
|
};
|
|
@@ -344,4 +352,16 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
344
352
|
return response;
|
|
345
353
|
};
|
|
346
354
|
}, "createAppSyncResolverHandler");
|
|
347
|
-
|
|
355
|
+
|
|
356
|
+
// src/scalars.ts
|
|
357
|
+
import { schemaComposer } from "@ttoss/graphql-api";
|
|
358
|
+
var AWSJSONTC = schemaComposer.createScalarTC(`scalar AWSJSON`);
|
|
359
|
+
var AWSDateTimeTC = schemaComposer.createScalarTC(`scalar AWSDateTime`);
|
|
360
|
+
var AWSDateTC = schemaComposer.createScalarTC(`scalar AWSDate`);
|
|
361
|
+
var AWSTimeTC = schemaComposer.createScalarTC(`scalar AWSTime`);
|
|
362
|
+
var AWSTimestampTC = schemaComposer.createScalarTC(`scalar AWSTimestamp`);
|
|
363
|
+
var AWSEmailTC = schemaComposer.createScalarTC(`scalar AWSEmail`);
|
|
364
|
+
var AWSURLTC = schemaComposer.createScalarTC(`scalar AWSURL`);
|
|
365
|
+
var AWSPhoneTC = schemaComposer.createScalarTC(`scalar AWSPhone`);
|
|
366
|
+
var AWSIPAddressTC = schemaComposer.createScalarTC(`scalar AWSIPAddress`);
|
|
367
|
+
export { AWSDateTC, AWSDateTimeTC, AWSEmailTC, AWSIPAddressTC, AWSJSONTC, AWSPhoneTC, AWSTimeTC, AWSTimestampTC, AWSURLTC, createApiTemplate, createAppSyncResolverHandler };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as _ttoss_graphql_api from '@ttoss/graphql-api';
|
|
1
2
|
import { SchemaComposer, BuildSchemaInput } from '@ttoss/graphql-api';
|
|
2
|
-
import { AppSyncResolverHandler as AppSyncResolverHandler$1 } from 'aws-lambda';
|
|
3
|
+
import { AppSyncResolverHandler as AppSyncResolverHandler$1, Context, AppSyncIdentity } from 'aws-lambda';
|
|
3
4
|
export { AppSyncIdentityCognito } from 'aws-lambda';
|
|
4
5
|
|
|
5
6
|
type CloudFormationRef = {
|
|
@@ -109,6 +110,56 @@ declare const createApiTemplate: ({ additionalAuthenticationProviders, authentic
|
|
|
109
110
|
}) => CloudFormationTemplate;
|
|
110
111
|
|
|
111
112
|
type AppSyncResolverHandler<TArguments, TResult, TSource = Record<string, any> | null> = AppSyncResolverHandler$1<TArguments, TResult, TSource>;
|
|
112
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The base context object passed to all AppSync resolvers.
|
|
115
|
+
*/
|
|
116
|
+
type BaseAppSyncContext = {
|
|
117
|
+
/** The raw Lambda invocation context. */
|
|
118
|
+
handler: Context;
|
|
119
|
+
/** The AppSync request object (includes headers). */
|
|
120
|
+
request: any;
|
|
121
|
+
/** The caller's identity (Cognito, IAM, Lambda, or OIDC). Null when using API key auth. */
|
|
122
|
+
identity: AppSyncIdentity | null | undefined;
|
|
123
|
+
};
|
|
124
|
+
declare const createAppSyncResolverHandler: ({ createContext, ...buildSchemaInput }: BuildSchemaInput & {
|
|
125
|
+
/**
|
|
126
|
+
* Optional async function called once per request to enrich the resolver
|
|
127
|
+
* context. The returned object is shallow-merged into the base context and
|
|
128
|
+
* made available to every resolver.
|
|
129
|
+
*
|
|
130
|
+
* Use this for per-request setup such as resolving a `userId` from Cognito.
|
|
131
|
+
* For authorization rules or before/after resolver logic, prefer `middlewares`.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* createAppSyncResolverHandler({
|
|
136
|
+
* schemaComposer,
|
|
137
|
+
* createContext: async ({ identity }) => ({
|
|
138
|
+
* userId: await getUserIdFromCognitoSub(identity?.sub),
|
|
139
|
+
* }),
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
createContext?: (baseContext: BaseAppSyncContext) => Promise<Record<string, any>> | Record<string, any>;
|
|
144
|
+
}) => AppSyncResolverHandler<any, any, any>;
|
|
145
|
+
|
|
146
|
+
/** AWS AppSync scalar for JSON data. Represents a JSON object or array. */
|
|
147
|
+
declare const AWSJSONTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
148
|
+
/** AWS AppSync scalar for combined date and time values (ISO 8601, e.g. `2007-04-05T14:30:28Z`). */
|
|
149
|
+
declare const AWSDateTimeTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
150
|
+
/** AWS AppSync scalar for date values (ISO 8601, e.g. `1970-01-01`). */
|
|
151
|
+
declare const AWSDateTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
152
|
+
/** AWS AppSync scalar for time values (ISO 8601, e.g. `12:30:00.000Z`). */
|
|
153
|
+
declare const AWSTimeTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
154
|
+
/** AWS AppSync scalar for Unix epoch timestamps (integer, seconds since 1970-01-01T00:00:00Z). */
|
|
155
|
+
declare const AWSTimestampTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
156
|
+
/** AWS AppSync scalar for email addresses (RFC 822). */
|
|
157
|
+
declare const AWSEmailTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
158
|
+
/** AWS AppSync scalar for URLs (RFC 1738). */
|
|
159
|
+
declare const AWSURLTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
160
|
+
/** AWS AppSync scalar for phone numbers (E.164 format). */
|
|
161
|
+
declare const AWSPhoneTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
162
|
+
/** AWS AppSync scalar for IPv4 and IPv6 addresses. */
|
|
163
|
+
declare const AWSIPAddressTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
113
164
|
|
|
114
|
-
export { type AppSyncResolverHandler, createApiTemplate, createAppSyncResolverHandler };
|
|
165
|
+
export { AWSDateTC, AWSDateTimeTC, AWSEmailTC, AWSIPAddressTC, AWSJSONTC, AWSPhoneTC, AWSTimeTC, AWSTimestampTC, AWSURLTC, type AppSyncResolverHandler, type BaseAppSyncContext, createApiTemplate, createAppSyncResolverHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as _ttoss_graphql_api from '@ttoss/graphql-api';
|
|
1
2
|
import { SchemaComposer, BuildSchemaInput } from '@ttoss/graphql-api';
|
|
2
|
-
import { AppSyncResolverHandler as AppSyncResolverHandler$1 } from 'aws-lambda';
|
|
3
|
+
import { AppSyncResolverHandler as AppSyncResolverHandler$1, Context, AppSyncIdentity } from 'aws-lambda';
|
|
3
4
|
export { AppSyncIdentityCognito } from 'aws-lambda';
|
|
4
5
|
|
|
5
6
|
type CloudFormationRef = {
|
|
@@ -109,6 +110,56 @@ declare const createApiTemplate: ({ additionalAuthenticationProviders, authentic
|
|
|
109
110
|
}) => CloudFormationTemplate;
|
|
110
111
|
|
|
111
112
|
type AppSyncResolverHandler<TArguments, TResult, TSource = Record<string, any> | null> = AppSyncResolverHandler$1<TArguments, TResult, TSource>;
|
|
112
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The base context object passed to all AppSync resolvers.
|
|
115
|
+
*/
|
|
116
|
+
type BaseAppSyncContext = {
|
|
117
|
+
/** The raw Lambda invocation context. */
|
|
118
|
+
handler: Context;
|
|
119
|
+
/** The AppSync request object (includes headers). */
|
|
120
|
+
request: any;
|
|
121
|
+
/** The caller's identity (Cognito, IAM, Lambda, or OIDC). Null when using API key auth. */
|
|
122
|
+
identity: AppSyncIdentity | null | undefined;
|
|
123
|
+
};
|
|
124
|
+
declare const createAppSyncResolverHandler: ({ createContext, ...buildSchemaInput }: BuildSchemaInput & {
|
|
125
|
+
/**
|
|
126
|
+
* Optional async function called once per request to enrich the resolver
|
|
127
|
+
* context. The returned object is shallow-merged into the base context and
|
|
128
|
+
* made available to every resolver.
|
|
129
|
+
*
|
|
130
|
+
* Use this for per-request setup such as resolving a `userId` from Cognito.
|
|
131
|
+
* For authorization rules or before/after resolver logic, prefer `middlewares`.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* createAppSyncResolverHandler({
|
|
136
|
+
* schemaComposer,
|
|
137
|
+
* createContext: async ({ identity }) => ({
|
|
138
|
+
* userId: await getUserIdFromCognitoSub(identity?.sub),
|
|
139
|
+
* }),
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
createContext?: (baseContext: BaseAppSyncContext) => Promise<Record<string, any>> | Record<string, any>;
|
|
144
|
+
}) => AppSyncResolverHandler<any, any, any>;
|
|
145
|
+
|
|
146
|
+
/** AWS AppSync scalar for JSON data. Represents a JSON object or array. */
|
|
147
|
+
declare const AWSJSONTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
148
|
+
/** AWS AppSync scalar for combined date and time values (ISO 8601, e.g. `2007-04-05T14:30:28Z`). */
|
|
149
|
+
declare const AWSDateTimeTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
150
|
+
/** AWS AppSync scalar for date values (ISO 8601, e.g. `1970-01-01`). */
|
|
151
|
+
declare const AWSDateTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
152
|
+
/** AWS AppSync scalar for time values (ISO 8601, e.g. `12:30:00.000Z`). */
|
|
153
|
+
declare const AWSTimeTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
154
|
+
/** AWS AppSync scalar for Unix epoch timestamps (integer, seconds since 1970-01-01T00:00:00Z). */
|
|
155
|
+
declare const AWSTimestampTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
156
|
+
/** AWS AppSync scalar for email addresses (RFC 822). */
|
|
157
|
+
declare const AWSEmailTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
158
|
+
/** AWS AppSync scalar for URLs (RFC 1738). */
|
|
159
|
+
declare const AWSURLTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
160
|
+
/** AWS AppSync scalar for phone numbers (E.164 format). */
|
|
161
|
+
declare const AWSPhoneTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
162
|
+
/** AWS AppSync scalar for IPv4 and IPv6 addresses. */
|
|
163
|
+
declare const AWSIPAddressTC: _ttoss_graphql_api.ScalarTypeComposer<any>;
|
|
113
164
|
|
|
114
|
-
export { type AppSyncResolverHandler, createApiTemplate, createAppSyncResolverHandler };
|
|
165
|
+
export { AWSDateTC, AWSDateTimeTC, AWSEmailTC, AWSIPAddressTC, AWSJSONTC, AWSPhoneTC, AWSTimeTC, AWSTimestampTC, AWSURLTC, type AppSyncResolverHandler, type BaseAppSyncContext, createApiTemplate, createAppSyncResolverHandler };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,15 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
+
AWSDateTC: () => AWSDateTC,
|
|
35
|
+
AWSDateTimeTC: () => AWSDateTimeTC,
|
|
36
|
+
AWSEmailTC: () => AWSEmailTC,
|
|
37
|
+
AWSIPAddressTC: () => AWSIPAddressTC,
|
|
38
|
+
AWSJSONTC: () => AWSJSONTC,
|
|
39
|
+
AWSPhoneTC: () => AWSPhoneTC,
|
|
40
|
+
AWSTimeTC: () => AWSTimeTC,
|
|
41
|
+
AWSTimestampTC: () => AWSTimestampTC,
|
|
42
|
+
AWSURLTC: () => AWSURLTC,
|
|
34
43
|
createApiTemplate: () => createApiTemplate,
|
|
35
44
|
createAppSyncResolverHandler: () => createAppSyncResolverHandler
|
|
36
45
|
});
|
|
@@ -46,19 +55,19 @@ var AppSyncGraphQLApiKeyLogicalId = "AppSyncGraphQLApiKey";
|
|
|
46
55
|
var createApiTemplate = /* @__PURE__ */__name(({
|
|
47
56
|
additionalAuthenticationProviders,
|
|
48
57
|
authenticationType = "AMAZON_COGNITO_USER_POOLS",
|
|
49
|
-
schemaComposer,
|
|
58
|
+
schemaComposer: schemaComposer2,
|
|
50
59
|
dataSource,
|
|
51
60
|
lambdaFunction,
|
|
52
61
|
userPoolConfig,
|
|
53
62
|
customDomain
|
|
54
63
|
}) => {
|
|
55
|
-
const sdlWithoutComments =
|
|
64
|
+
const sdlWithoutComments = schemaComposer2.toSDL({
|
|
56
65
|
commentDescriptions: false,
|
|
57
66
|
omitDescriptions: true,
|
|
58
67
|
omitScalars: true
|
|
59
68
|
});
|
|
60
|
-
import_graphql_api.graphql.validateSchema(
|
|
61
|
-
const resolveMethods =
|
|
69
|
+
import_graphql_api.graphql.validateSchema(schemaComposer2.buildSchema());
|
|
70
|
+
const resolveMethods = schemaComposer2.getResolveMethods();
|
|
62
71
|
const resolveMethodsEntries = Object.entries(resolveMethods).flatMap(([typeName, fieldResolvers]) => {
|
|
63
72
|
return Object.entries(fieldResolvers).map(([fieldName, resolver]) => {
|
|
64
73
|
if (typeof resolver !== "function") {
|
|
@@ -131,12 +140,15 @@ var createApiTemplate = /* @__PURE__ */__name(({
|
|
|
131
140
|
Layers: lambdaFunction.layers,
|
|
132
141
|
MemorySize: 512,
|
|
133
142
|
Role: lambdaFunction.roleArn,
|
|
134
|
-
|
|
143
|
+
/**
|
|
144
|
+
* https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtimes-supported
|
|
145
|
+
*/
|
|
146
|
+
Runtime: "nodejs24.x",
|
|
135
147
|
/**
|
|
136
148
|
* https://docs.aws.amazon.com/general/latest/gr/appsync.html
|
|
137
149
|
* Request execution time for mutations, queries, and subscriptions: 30 seconds
|
|
138
150
|
*/
|
|
139
|
-
Timeout:
|
|
151
|
+
Timeout: 30
|
|
140
152
|
}
|
|
141
153
|
},
|
|
142
154
|
[AppSyncLambdaFunctionAppSyncDataSourceLogicalId]: {
|
|
@@ -312,11 +324,12 @@ var createApiTemplate = /* @__PURE__ */__name(({
|
|
|
312
324
|
// src/createAppSyncResolverHandler.ts
|
|
313
325
|
var import_graphql_api2 = require("@ttoss/graphql-api");
|
|
314
326
|
var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
327
|
+
createContext,
|
|
315
328
|
...buildSchemaInput
|
|
316
329
|
}) => {
|
|
317
330
|
return async (event, appSyncHandlerContext) => {
|
|
318
331
|
const {
|
|
319
|
-
schemaComposer
|
|
332
|
+
schemaComposer: schemaComposer2
|
|
320
333
|
} = buildSchemaInput;
|
|
321
334
|
const {
|
|
322
335
|
info,
|
|
@@ -328,11 +341,15 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
328
341
|
parentTypeName,
|
|
329
342
|
fieldName
|
|
330
343
|
} = info;
|
|
331
|
-
const
|
|
344
|
+
const baseContext = {
|
|
332
345
|
handler: appSyncHandlerContext,
|
|
333
346
|
request,
|
|
334
347
|
identity: event.identity
|
|
335
348
|
};
|
|
349
|
+
const context = createContext ? {
|
|
350
|
+
...baseContext,
|
|
351
|
+
...(await createContext(baseContext))
|
|
352
|
+
} : baseContext;
|
|
336
353
|
const schema = (0, import_graphql_api2.buildSchema)(buildSchemaInput);
|
|
337
354
|
const parentType = schema.getType(parentTypeName);
|
|
338
355
|
if (!parentType) {
|
|
@@ -345,7 +362,7 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
345
362
|
}
|
|
346
363
|
const argsWithEnumValues = (() => {
|
|
347
364
|
const fieldsArgsIsEnumType = field.args.filter(arg => {
|
|
348
|
-
return
|
|
365
|
+
return schemaComposer2.isEnumType(arg.type);
|
|
349
366
|
});
|
|
350
367
|
const enumArgs = fieldsArgsIsEnumType.map(enumArg => {
|
|
351
368
|
if (!args[enumArg.name]) {
|
|
@@ -353,7 +370,7 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
353
370
|
[enumArg.name]: enumArg.defaultValue
|
|
354
371
|
};
|
|
355
372
|
}
|
|
356
|
-
const values =
|
|
373
|
+
const values = schemaComposer2.getETC(enumArg.type).getFields();
|
|
357
374
|
return {
|
|
358
375
|
[enumArg.name]: values[args[enumArg.name]].value
|
|
359
376
|
};
|
|
@@ -375,8 +392,29 @@ var createAppSyncResolverHandler = /* @__PURE__ */__name(({
|
|
|
375
392
|
return response;
|
|
376
393
|
};
|
|
377
394
|
}, "createAppSyncResolverHandler");
|
|
395
|
+
|
|
396
|
+
// src/scalars.ts
|
|
397
|
+
var import_graphql_api3 = require("@ttoss/graphql-api");
|
|
398
|
+
var AWSJSONTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSJSON`);
|
|
399
|
+
var AWSDateTimeTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSDateTime`);
|
|
400
|
+
var AWSDateTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSDate`);
|
|
401
|
+
var AWSTimeTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSTime`);
|
|
402
|
+
var AWSTimestampTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSTimestamp`);
|
|
403
|
+
var AWSEmailTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSEmail`);
|
|
404
|
+
var AWSURLTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSURL`);
|
|
405
|
+
var AWSPhoneTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSPhone`);
|
|
406
|
+
var AWSIPAddressTC = import_graphql_api3.schemaComposer.createScalarTC(`scalar AWSIPAddress`);
|
|
378
407
|
// Annotate the CommonJS export names for ESM import in node:
|
|
379
408
|
0 && (module.exports = {
|
|
409
|
+
AWSDateTC,
|
|
410
|
+
AWSDateTimeTC,
|
|
411
|
+
AWSEmailTC,
|
|
412
|
+
AWSIPAddressTC,
|
|
413
|
+
AWSJSONTC,
|
|
414
|
+
AWSPhoneTC,
|
|
415
|
+
AWSTimeTC,
|
|
416
|
+
AWSTimestampTC,
|
|
417
|
+
AWSURLTC,
|
|
380
418
|
createApiTemplate,
|
|
381
419
|
createAppSyncResolverHandler
|
|
382
420
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/appsync-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "A library for building GraphQL APIs for AWS AppSync.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"graphql-shield": "^7.6.5",
|
|
37
37
|
"jest": "^30.2.0",
|
|
38
38
|
"tsup": "^8.5.1",
|
|
39
|
+
"@ttoss/graphql-api": "^0.8.17",
|
|
39
40
|
"@ttoss/config": "^1.36.0",
|
|
40
|
-
"@ttoss/ids": "^0.3.14"
|
|
41
|
-
"@ttoss/graphql-api": "^0.8.17"
|
|
41
|
+
"@ttoss/ids": "^0.3.14"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"api",
|