Skip to content

Commit

Permalink
Set runtime for resolvers which use generated code (#3240)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssenchenko committed Jul 5, 2023
1 parent 993d279 commit 10e4c01
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,10 @@ Resources:
Resolvers:
Mutation:
addPost:
Runtime:
Name: APPSYNC_JS
Version: 1.0.0
Pipeline:
- lambdaInvoker
Query:
getPost:
Runtime:
Name: APPSYNC_JS
Version: 1.0.0
Pipeline:
- lambdaInvoker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,13 @@ Resources:
Resolvers:
Mutation:
addPost:
Runtime:
Name: APPSYNC_JS
Version: 1.0.0
Pipeline:
- formatPostLogItem
- createPostLogItem
- formatPostItem
- createPostItem
Query:
getPost:
Runtime:
Name: APPSYNC_JS
Version: 1.0.0
Pipeline:
- getPostFromTable

Expand Down
7 changes: 7 additions & 0 deletions samtranslator/internal/model/appsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class AppSyncRuntimeType(TypedDict):
RuntimeVersion: str


# Runtime for the default generated resolver code (see APPSYNC_PIPELINE_RESOLVER_JS_CODE above)
APPSYNC_PIPELINE_RESOLVER_JS_RUNTIME: AppSyncRuntimeType = {
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.0.0",
}


class LambdaConflictHandlerConfigType(TypedDict):
LambdaConflictHandlerArn: str

Expand Down
7 changes: 5 additions & 2 deletions samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from samtranslator.internal.intrinsics import resolve_string_parameter_in_resource
from samtranslator.internal.model.appsync import (
APPSYNC_PIPELINE_RESOLVER_JS_CODE,
APPSYNC_PIPELINE_RESOLVER_JS_RUNTIME,
AdditionalAuthenticationProviderType,
ApiCache,
ApiKey,
Expand Down Expand Up @@ -2187,7 +2188,7 @@ def _add_connector_metadata(


class SamGraphQLApi(SamResourceMacro):
"""SAM GraphQL API Macro (WIP)."""
"""SAM GraphQL API Macro."""

resource_type = "AWS::Serverless::GraphQLApi"
property_types = {
Expand Down Expand Up @@ -2973,11 +2974,13 @@ def _construct_appsync_resolver_resources(
# to a default snippet which has basic definition of request/response functions.
if not cfn_resolver.Code and not cfn_resolver.CodeS3Location:
cfn_resolver.Code = APPSYNC_PIPELINE_RESOLVER_JS_CODE
cfn_resolver.Runtime = APPSYNC_PIPELINE_RESOLVER_JS_RUNTIME
else:
cfn_resolver.Runtime = self._parse_runtime(resolver, relative_id)

cfn_resolver.ApiId = api_id
cfn_resolver.FieldName = resolver.FieldName or relative_id
cfn_resolver.TypeName = type_name
cfn_resolver.Runtime = self._parse_runtime(resolver, relative_id)

if resolver.Pipeline:
cfn_resolver.Kind = "PIPELINE"
Expand Down
32 changes: 1 addition & 31 deletions tests/translator/input/error_graphqlapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,6 @@ Resources:
Version: 1.2.3
InlineCode: this is my epic code

ResolverBothDatasourcePropertiesDefined:
Type: AWS::Serverless::GraphQLApi
Properties:
Name: SomeApi
SchemaInline: |
type Mutation {
addTodo(id: ID!, name: String, description: String, priority: Int): Todo
}
XrayEnabled: true
Auth:
Type: AWS_IAM
Tags:
key1: value1
key2: value2
Resolvers:
Mutation:
BothDatasourcePropertiesDefined:
FieldName: my_field
Runtime:
Name: some-runtime
Version: 1.2.3
Pipeline:
- MyFunction
Functions:
MyFunction:
DataSource: NONE
Runtime:
Name: some-runtime
Version: 1.2.3
InlineCode: this is my epic code

ResolverWithNoRuntime:
Type: AWS::Serverless::GraphQLApi
Properties:
Expand All @@ -333,6 +302,7 @@ Resources:
Mutation:
NoRuntimeForResolver:
FieldName: my_field
InlineCode: overridden code must be supplied with Runtime
Pipeline:
- MyFunction
Functions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ Resources:
myResolver:
FieldName: my_field
MaxBatchSize: 10
Caching:
Ttl: 20
CachingKeys:
- key1
- key2
Pipeline:
- MyFunction
myResolverWithCustomCode:
FieldName: my_field
InlineCode: custom code
Runtime:
Name: some-runtime
Name: APPSYNC_JS
Version: 1.2.3
MaxBatchSize: 10
Caching:
Ttl: 20
CachingKeys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,47 @@
]
},
"Runtime": {
"Name": "some-runtime",
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.0.0"
},
"TypeName": "Mutation"
},
"Type": "AWS::AppSync::Resolver"
},
"SuperCoolAPIMutationmyResolverWithCustomCode": {
"DependsOn": [
"SuperCoolAPISchema"
],
"Properties": {
"ApiId": {
"Fn::GetAtt": [
"SuperCoolAPI",
"ApiId"
]
},
"CachingConfig": {
"CachingKeys": [
"key1",
"key2"
],
"Ttl": 20
},
"Code": "custom code",
"FieldName": "my_field",
"Kind": "PIPELINE",
"MaxBatchSize": 10,
"PipelineConfig": {
"Functions": [
{
"Fn::GetAtt": [
"SuperCoolAPIMyFunction",
"FunctionId"
]
}
]
},
"Runtime": {
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.2.3"
},
"TypeName": "Mutation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,47 @@
]
},
"Runtime": {
"Name": "some-runtime",
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.0.0"
},
"TypeName": "Mutation"
},
"Type": "AWS::AppSync::Resolver"
},
"SuperCoolAPIMutationmyResolverWithCustomCode": {
"DependsOn": [
"SuperCoolAPISchema"
],
"Properties": {
"ApiId": {
"Fn::GetAtt": [
"SuperCoolAPI",
"ApiId"
]
},
"CachingConfig": {
"CachingKeys": [
"key1",
"key2"
],
"Ttl": 20
},
"Code": "custom code",
"FieldName": "my_field",
"Kind": "PIPELINE",
"MaxBatchSize": 10,
"PipelineConfig": {
"Functions": [
{
"Fn::GetAtt": [
"SuperCoolAPIMyFunction",
"FunctionId"
]
}
]
},
"Runtime": {
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.2.3"
},
"TypeName": "Mutation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,47 @@
]
},
"Runtime": {
"Name": "some-runtime",
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.0.0"
},
"TypeName": "Mutation"
},
"Type": "AWS::AppSync::Resolver"
},
"SuperCoolAPIMutationmyResolverWithCustomCode": {
"DependsOn": [
"SuperCoolAPISchema"
],
"Properties": {
"ApiId": {
"Fn::GetAtt": [
"SuperCoolAPI",
"ApiId"
]
},
"CachingConfig": {
"CachingKeys": [
"key1",
"key2"
],
"Ttl": 20
},
"Code": "custom code",
"FieldName": "my_field",
"Kind": "PIPELINE",
"MaxBatchSize": 10,
"PipelineConfig": {
"Functions": [
{
"Fn::GetAtt": [
"SuperCoolAPIMyFunction",
"FunctionId"
]
}
]
},
"Runtime": {
"Name": "APPSYNC_JS",
"RuntimeVersion": "1.2.3"
},
"TypeName": "Mutation"
Expand Down

0 comments on commit 10e4c01

Please sign in to comment.