amplify-category-api
amplify-category-api copied to clipboard
Can't use enums as sortKeyFields
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v16.13.1
Amplify CLI Version
8.0.1
What operating system are you using?
Mac
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
no
Amplify Categories
api
Amplify Commands
push
Describe the bug
It's this aws-amplify/amplify-cli#1572 but with @index
Expected behavior
You can use enums as sorts
Reproduction steps
Make an enum a sort key
try to push
GraphQL schema(s)
No response
Log output
# Put your logs below this line
Additional information
No response
Hey @CodySwannGT :wave: thanks for raising this! I will mark this as a feature request for GraphQL Transformer v2, and this seems related to aws-amplify/amplify-category-api#396
Seconded. Have been waiting for this for almost a year ..
Hey @CodySwannGT :wave: revisiting this issue I was able to use enum values on sortKeyFields with the following schema
enum Completed {
YES
NO
}
enum Priority {
LOW
MEDIUM
HIGH
}
type Todo
@model
@auth(rules: [{ allow: owner, operations: [create, read, update] }]) {
id: ID!
title: String!
createdAt: AWSDateTime
priority: Priority
@default(value: "LOW")
@index(
name: "byPriority"
sortKeyFields: ["completed"]
queryField: "listTodosByPriority"
)
completed: Completed
@default(value: "NO")
}
Are you experiencing an issue when attempting to set the sortKeyField to an enum field? If so, may you provide a sample schema for reproduction?
@josefaidt try to add @hasMany relation using this index in parent (TodoList):
type TodoList @model {
id: ID!
todos: [Todo] @hasMany(indexName: "byPriority", fields: ["id"])
}
yes. can confirm can't use enums as sortKeyFields in @belongsTo with @hasMany.
You can add another sorting column aside and will work, Or it does it for me....
[Update] Never mind, it is created but it doesn't work correctly once we use it.
Interested!
I am able to repro the issue with the following schema. Mark it as a bug.
enum Completed {
YES
NO
}
enum Priority {
LOW
MEDIUM
HIGH
}
type Todo
@model
@auth(rules: [{ allow: owner, operations: [create, read, update] }]) {
id: ID!
title: String!
createdAt: AWSDateTime
priority: Priority
@default(value: "LOW")
@index(
name: "byPriority"
sortKeyFields: ["completed"]
queryField: "listTodosByPriority"
)
completed: Completed
@default(value: "NO")
}
type TodoList @model {
priority: Priority! @primaryKey
todos: [Todo] @hasMany(indexName: "byPriority", fields: ["priority"])
}