social-network
social-network/Mutation_notifyComment.tf
1
resource "aws_appsync_resolver" "Mutation_notifyComment" {
2
  api_id = aws_appsync_graphql_api.appsync.id
3
  type   = "Mutation"
4
  field  = "notifyComment"
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.Mutation_notifyComment_1.function_id,
21
      aws_appsync_function.Mutation_notifyComment_2.function_id,
22
    ]
23
  }
24
}
25
resource "aws_appsync_function" "Mutation_notifyComment_1" {
26
  api_id      = aws_appsync_graphql_api.appsync.id
27
  data_source = aws_appsync_datasource.ddb_comment.name
28
  name        = "Mutation_notifyComment_1"
29
  runtime {
30
    name            = "APPSYNC_JS"
31
    runtime_version = "1.0.0"
32
  }
33
  code = <<EOF
34
import {util} from "@aws-appsync/utils";
35
export function request(ctx) {
36
	return {
37
		version : "2018-05-29",
38
		operation : "GetItem",
39
		key : {
40
			id: {S: ctx.args.commentId}
41
		},
42
	};
43
}
44
export function response(ctx) {
45
	if (ctx.error) {
46
		return util.error(ctx.error.message, ctx.error.type);
47
	}
48
	return ctx.result;
49
}
50
EOF
51
}
52
resource "aws_appsync_function" "Mutation_notifyComment_2" {
53
  api_id      = aws_appsync_graphql_api.appsync.id
54
  data_source = aws_appsync_datasource.ddb_post.name
55
  name        = "Mutation_notifyComment_2"
56
  runtime {
57
    name            = "APPSYNC_JS"
58
    runtime_version = "1.0.0"
59
  }
60
  code = <<EOF
61
import {util} from "@aws-appsync/utils";
62
export function request(ctx) {
63
	return {
64
		version : "2018-05-29",
65
		operation : "GetItem",
66
		key : {
67
			id: {S: ctx.prev.result.postId}
68
		},
69
	};
70
}
71
export function response(ctx) {
72
	if (ctx.error) {
73
		return util.error(ctx.error.message, ctx.error.type);
74
	}
75
	return {
76
		postUserId: ctx.result.userId,
77
		postDate: util.time.epochMilliSecondsToISO8601(ctx.result.date),
78
		comment: ctx.prev.result,
79
	};
80
}
81
EOF
82
}
83
84