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

Generated swift model for a hasOne relation uses incorrect arguments #883

Open
concavegit opened this issue Sep 23, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@concavegit
Copy link

Environment information

System:
  OS: macOS 15.0
  CPU: (8) arm64 Apple M2
  Memory: 129.42 MB / 24.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 22.9.0 - /opt/homebrew/bin/node
  Yarn: undefined - undefined
  npm: 10.8.3 - /opt/homebrew/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.3.1
  @aws-amplify/backend: 1.3.0
  @aws-amplify/backend-auth: 1.2.0
  @aws-amplify/backend-cli: 1.2.8
  @aws-amplify/backend-data: 1.1.4
  @aws-amplify/backend-deployer: 1.1.3
  @aws-amplify/backend-function: 1.5.0
  @aws-amplify/backend-output-schemas: 1.2.0
  @aws-amplify/backend-output-storage: 1.1.2
  @aws-amplify/backend-secret: 1.1.2
  @aws-amplify/backend-storage: 1.2.0
  @aws-amplify/cli-core: 1.1.3
  @aws-amplify/client-config: 1.3.1
  @aws-amplify/deployed-backend-client: 1.4.1
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.8
  @aws-amplify/platform-core: 1.1.0
  @aws-amplify/plugin-types: 1.3.0
  @aws-amplify/sandbox: 1.2.2
  @aws-amplify/schema-generator: 1.2.4
  aws-amplify: 6.6.2
  aws-cdk: 2.159.1
  aws-cdk-lib: 2.159.1
  typescript: 5.6.2
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Codegen packages

kanaiamplify@1.0.0 /Users/concaveusr/Projects/KanaiAmplify
└─┬ @aws-amplify/backend-cli@1.2.8
  └─┬ @aws-amplify/model-generator@1.0.8
    └── @aws-amplify/graphql-generator@0.4.5

Description

hasOne relations generate incorrect Swift code.

If I define a hasOne model like this:

const schema = a.schema({
  Cart: a.model({
    customerId: a.id(),
    customer: a.belongsTo('Customer', 'customerId'),
  }),
  Customer: a.model({
    activeCart: a.hasOne('Cart', 'customerId')
  }),
});

Then the Swift generated code has a line like

    model.fields(
...
      .hasOne(customer.activeCart, is: .optional, ofType: Cart.self, associatedFields: [Cart.customerId])
...
    )

This throws the following errors:

Argument type '[Cart.CodingKeys]' does not conform to expected type 'CodingKey'
Incorrect argument label in call (have '_:is:ofType:associatedFields:', expected '_:is:ofType:associatedWith:')

I can silence these errors by using the correct function label associatedWith and by removing the square brackets:

      .hasOne(customer.activeCart, is: .optional, ofType: Cart.self, associatedWith: Cart.customerId)
@concavegit concavegit added the pending-triage Issues that need further discussion to determine label Sep 23, 2024
@dpilch dpilch added bug Something isn't working and removed pending-triage Issues that need further discussion to determine labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants