aws-amplify / aws-amplify/amplify-data
Field level auth on a customType
- Dominant language
- TypeScript
- Stars
- 18
- Forks
- 23
- Avg merge
- 26m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
`a.customType()` currently allows users to set authorization on fields, but when this is deployed no resolver is created and no error is displayed.
**To Reproduce**
```typescript
const schema = a.schema({
Post: a.customType({
id: a.id().required(),
title: a.string().required(),
// I would expect this field to have a resolver and to be omitted if not logged in
description: a.string()
.authorization((allow) => allow.authenticated()),
}),
searchForPosts: a
.query()
.arguments({
search: a.string(),
})
.returns(a.ref('Post').required().array().required())
.handler(
a.handler.function(defineFunction({
entry: './posts/search.ts',
}))
),
})
.authorization((allow) => allow.publicApiKey());
```
**Expected behavior**
Either:
- (Preferred) An appropriate field resolver to be created, and for the field to be null when not authorized.
- (Less preferred) Not able to call `.authorization` on a customType
**Desktop (please complete the following information):**
- "aws-amplify": "6.15.3",
**Additional context**
Switching `.customType` to `.model` causes the resolver to be created (but also creates a db table that are unnecessary)
Contributor guide
Research direction
Reproduce the schema in the issue, including the searchForPosts entry point at posts/search.ts, and inspect the deployed behavior for authorization on the customType.description field. Compare this with the resolver behavior when the type is changed to a model. Done means the chosen authorization behavior is enforced without requiring an unnecessary database table.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, authorization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100