aws-amplify / aws-amplify/amplify-data

Data API - Nested custom resolvers (queries/mutations)

Open
#450 0 comments 2 reactions 0 assignees View on GitHub
data-schema feature-request Gen 2
Dominant language
TypeScript
Stars
18
Forks
23
Avg merge
26m
Merged PRs (30d)
1

Description

### Describe the feature you'd like to request

I would like to request the addition of support for nested resolvers in the amplify-category-api for AWS AppSync. Currently, the amplify-category-api simplifies the creation and management of GraphQL APIs with AWS AppSync, but it lacks support for nested resolvers. Nested resolvers are essential for efficiently handling complex queries and maintaining a clean and modular schema structure.

### Describe the solution you'd like

The solution I envision involves extending the amplify-category-api to support the definition and deployment of nested resolvers directly from the schema definition much like custom resolvers are defined in the root.

E.g:
```
const schema = a.schema({
Todo: a.model({
content: a.string(),
fieldWithCustomResolver: a
.query()
.arguments({ someArg: a.string() })
.returns(a.string())
.handler([a.handler.function(customHandler)])
.authorization((allow) => [allow.authenticated()]),
}),
});
```

SQL Schema:
```
const sqlSchema = generatedSqlSchema
.addToModel((models) => ({
models.Todo.addResolver({
fieldWithCustomResolver: a
.query()
.arguments({ someArg: a.string() })
.returns(a.string())
.handler([a.handler.function(customHandler)])
.authorization((allow) => [allow.authenticated()]),
})
}));
```

Example query definition
```
query MyQuery {
listTodos {
items {
content
fieldWithCustomResolver(someArg: "foobar")
}
}
}
```

### Describe alternatives you've considered

No real work around other than creating root resolvers that clutters the schema definition.

### Additional context

_No response_

### Is this something that you'd be interested in working on?

- [ ] 👋 I may be able to implement this feature request

### Would this feature include a breaking change?

- [ ] ⚠️ This feature might incur a breaking change

Contributor guide

Open the contributing guide

Research direction

Start with the amplify-category-api schema-definition path and compare how root custom resolvers are handled with the Todo and generatedSqlSchema examples. Trace the AWS AppSync deployment entry point, then verify that a nested field resolver with arguments, a return type, a handler, and authorization works in the shown example query.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql, typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.