aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
90 stars 77 forks source link

Cannot use enums to sort @searchable search results #1557

Open Jupdi opened 1 year ago

Jupdi commented 1 year ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

11.0.4

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.

None

Describe the bug

I cannot use enums to sort my search results using graphql, and they are not beeing generated in to he SortableFields.

Expected behavior

Use enums to sort, like using other types of fields.

Reproduction steps

  1. Create a type with @searchable
  2. Add a field with type enum
  3. Push some data into Opensearch
  4. Using the seach query to search for some of the data
  5. Try to use the enum field to sort

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

Jupdi commented 1 year ago

I could fix the problem by manually add the SortableFields Enum to my schema and add the missing fields, but now i need to manually keep that in sync.

AnilMaktala commented 1 year ago

Hi @Jupdi, Thank you for bringing this to our attention.We greatly appreciate your proactive approach in resolving the problem by manually adding the missing fields to the SortableFields enum in the schema. We have successfully reproduced the problem by following the steps outlined in the description. As a result, we have categorized this as a bug and will further investigate it with our team.

schema used:

type Post @model @searchable {
  postId: ID!
    @primaryKey(sortKeyFields: ["title"])
    @index(name: "postByPostId", sortKeyFields: ["title"])
  title: String!
  comments: [Comment] @hasMany(indexName: "byPost", fields: ["postId", "title"])
  posttype: PostType
}

type Comment @model {
  commentId: ID! @primaryKey(sortKeyFields: ["content"])
  content: String!
  postId: ID @index(name: "byPost", sortKeyFields: ["postTitle"]) # customized foreign key for parent primary key
  postTitle: String # customized foreign key for parent sort key
  post: Post @belongsTo(fields: ["postId", "postTitle"])
}

enum PostType {
  newsletter
  blog
}
image
cjsilva-umich commented 1 year ago

Any update? Surprised that we can't sort by enums...