amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Can't use enums as sortKeyFields

Open CodySwannGT opened this issue 3 years ago • 8 comments

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

CodySwannGT avatar Apr 21 '22 18:04 CodySwannGT

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

josefaidt avatar Apr 21 '22 18:04 josefaidt

Seconded. Have been waiting for this for almost a year ..

thejasonfisher avatar Apr 22 '22 23:04 thejasonfisher

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")
}
image image

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 avatar Jun 22 '22 16:06 josefaidt

@josefaidt try to add @hasMany relation using this index in parent (TodoList):

type TodoList @model {
  id: ID!
  todos: [Todo] @hasMany(indexName: "byPriority", fields: ["id"])
}

jk171505 avatar Jun 29 '22 20:06 jk171505

yes. can confirm can't use enums as sortKeyFields in @belongsTo with @hasMany.

losdwind avatar Aug 12 '22 14:08 losdwind

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.

LuisMyRobal avatar Dec 01 '22 19:12 LuisMyRobal

Interested!

ggiallo28 avatar Jan 01 '24 19:01 ggiallo28

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"])
}

AaronZyLee avatar Apr 19 '24 00:04 AaronZyLee