1 | resource "aws_appsync_resolver" "Comment_post" { |
2 | api_id = aws_appsync_graphql_api.appsync.id |
3 | type = "Comment" |
4 | field = "post" |
5 | runtime { |
6 | name = "APPSYNC_JS" |
7 | runtime_version = "1.0.0" |
8 | } |
9 | code = <<EOF |
10 | export function request(ctx) { |
11 | return {}; |
12 | } |
13 | export function response(ctx) { |
14 | return ctx.result; |
15 | } |
16 | EOF |
17 | kind = "PIPELINE" |
18 | pipeline_config { |
19 | functions = [ |
20 | aws_appsync_function.Comment_post_1.function_id, |
21 | ] |
22 | } |
23 | } |
24 | resource "aws_appsync_function" "Comment_post_1" { |
25 | api_id = aws_appsync_graphql_api.appsync.id |
26 | data_source = aws_appsync_datasource.ddb_post.name |
27 | name = "Comment_post_1" |
28 | runtime { |
29 | name = "APPSYNC_JS" |
30 | runtime_version = "1.0.0" |
31 | } |
32 | code = <<EOF |
33 | import {util} from "@aws-appsync/utils"; |
34 | export function request(ctx) { |
35 | return { |
36 | version : "2018-05-29", |
37 | operation : "GetItem", |
38 | key: { |
39 | id: {S: ctx.source.postId} |
40 | } |
41 | }; |
42 | } |
43 | export function response(ctx) { |
44 | if (ctx.error) { |
45 | return util.error(ctx.error.message, ctx.error.type); |
46 | } |
47 | return ctx.result; |
48 | } |
49 | EOF |
50 | } |
51 | |
52 | |