-
Notifications
You must be signed in to change notification settings - Fork 64
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
Conversation
There was a problem hiding this 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.
...plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap
Outdated
Show resolved
Hide resolved
@@ -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' && |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
The introspection schema will generate a
primaryKeyInfo
for each model intermediate representation. It is not correctly retrieved when the following conditions are met:belongsTo
connection field(targetName)respectprimarykeyattributesonconnectionfield
is set to falseThis 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
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.