Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gen2] Add sort key to model identifier #13201

Open
1 of 2 tasks
ryanmalesic opened this issue Apr 1, 2024 · 5 comments
Open
1 of 2 tasks

[Gen2] Add sort key to model identifier #13201

ryanmalesic opened this issue Apr 1, 2024 · 5 comments
Assignees
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues question General question

Comments

@ryanmalesic
Copy link

ryanmalesic commented Apr 1, 2024

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

DynamoDB

Describe the feature you'd like to request

.identifier() on models should allow for sort keys.

Describe the solution you'd like

.identifier({ hashKey: [...], sortKey: [...] })

Describe alternatives you've considered

GSIs with sort keys don't fit my use-case as duplicates are allowed in GSIs

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change
@ryanmalesic ryanmalesic added the pending-triage Issue is pending triage label Apr 1, 2024
@cwomack cwomack self-assigned this Apr 1, 2024
@cwomack cwomack added GraphQL Related to GraphQL API issues Gen 2 Issues related to Gen 2 Amplify projects labels Apr 1, 2024
@cwomack
Copy link
Contributor

cwomack commented Apr 1, 2024

Hello, @ryanmalesic 👋 and thank you for opening this issue. It looks like you're referring to the Gen2 Developer Experience with this feature request. Just to confirm, have you reviewed the composite identifier section that shows how to use a sort key within the identifier() call?

The first string that's passed into the array is the partition key. The second (and any more) would be additional sort keys.

@cwomack cwomack added question General question pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Apr 1, 2024
@ryanmalesic
Copy link
Author

ryanmalesic commented Apr 1, 2024

Thanks. I guess my request then is updating the docs to explicitly call out that subsequent items are sort keys and NOT 1 PK with all the fields joined is needed then: https://docs.amplify.aws/gen2/build-a-backend/data/data-modeling/identifiers/#pageMain

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue requestor label Apr 1, 2024
@ryanmalesic
Copy link
Author

ryanmalesic commented Apr 2, 2024

Also, it seems sort keys on the primary index don't support comparison operations in the autogenerated gets/queries? Is this correct

@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Apr 15, 2024

Hi @ryanmalesic can you explain your use case a bit more? When performing a get request, the expected behavior is to return a single item so the arguments to the query are constrained as such, which means you can't use a filter expression. However, you can use a filter expression on a list query as it returns multiple items. So you can do something like this:

const schema = a.schema({
  Customer: a
    .model({
      name: a.string(),
      phoneNumber: a.phone().required(),
      accountRepresentativeId: a.id().required(),
    })
    .identifier(["accountRepresentativeId", "phoneNumber"])
    .authorization([a.allow.owner()]),
});
image

If this doesn't fit your use case either, then can you provide an example of your schema and the data access pattern you're trying to achieve?

@chrisbonifacio chrisbonifacio added the pending-response Issue is pending response from the issue requestor label Apr 15, 2024
@ryanmalesic
Copy link
Author

ryanmalesic commented Apr 15, 2024

Understood on the get, that was a mistype.

Does list + filter convert to a Scan + Filter expression or a Query when calling DDB from the default generated app sync resolver?

If it's scan + filter, this is too unoptimized and comparatively expensive to a Query for my use-cases. Dynamo makes a point to discourage scan usage for things that could be queries

My use case would involve having a method called query (for example) on the generated model that accepts the pk and then optionally a query (beginsWith, lt, gt, etc) operation on the (composite) sort key. This would translate to a Query operation on the table in the resolver function

Also having a composite pk would be helpful. Instead of identifier having the first field of the array be the pk and the rest becoming a composite sk, it could be something like

.identifier({
    hashKey: [...],
    sortKey: [...],
})

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue requestor label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues question General question
Projects
None yet
Development

No branches or pull requests

3 participants