social-network
social-network/Query_currentUser.tf
1
resource "aws_appsync_resolver" "Query_currentUser" {
2
  api_id = aws_appsync_graphql_api.appsync.id
3
  type   = "Query"
4
  field  = "currentUser"
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.Query_currentUser_1.function_id,
21
    ]
22
  }
23
}
24
resource "aws_appsync_function" "Query_currentUser_1" {
25
  api_id      = aws_appsync_graphql_api.appsync.id
26
  data_source = aws_appsync_datasource.ddb_user.name
27
  name        = "Query_currentUser_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.identity.sub}
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