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

Custom primary key support #1426

Closed
2 of 9 tasks
dnys1 opened this issue Mar 3, 2022 · 15 comments
Closed
2 of 9 tasks

Custom primary key support #1426

dnys1 opened this issue Mar 3, 2022 · 15 comments
Assignees
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category. fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch GraphQL API Issues related to the API (GraphQL) Category

Comments

@dnys1
Copy link
Contributor

dnys1 commented Mar 3, 2022

Description

This is to track support of custom primary keys in model gen and model mutations.

  • Model gen
  • Model mutations

Current state of custom primary key support

CPK Support Stable ver. Dev Preview ver.
GraphQL API
DataStore

Categories

  • Analytics
  • API
  • Auth
  • DataStore
  • Storage

Steps to Reproduce

No response

Screenshots

No response

Platforms

  • iOS
  • Android

Environment

N/A

Dependencies

N/A

Device

N/A

OS

N/A

CLI Version

N/A

Additional Context

No response

@dnys1 dnys1 added GraphQL API Issues related to the API (GraphQL) Category datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category. labels Mar 3, 2022
@dnys1 dnys1 added this to Pending Triage in Issues Triaging via automation Mar 3, 2022
@dnys1 dnys1 moved this from Pending Triage to Feature Requests in Issues Triaging Mar 3, 2022
@tr-asimpson
Copy link

tr-asimpson commented Mar 31, 2022

Use case for using Custom PK.

We have a BLE device that has its own identifier which cannot be changed for security reasons. This along with some other information is sent to a Lambda function which then searches for the device "key" in DynamoDB and updates via AppSync.

I did not want to have to send the generated "ID" as this means id have to then store it on flash (Limited space) and add it to the network packet which uses 3g/4g increasing our overhead.

I believe AppSync requires the primary key field for updates hence me needing a custom one.

This is also how the subscriptions for updates work by key. I am not sure if I could have done the same via ID, Correct me if I am wrong.

Thinking on it I could have searched the DB for the ID by finding the key field and then updated... It just felt better to make a custom primary key.

@h2ouw8n4
Copy link

h2ouw8n4 commented May 16, 2022

We have been confronted with almost the exact same use case as @tr-asimpson . We are working with BLE devices and have natural keys currently defined in DynamoDB. We really want to use AppSync, but if we do, we'll have to apply costly workarounds, and will impact our customer experience. Is it possible to share where this enhancement is on the roadmap or an ETA so that we can appropriately plan?

Thanks!

@veeramneni
Copy link

+1

@AmanMasipeddi
Copy link

AmanMasipeddi commented May 20, 2022

Even we are facing this issue. It would be helpful if this is implemented soon.

@Simon-PumpAndUp
Copy link

Simon-PumpAndUp commented Jun 17, 2022

Hi there

I can't get a unique record from dynamodb through AppSync using:
Amplify.API.query(request: ModelQueries.get(Model.classType, 123, "abc"))
As the parameter ID takes a single String.

Also, since I can't use two owner type auth rules (aws-amplify/amplify-swift#1590, aws-amplify/amplify-cli#10110)
I need a way to retrieve data from other users. Is there a way to automatically sync down specific records from a model, anyone?

EDIT: Nevermind, I realized I can just replace ModelQueries.get with a GraphQL query...

@hanna-becker
Copy link

Hey there, what's the ETA on resolving this issue? It looks like a lot of work has already been completed and is merged. We just started prototyping a flutter mobile app client for our existing amplify web application that uses custom PKs and ran into this issue. Currently we're considering two options:

  1. A rather expensive and risky schema migration away from custom PKs, as the web app is already in production state
  2. Switching to another mobile app framework, e.g. React Native, where we hope amplify supports custom PKs

@HuiSF
Copy link
Contributor

HuiSF commented Aug 19, 2022

Hello @hanna-becker sorry for the delayed response!

You are right! This feature is almost ready (library support has been released with version 0.6.6). We are currently working on some final tunings cross Amplify platforms. We expect this feature to be live very soon, thank you for your patience!

@hanna-becker
Copy link

Nice! We're very excited about this.

@8maxxam8
Copy link

Hi do you have any updates about this? Is it already possible to set a custom primary key with amplify?

@HuiSF
Copy link
Contributor

HuiSF commented Nov 28, 2022

Hi @hanna-becker @8maxxam8 with the release of @aws-amplify/cli 10.5, custom primary key feature becomes generally available. You can give it a try :)

For an existing project, you may need to manually flip a feature flag in order to enable custom primary key functionality with Amplify CLI and codegen.

Set respectPrimaryKeyAttributesOnConnectionField to true in your amplify/cli.json file:

{
  "features": {
    "graphqltransformer": {
      "respectPrimaryKeyAttributesOnConnectionField": true,
    }
  }
}

Then run amplify codegen models (please make sure you've installed Amplify CLI 10.5).

In addition, currently custom primary key feature is only available for DataStore plugin, model generated with a custom primary key will not work with API plugin GraphQL helper.

@vgribok
Copy link

vgribok commented Jan 4, 2023

"...custom primary key feature is only available for DataStore plugin, model generated with a custom primary key will not work with API plugin GraphQL helper."

@HuiSF, to clarify where CPK support is available, would it be possible to have something like

CPK Support Stable ver. Dev Preview ver.
GraphQL API ? ?
DataStore ? ?

@HuiSF
Copy link
Contributor

HuiSF commented Jan 4, 2023

Hi @vgribok thanks for asking the clarification.

Current state:

CPK Support Stable ver. Dev Preview ver.
GraphQL API
DataStore

For the API plugin the GraphQL helper APIs need to be update to support ModelIdentifier which allows composite key instead of hardcoded id.

@ragingsquirrel3
Copy link
Contributor

Just noting PR merged for GraphQL API support here #2606, should go out in next dev preview version.

@ragingsquirrel3
Copy link
Contributor

GraphQL API model helper support for custom primary key was just released in dev preview with amplify_api 1.0.0-next.6. There are some examples of usage on https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/flutter/#query-item. We will leave this issue open until there is a stable release for this.

@Jordan-Nelson Jordan-Nelson added the fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch label Mar 8, 2023
@Jordan-Nelson
Copy link
Contributor

This issue has been addressed in v1.0.0 of Amplify Flutter, which is now stable. See the comment above for a link to the docs.

This release also includes web and desktop support for Auth, API, Analytics, and Storage. You can see the list of new features and bug fixes in the release notes, and see more details on how to migrate in the upgrade guide.

Issues Triaging automation moved this from Feature Requests to Closed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category. fixed-in-release-candidate Issues that have been addressed in the current release-candidate branch GraphQL API Issues related to the API (GraphQL) Category
Projects
No open projects
Development

No branches or pull requests