Skip to content

Commit 06f8ce5

Browse files
committed
refactor: standardize router naming and improve type annotations in examples
1 parent b97ab20 commit 06f8ce5

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

docs/features/event-handler/appsync-graphql.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Let's assume you have `app.ts` as your Lambda function entrypoint and routes in
140140

141141
We use `includeRouter` method and include all operations registered in the router instances.
142142

143-
```typescript hl_lines="2-3 7"
143+
```typescript hl_lines="3-4 8"
144144
--8<-- "examples/snippets/event-handler/appsync-graphql/splitRouter.ts"
145145
```
146146

@@ -156,7 +156,7 @@ You can use `appendContext` when you want to share data between your App and Rou
156156

157157
=== "app.ts"
158158

159-
```typescript hl_lines="9"
159+
```typescript hl_lines="10"
160160
--8<-- "examples/snippets/event-handler/appsync-graphql/appendContext.ts"
161161
```
162162

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { AppSyncGraphQLResolver } from '@aws-lambda-powertools/event-handler/appsync-graphql';
2+
import type { Context } from 'aws-lambda/handler';
23
import { postRouter } from './postRouter';
3-
import { usersRouter } from './userRouter';
4+
import { userRouter } from './userRouter';
45

56
const app = new AppSyncGraphQLResolver();
67

7-
app.includeRouter([postRouter, usersRouter]);
8+
app.includeRouter([postRouter, userRouter]);
89

910
app.appendContext({ requestId: crypto.randomUUID() });
1011

11-
export const handler = async (event, context) => app.resolve(event, context);
12+
export const handler = async (event: unknown, context: Context) =>
13+
app.resolve(event, context);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { AppSyncGraphQLResolver } from '@aws-lambda-powertools/event-handler/appsync-graphql';
2+
import type { Context } from 'aws-lambda';
23
import { postRouter } from './postRouter';
34
import { userRouter } from './userRouter';
45

56
const app = new AppSyncGraphQLResolver();
67

78
app.includeRouter([postRouter, userRouter]);
89

9-
export const handler = async (event, context) => app.resolve(event, context);
10+
export const handler = async (event: unknown, context: Context) =>
11+
app.resolve(event, context);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Router } from '@aws-lambda-powertools/event-handler/appsync-graphql';
22

3-
const usersRouter = new Router();
3+
const userRouter = new Router();
44

5-
usersRouter.onQuery('getUsers', async (args, { sharedContext }) => {
5+
userRouter.onQuery('getUsers', async (args, { sharedContext }) => {
66
const requestId = sharedContext?.get('requestId');
77
return [{ id: 1, name: 'John Doe', email: '[email protected]', requestId }];
88
});
99

10-
export { usersRouter };
10+
export { userRouter };

0 commit comments

Comments
 (0)