aws / aws/aws-appsync-community

Only one resolver is allowed per field

Open
#128 6 comments 21 reactions 0 assignees View on GitHub
bug
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

AppSync does not seem to detach and attach resolvers when they are removed or renamed in CloudFormation resulting in edge cases that require manual intervention.

### Reproduction Steps

The simplest version of this to replicate is to change the name of an AppSync resolver resulting in an error where the old resolver is still attached and the new one fails to attach with the error `Only one resolver is allowed per field`.

Using CDK for conciseness:

```python
api = aws_appsync.GraphQLApi(
self,
"test_api",
name="test_api",
schema_definition=aws_appsync.SchemaDefinition.FILE,
log_config=aws_appsync.LogConfig(
exclude_verbose_content=False, field_log_level=aws_appsync.FieldLogLevel.ALL,
),
schema_definition_file="resources/schema.graphql",
xray_enabled=True,
)

api.add_none_data_source("ping", "Ping").create_resolver(
type_name="Query",
field_name="ping",
request_mapping_template=aws_appsync.MappingTemplate.from_string(
'{"version": "2018-05-29"}'
),
response_mapping_template=aws_appsync.MappingTemplate.from_string(
'$util.toJson("pong")'
),
)
```

Schema:
```graphql
type Query {
ping: String
}
```

The above code deploys an AppSync API and attaches a resolver that echos "pong" when the "ping" field is queried. Once deployed simply changing the name of the datasource reproduces this error. Line 12 can be changed to `api.add_none_data_source("ping2", "Ping").create_resolver(` (note **"ping2"**). This results in the old datasource being deleted (**but not detached**) and the new datasource being created and failing to attach due to it clashing with the old datasource.

### Other

This issue has also been raised on the Amplify community - https://github.com/aws-amplify/amplify-cli/issues/682

---

This is :bug: Bug Report

Contributor guide

Open the contributing guide

Research direction

Start with the CDK example in the issue and resources/schema.graphql, deploy the API, then rename the data source from "ping" to "ping2" and query the Query.ping field. Compare the resolver and data-source state after deployment; done means the old resolver is detached and the renamed resolver attaches without the "Only one resolver is allowed per field" error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, python
Domain
api, backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.