aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
87 stars 73 forks source link

Custom query with ref argument causes TypeScript error #2706

Open ErlendHer opened 1 month ago

ErlendHer commented 1 month ago

Environment information

System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 248.41 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.17.1/bin/yarn
  npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
  pnpm: 9.4.0 - ~/.nvm/versions/node/v18.17.1/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.4
  @aws-amplify/backend-cli: 1.1.0
  aws-amplify: 6.4.0
  aws-cdk: 2.148.1
  aws-cdk-lib: 2.148.1
  typescript: 5.4.5
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

When trying to use a customType or enum as input to a query, TypeScript is not happy.

const schema = a
  .schema({
    Foo: a.enum(["BAR", "BAZ"]),

    customQuery: a.query().arguments({
      foo: a.ref("Foo") // Type 'RefType<RefTypeArgFactory<"Foo">, never, undefined>' is not assignable to type 'ModelField<any, any> | EnumType<EnumTypeParamShape>'
    })
  })

This won't compile because of the type error. However the functionality seems to work just fine, so if you cast it to any it will successfully deploy and it works as expected.

chrisbonifacio commented 1 month ago

Hi @ErlendHer thanks for raising this. I've marked it as a feature request for the team to consider. At the moment, arguments must be a scalar or an enum (inline).