Skip to content

Commit d660ffb

Browse files
Pranav-Dakshinabryantbiggsantonbabenko
authored
feat: Added support for js pipeline resolver (#46)
Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com> Co-authored-by: Anton Babenko <anton@antonbabenko.com>
1 parent d3baf66 commit d660ffb

File tree

9 files changed

+50
-11
lines changed

9 files changed

+50
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ $ terraform apply
112112
| Name | Version |
113113
|------|---------|
114114
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
115-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
115+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.49 |
116116
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
117117

118118
## Providers
119119

120120
| Name | Version |
121121
|------|---------|
122-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
122+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.49 |
123123

124124
## Modules
125125

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Note that this example may create resources which cost money. Run `terraform des
2121
| Name | Version |
2222
|------|---------|
2323
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
24-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
24+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.49 |
2525
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2626

2727
## Providers
2828

2929
| Name | Version |
3030
|------|---------|
31-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.49 |
3232
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3333

3434
## Modules

examples/complete/main.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ provider "aws" {
22
region = "eu-west-1"
33

44
# Make it faster by skipping something
5-
skip_get_ec2_platforms = true
65
skip_metadata_api_check = true
76
skip_region_validation = true
87
skip_credentials_validation = true
@@ -16,7 +15,6 @@ provider "aws" {
1615
alias = "us-east-1"
1716

1817
# Make it faster by skipping something
19-
skip_get_ec2_platforms = true
2018
skip_metadata_api_check = true
2119
skip_region_validation = true
2220
skip_credentials_validation = true
@@ -251,6 +249,19 @@ EOF
251249
"None",
252250
]
253251
}
252+
253+
"Query.user" = {
254+
kind = "PIPELINE"
255+
type = "Query"
256+
field = "user"
257+
runtime = {
258+
name = "APPSYNC_JS"
259+
}
260+
code = file("src/index.js")
261+
functions = [
262+
"None",
263+
]
264+
}
254265
}
255266
}
256267

examples/complete/schema.graphql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ type Post {
77
title: String!
88
}
99

10+
type User {
11+
id: ID!
12+
name: String
13+
}
14+
1015
type Query {
1116
singlePost(id: ID!): Post
1217
none(dummyString: String!): String!
18+
user(id: ID!): User
1319
}
1420

1521
schema {

examples/complete/src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// For more examples, refer this doc: https://docs.aws.amazon.com/appsync/latest/devguide/configuring-resolvers-js.html
2+
import { util } from "@aws-appsync/utils";
3+
4+
export function request(ctx) {
5+
return {};
6+
}
7+
8+
export function response(ctx) {
9+
return ctx.result.items;
10+
}

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.0"
7+
version = ">= 4.49"
88
}
99
random = {
1010
source = "hashicorp/random"

main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,20 @@ resource "aws_appsync_resolver" "this" {
181181
field = each.value.field
182182
kind = lookup(each.value, "kind", null)
183183

184-
request_template = lookup(each.value, "request_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_request_template : "{}")
185-
response_template = lookup(each.value, "response_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_response_template : "{}")
184+
dynamic "runtime" {
185+
for_each = try([each.value.runtime], [])
186+
187+
content {
188+
name = runtime.value.name
189+
runtime_version = try(runtime.value.runtime_version, "1.0.0")
190+
}
191+
}
192+
193+
# code is required when runtime is APPSYNC_JS
194+
code = try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? each.value.code : null
195+
196+
request_template = lookup(each.value, "request_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_request_template : try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}")
197+
response_template = lookup(each.value, "response_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_response_template : try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}")
186198

187199
data_source = lookup(each.value, "data_source", null) != null ? aws_appsync_datasource.this[each.value.data_source].name : lookup(each.value, "data_source_arn", null)
188200

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ output "appsync_domain_hosted_zone_id" {
7373
# Extra
7474
output "appsync_graphql_api_fqdns" {
7575
description = "Map of FQDNs associated with the API (no protocol and path)"
76-
value = { for k, v in try(aws_appsync_graphql_api.this[0].uris, "") : k => regex("://([^/?#]*)?", v)[0] if length(aws_appsync_graphql_api.this) > 0 }
76+
value = { for k, v in try(aws_appsync_graphql_api.this[0].uris, []) : k => regex("://([^/?#]*)?", v)[0] if length(aws_appsync_graphql_api.this) > 0 }
7777
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.0"
7+
version = ">= 4.49"
88
}
99
random = {
1010
source = "hashicorp/random"

0 commit comments

Comments
 (0)