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

fix(introspection): primary key info when pk is belongsTo field #570

Merged
merged 4 commits into from
Apr 12, 2023

Conversation

AaronZyLee
Copy link
Contributor

@AaronZyLee AaronZyLee commented Apr 12, 2023

The introspection schema will generate a primaryKeyInfo for each model intermediate representation. It is not correctly retrieved when the following conditions are met:

  • the primary key is the belongsTo connection field(targetName)
  • The feature flag value respectprimarykeyattributesonconnectionfield is set to false

This will trigger the code block and remove the pk field from the representation
https://github.com/aws-amplify/amplify-codegen/blob/main/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts#L1023-L1039

Description of changes

Add condition check to block the execution of field removal for that scenario

Issue #, if available

Fix aws-amplify/amplify-category-api#1399

Description of how you validated changes

yarn test
amplify-dev codegen model-introspection --output-dir .

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • Breaking changes to existing customers are released behind a feature flag or major version update
  • Changes are tested using sample applications for all relevant platforms (iOS/android/flutter/Javascript) that use the feature added/modified

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@AaronZyLee AaronZyLee requested a review from a team as a code owner April 12, 2023 02:13
Copy link
Contributor

@phani-srikar phani-srikar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include some context in the PR description as it is not clear from the title what this is accomplishing.

@@ -1028,7 +1028,9 @@ export class AppSyncModelVisitor<
connectionInfo &&
connectionInfo.kind !== CodeGenConnectionType.HAS_MANY &&
connectionInfo.kind !== CodeGenConnectionType.HAS_ONE &&
connectionInfo.targetName !== 'id'
connectionInfo.targetName !== 'id' &&
!(this.config.target === 'introspection' &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the other targets that are valid here and why this fix only required for "introspection" target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other targets are controlled by the feature flag value. For introspection, there are cases where the app has CPK value as false and the code block above is entered. That's why it is protected not to execute the line when target is introspection and belongsTo connnection field is primary key

@AaronZyLee AaronZyLee requested a review from phani-srikar April 12, 2023 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic build of hosting environment fails with error: Cannot read property 'primaryKeyInfo' of undefined
2 participants