Closed ritxweb closed 1 year ago
Hi @ritxweb 👋 thanks for raising this issue. Can you share your GraphQL schema, or at least the models you believe might be part of the issue?
Hi Anil, The graphql schema is the one described before:
type Item @model @auth(rules: [{allow: private}]) { pk: ID! @primaryKey(sortKeyFields: ["sk"]) sk: ID! }
My model now is different to bypass this issue so I don't have the completed one generated by Amplify after the transformer applies. Do you need this too?
DataStore does not yet support custom primary and composite keys. This feature will be released in the near future and will potentially resolve this issue.
pull request changes has been merged and waiting for the release. Will close the ticket once released.
Custom primary key support is now released in aws-amplify@4.3.38
/@aws-amplify/datastore@3.13.0
. Let us know if you have an issue after upgrading.
@dpilch I'm running into an issue where the 'ready' event never fires when we do the initial full sync.
DataStore - subscriptionError Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field 'id' in type 'OurModel' is undefined @ 'onDeleteOurModel/id'"}]}
I'm running "aws-amplify": "^5.0.4" and the model has Id: ID! @primaryKey
I have verified that when I revert the primary key back to the default id: ID!, the sync completes and the 'ready' event fires.
@mjmostachetti
I have verified that when I revert the primary key back to the default id: ID!, the sync completes and the 'ready' event fires. What do you mean by "revert the primary key"? Changing the primary key on a model is a destructive action and will probably result in invalid data.
Are you using the latest version of the Amplify CLI? If not, please upgrade and regenerate your models with amplify codegen models
.
Can you share your schema and give us reproduction steps like your schema before & after the primary key change so that we can reproduce your issue?
Yeah. I'm using the latest cli. Unfortunately I'm not going to share my schema. All our models are using the default id except for this one, so the repro steps would be create a few models with the default "id: ID!" and one model with "Id: ID! @PrimaryKey". Run an app w/ the hub events and see that you get the 'ready' event for datastore when you pull. When I reverted that one model back to "id: ID!" it worked again.
This is also in a fresh environment with no data - re: your comment about a destructive action.
In amplify/cli.json
is respectprimarykeyattributesonconnectionfield
set to true?
At the moment respectprimarykeyattributesonconnectionfield is set to false - I'd assume it was also set to false previously. I don't recall setting this field or modifying it.
At the moment respectprimarykeyattributesonconnectionfield is set to false - I'd assume it was also set to false previously. I don't recall setting this field or modifying it.
Flip it to true, regenerate your models, and let us know if the issue persists!
This is required for custom primary keys in DataStore to work
More info: https://docs.amplify.aws/cli/reference/feature-flags/#respectPrimaryKeyAttributesOnConnectionField
Good to know. Thanks for the info.
Before opening, please confirm:
JavaScript Framework
Angular
Amplify APIs
GraphQL API, DataStore
Amplify Categories
api
Environment information
Describe the bug
System fails to sync on startup when creating a model providing a custom primary key composed by partition key and sort key. From this point none of the sync subscriptions works and updates DataStore. It looks like, on startup, system tries to initialize the subscriptions using the default "id" field as primary key but the model is using as primary key a composite key composed by the fields "pk" and "sk", as specified in the schema. It is weird because I can still see socket messages from the server of a new instance created in the backend but DataStore is not actualized with this new instances. The Api subscriptions also work and react to onCreate events.
Expected behavior
Model sync and reacting to new instances created on the backend.
Reproduction steps
PS C:> amplify add api
? Select from one of the below mentioned services: GraphQL ? Here is the GraphQL API that we will create. Select a setting to edit or continue Name: **** ? Provide API name: **** ? Here is the GraphQL API that we will create. Select a setting to edit or continue Authorization modes: API key (default, expiration time: 7 days from now) ? Choose the default authorization type for the API Amazon Cognito User Pool Use a Cognito user pool configured as a part of this project. ? Configure additional auth types? No ? Here is the GraphQL API that we will create. Select a setting to edit or continue Conflict detection (required for DataStore): Disabled ? Enable conflict detection? Yes ? Select the default resolution strategy Auto Merge ? Here is the GraphQL API that we will create. Select a setting to edit or continue Continue ? Choose a schema template: Single object with fields (e.g., “Todo” with ID, name, description)
Learn more about "@auth" authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules ✅ GraphQL schema compiled successfully.
Edit your schema at ...\amplify\backend\api******\schema.graphql or place .graphql files in a directory at ...\amplify\backend\api******\schema √ Do you want to edit the schema now? (Y/n) · no ✅ Successfully added resource **** locally
✅ Some next steps: "amplify push" will build all your local backend resources and provision it in the cloud "amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
PS C:> amplify push
/ Fetching updates to backend environment: dev from the cloud.✅ GraphQL schema compiled successfully.
Edit your schema at ...\amplify\backend\api*\schema.graphql or place .graphql files in a directory at ...\amplify\backend\api\\schema √ Successfully pulled backend environment dev from the cloud. \ Building resource api/****✅ GraphQL schema compiled successfully.
Edit your schema at ...\amplify\backend\api****\schema.graphql or place .graphql files in a directory at ...\amplify\backend\api****\schema
┌──────────┬──────────────────┬───────────┬───────────────────┐ │ Category │ Resource name │ Operation │ Provider plugin │ ├──────────┼──────────────────┼───────────┼───────────────────┤ │ Api │ *│ Create │ awscloudformation │ ├──────────┼──────────────────┼───────────┼───────────────────┤ │ Auth │ *** │ No Change │ awscloudformation │ ├──────────┼──────────────────┼───────────┼───────────────────┤ │ Storage │ ****│ No Change │ awscloudformation │ ├──────────┼──────────────────┼───────────┼───────────────────┤ │ Hosting │ amplifyhosting │ No Change │ │ └──────────┴──────────────────┴───────────┴───────────────────┘ ? Are you sure you want to continue? Yes ✅ GraphQL schema compiled successfully.
Edit your schema at ......\amplify\backend\api**\schema.graphql or place .graphql files in a directory at .....\amplify\backend\api***\schema
Edit your schema at .....\amplify\backend\api***\schema.graphql or place .graphql files in a directory at ...\amplify\backend\api****\schema ? Do you want to generate code for your newly created GraphQL API Yes ? Choose the code generation language target angular ? Enter the file name pattern of graphql queries, mutations and subscriptions src\graphql*\.graphql ? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions Yes ? Enter maximum statement depth [increase from default if your schema is deeply nested] 2 ? Enter the file name for the generated code src\app\API.service.ts
Deploying resources into dev environment. This will take a few minutes. ⠹ Deployment completed. Deploying root stack ****[ ================================-------- ] 4/5 amplify-****-dev-65545 AWS::CloudFormation::Stack UPDATE_COMPLETE Wed Sep 28 2022 20:32:24…
storagel AWS::CloudFormation::Stack UPDATE_COMPLETE Wed Sep 28 2022 20:27:41…
auth AWS::CloudFormation::Stack UPDATE_COMPLETE Wed Sep 28 2022 20:27:41…
api* AWS::CloudFormation::Stack CREATE_COMPLETE Wed Sep 28 2022 20:32:20…
Deployed api ****[ ======================================== ] 9/9 GraphQLAPI AWS::AppSync::GraphQLApi CREATE_COMPLETE Wed Sep 28 2022 20:27:54…
GraphQLAPI**** AWS::AppSync::DataSource CREATE_COMPLETE Wed Sep 28 2022 20:27:58…
AmplifyDataStore***… AWS::IAM::Role CREATE_COMPLETE Wed Sep 28 2022 20:28:19…
DataStore AWS::DynamoDB::Table CREATE_COMPLETE Wed Sep 28 2022 20:28:14…
GraphQLAPITransformerSchema3C… AWS::AppSync::GraphQLSchema CREATE_COMPLETE Wed Sep 28 2022 20:28:59…
DynamoDBAccess**** AWS::IAM::Policy CREATE_COMPLETE Wed Sep 28 2022 20:31:21…
Edit your schema at ...\amplify\backend\api****\schema.graphql or place .graphql files in a directory at ...\amplify\backend\api****\schema Successfully generated models. Generated models can be found in ...\src √ Code generated successfully and saved in file src\app\API.service.ts √ Successfully generated models in the cloud.
GraphQL endpoint: https://************************************************************.amazonaws.com/graphql
GraphQL transformer version: 2
PS C:>
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response