From 9d3e9b0beb0d91b518c47771e51bd49768755db0 Mon Sep 17 00:00:00 2001 From: James Goodhand Date: Wed, 30 Aug 2023 17:07:42 +0100 Subject: [PATCH] fix: Fixed APPSYNC_JS resolvers for both kinds (UNIT and PIPELINE) (#55) --- examples/complete/main.tf | 12 ++++++++++++ examples/complete/schema.graphql | 6 ++++++ main.tf | 6 +++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/complete/main.tf b/examples/complete/main.tf index b94e93b..d921e5a 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -269,6 +269,18 @@ EOF ] } + "Query.singleComment" = { + kind = "UNIT" + type = "Query" + field = "singleComment" + code = file("src/function.js") + runtime = { + name = "APPSYNC_JS" + runtime_version = "1.0.0" + } + data_source = "dynamodb1" + } + "Query.user" = { kind = "PIPELINE" type = "Query" diff --git a/examples/complete/schema.graphql b/examples/complete/schema.graphql index 8ed7ba2..f9b6892 100644 --- a/examples/complete/schema.graphql +++ b/examples/complete/schema.graphql @@ -12,10 +12,16 @@ type User { name: String } +type Comment { + id: ID ! + comment: String! +} + type Query { singlePost(id: ID!): Post none(dummyString: String!): String! user(id: ID!): User + singleComment(id: ID!): Comment } schema { diff --git a/main.tf b/main.tf index 2c6c065..be4398c 100644 --- a/main.tf +++ b/main.tf @@ -201,10 +201,10 @@ resource "aws_appsync_resolver" "this" { } # code is required when runtime is APPSYNC_JS - code = try(each.value.kind == "PIPELINE" && each.value.runtime.name == "APPSYNC_JS", false) ? each.value.code : null + code = try(each.value.runtime.name == "APPSYNC_JS", false) ? each.value.code : null - 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 : "{}") - 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 : "{}") + request_template = lookup(each.value, "request_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_request_template : try(each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}") + response_template = lookup(each.value, "response_template", tobool(lookup(each.value, "direct_lambda", false)) ? var.direct_lambda_response_template : try(each.value.runtime.name == "APPSYNC_JS", false) ? null : "{}") 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)