You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A model that has composite identifier will cause TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo') while generating graphql model client code
TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')
[DEBUG] 2024-09-18T10:20:44.432Z: TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')
at AppSyncModelDartVisitor.getModelIdentifierFields (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:874:51)
at AppSyncModelDartVisitor.generateGetters (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:268:47)
at AppSyncModelDartVisitor.generateModelClass (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:168:14)
at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:116:43
at Array.forEach (<anonymous>)
at AppSyncModelDartVisitor.generateModelClasses (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:115:50)
at AppSyncModelDartVisitor.generate (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\visitors\appsync-dart-visitor.js:31:21)
at Object.plugin (G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\appsync-modelgen-plugin\lib\plugin.js:55:24)
at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\graphql-generator\node_modules\@graphql-codegen\core\cjs\execute-plugin.js:36:54
at G:\ADSATS\adsats_amplify_gen_2\node_modules\@aws-amplify\graphql-generator\node_modules\@graphql-codegen\core\node_modules\@graphql-codegen\plugin-helpers\cjs\profiler.js:7:49
How can this bug be reproduced?
Create two models and a many-to-many model in between
Specify the identifiers by those two Ids
Run npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/models --branch dev --debug
Please include any code snippets or screenshots that you think would be helpful!
I have found a solution in #887. We are removing the foreign keys on the belongsTo model for native platforms (dart, java, swift). This is done to improve the developer experience, but it does present an issue when the foreign key is also used as part of the primary key.
We will need to do some testing with the native platforms to ensure the proposed fix does not cause other issues. For now, you can work around this issue by using a different field for your primary key.
Environment information
Codegen packages
Description
Describe the bug:
A model that has composite identifier will cause
TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')
while generating graphql model client codeHow can this bug be reproduced?
npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/models --branch dev --debug
Please include any code snippets or screenshots that you think would be helpful!
npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/models --branch dev --debug
The text was updated successfully, but these errors were encountered: