Skip to content

Commit 91a4916

Browse files
committed
test: guard fetchProfile against null ctx.prev.result (CodeRabbit)
1 parent fa71f7b commit 91a4916

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import { util } from '@aws-appsync/utils';
1+
import { util, runtime } from '@aws-appsync/utils';
22

33
export function request(ctx) {
4+
// fetchUser returns null when the user isn't found; short-circuit the
5+
// pipeline function instead of dereferencing a null result.
6+
if (ctx.prev.result == null) {
7+
runtime.earlyReturn(null);
8+
}
49
return {
510
operation: 'GetItem',
611
key: util.dynamodb.toMapValues({ userId: ctx.prev.result.id }),
712
};
813
}
914

1015
export function response(ctx) {
16+
if (ctx.prev.result == null) {
17+
return null;
18+
}
1119
return { ...ctx.prev.result, profile: ctx.result };
1220
}

0 commit comments

Comments
 (0)