aws-amplify / aws-amplify/amplify-codegen

Can't generate models if schema used identifier function

Open
#909 1 comment 0 reactions 0 assignees View on GitHub
bug Gen 2 transferred
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### Environment information

```plain text
System:
OS: macOS 15.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 40.66 MB / 32.00 GB
Shell: /bin/zsh
Binaries:
Node: 22.6.0 - ~/.nvm/versions/node/v22.6.0/bin/node
Yarn: undefined - undefined
npm: 10.8.2 - ~/.nvm/versions/node/v22.6.0/bin/npm
pnpm: 9.11.0 - ~/.nvm/versions/node/v22.6.0/bin/pnpm
NPM Packages:
@aws-amplify/auth-construct: Not Found
@aws-amplify/backend: Not Found
@aws-amplify/backend-auth: Not Found
@aws-amplify/backend-cli: 1.4.2
@aws-amplify/backend-data: Not Found
@aws-amplify/backend-deployer: 1.1.9
@aws-amplify/backend-function: Not Found
@aws-amplify/backend-output-schemas: 1.4.0
@aws-amplify/backend-output-storage: Not Found
@aws-amplify/backend-secret: 1.1.5
@aws-amplify/backend-storage: Not Found
@aws-amplify/cli-core: 1.2.0
@aws-amplify/client-config: 1.5.2
@aws-amplify/deployed-backend-client: 1.4.2
@aws-amplify/form-generator: 1.0.3
@aws-amplify/model-generator: 1.0.9
@aws-amplify/platform-core: 1.2.0
@aws-amplify/plugin-types: 1.4.0
@aws-amplify/sandbox: 1.2.5
@aws-amplify/schema-generator: 1.2.5
aws-amplify: 6.8.2
aws-cdk: 2.164.1
aws-cdk-lib: 2.164.1
typescript: 5.6.3
AWS environment variables:
AWS_PAGER =
AWS_PROFILE = crowder
AWS_STS_REGIONAL_ENDPOINTS = regional
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables
```

### Describe the bug

It seems like if I specify an identifier on my schema models, then I'm not able to generate graphql-client-code. If I do have an identifier, whether composite or single value, i get the following error when I run the generate command:
`TypeError: Cannot read properties of undefined (reading 'primaryKeyInfo')`

### Reproduction steps

I have a schema model like so:
```typescript
Crowd: a
.model({
createdAt: a.timestamp().required(),
lastModifiedAt: a.timestamp(),
userId: a.id().required(),
user: a.belongsTo('User', 'userId'),
shopId: a.id().required(),
shop: a.belongsTo('Shop', 'shopId'),
offer: a.float(),
productURL: a.string(),
productId: a.string().required(),
})
.identifier(['userId', 'shopId', 'productId'])
.authorization((allow) => [allow.publicApiKey()])
```

The goal is to have a composite identifier made up of userId, shopId and productId, but I have also tried with just e.g shopId and gotten the same result.

The command I run is:
`npx ampx generate graphql-client-code --format modelgen --model-target dart --out lib/src/db --stack `

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.