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
81 stars 71 forks source link

Cannot set enum to arguments in Function Mutation #2575

Open kita3222 opened 1 month ago

kita3222 commented 1 month ago

Environment information

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M2
  Memory: 173.20 MB / 24.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
  Yarn: 1.22.19 - ~/.nvm/versions/node/v20.9.0/bin/yarn
  npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
  pnpm: 8.11.0 - ~/.nvm/versions/node/v20.9.0/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.2
  @aws-amplify/backend-cli: 1.0.3
  aws-amplify: 6.3.4
  aws-cdk: 2.143.0
  aws-cdk-lib: 2.143.0
  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 I try to set ENUM in the arguments of the Function Mutation, I get the following error and cannot do a sandbox deploy.

Failed to instantiate data construct
Caused By: Schema validation failed.\n\nUnknown type "TestFunctionResolverTestEnum".\n\nGraphQL request:25:34\n25 |   TestFunctionResolver(testEnum: TestFunctionResolverTestEnum): EchoResponse @fu\n   |                                  ^\n   | nction(name: "FnTestFunctionResolver") @auth(rules: [{allow: private}]) 

Resolution: See the underlying error message for more details.

This is the definition of my function:

  TestFunctionResolver: a
    .mutation()
    .arguments({ testEnum: a.enum(["A", "B", "C"])})
    .returns(a.ref("EchoResponse"))
    .authorization((allow) => [allow.authenticated()])
    // 3. set the function has the handler
    .handler(a.handler.function(sayHello)),
ykethan commented 1 month ago

Hey👋, thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

hardchor commented 3 weeks ago

The same is true for refs:

  createTodo: a
    .mutation()
    .arguments({
      name: a.string().required(),
      title: a.string().required(),
      type: a.ref("TodoType"), // Type 'RefType<RefTypeArgFactory<"TodoType">, never, undefined>' is not assignable to type 'BaseModelField | EnumType<readonly string[]>'.
    })
    .returns(a.ref("TodoResponse"))
    .authorization((allow) => [allow.authenticated()])
    .handler(a.handler.function(defineFunction("createTodo"))),
AnilMaktala commented 3 weeks ago

Hey @kita3222, Thanks for raising this. We can reproduce the issue. Hence, marking this as a bug for the team to evaluate further.

image