Closed hamedhemmati closed 2 years ago
@key( name: "UsersByEmail" fields: ["email"] queryField: "UsersByEmail" )
@index(name: "UsersByEmail")
Can you try adding the queryField
argument to your @index
directive as you did with @key
in v1.
@key( name: "UsersByEmail" fields: ["email"] queryField: "UsersByEmail" )
@index(name: "UsersByEmail")
Can you try adding the
queryField
argument to your@index
directive as you did with@key
in v1.
This worked thanks. I think this should be added to the docs. I was under impression that the new @index only needs the name not both the name and the queryField.
Related to this the new @index cannot be removed once it has been created, unlike the old @key. When trying to remove the index you get an unhelpful "An error occurred when pushing the resources to the cloud". I had to delete the whole table and create it again to remove the index or move the index from one field to another. This used to be fine with @key in the V1.
I think this should be added to the docs.
Agreed. Thanks for pointing this out.
the new @Index cannot be removed once it has been created
Can you please provide more detailed steps to reproduce this. Based on your original post, I pushed the following schema:
type User
@model
@auth(
rules: [{ allow: owner, operations: [create, update, read, delete] }]
)
{
id: ID!
email: String! @index(name: "UsersByEmail", queryField: "UsersByEmail")
identityId: String!
}
I then removed the @index
and pushed again and everything succeeded.
A fix has been released in the latest appsync modelgen plugin, and should go out in the next CLI release.
Here's a quick video of removing the index
https://user-images.githubusercontent.com/2079826/144135900-57c88766-3146-4341-b546-eb8a0760596e.mov
.
@hamedhemmati there should be a better error message displayed, but based on your video, it looks like you removed the projectsByUser
index from the Project
model, but are still referencing that index from on line 7.
@hamedhemmati there should be a better error message displayed, but based on your video, it looks like you removed the
projectsByUser
index from theProject
model, but are still referencing that index from on line 7.
Thanks for catching that. It's working now. I see that the documentation has been updated to include the queryField now so I am closing this.
@hamedhemmati Can you give the link of documentation where you look? I cannot find anything about that inside migration to v2 documentations in the whole web. I mean this: https://docs.amplify.aws/cli/migration/transformer-migration/#changes-that-amplify-cli-will-auto-migrate-for-you and this: https://docs.amplify.aws/cli-legacy/graphql-transformer/connection/
@hamedhemmati Can you give the link of documentation where you look? I cannot find anything about that inside migration to v2 documentations in the whole web. I mean this: https://docs.amplify.aws/cli/migration/transformer-migration/#changes-that-amplify-cli-will-auto-migrate-for-you and this: https://docs.amplify.aws/cli-legacy/graphql-transformer/connection/
I know the documentation is really confusing for sure. The last bullet point says you need to type the queryField if you want a query. The screenshot doesn't include it. So basically if you want to generate a query you have to pass something like.
@index(name: "byOderByAmount", queryField: "byOderByAmount, sortKeyFields: ["amount"]
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Categories
No response
Environment information
Describe the bug
I have built a test environment to play with the new transformer V2. I am trying to get play with @index but I am not seeing any queries generated for it.
In the previous version, I use @key to get a list of users by email as follows.
type User @model @auth(rules: [{ allow: owner, operations: [create, update, read, delete] }]) @key( name: "UsersByEmail" fields: ["email"] queryField: "UsersByEmail" ) { id: ID! email: String! identityId: String! }
in the new version I am using the new @index with the following schema
type User @model @auth(rules: [{ allow: owner, operations: [create, update, read, delete] }]) { id: ID! email: String! @index(name: "UsersByEmail") identityId: String! }
It seems to be taking it just fine but it's not generating a query for me to use. Nothing in the graphql folder or AppSync console.
Expected behavior
Expecting a new query added to the list of GraphQL queries
Reproduction steps
Create a new type User with @index on a required field amplify push --y
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response