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

Cannot set enum to arguments in Function Mutation #2575

Closed
kita3222 opened this issue May 28, 2024 · 6 comments
Closed

Cannot set enum to arguments in Function Mutation #2575

kita3222 opened this issue May 28, 2024 · 6 comments
Assignees

Comments

@kita3222
Copy link
Contributor

kita3222 commented May 28, 2024

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
Copy link
Member

ykethan commented May 28, 2024

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

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend May 28, 2024
@AnilMaktala AnilMaktala self-assigned this May 28, 2024
@hardchor
Copy link

hardchor commented Jun 4, 2024

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
Copy link
Member

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

image

@AnilMaktala AnilMaktala added bug Something isn't working data-schema and removed pending-triage labels Jun 6, 2024
@dzhan-aws dzhan-aws added feature-request New feature or request and removed bug Something isn't working labels Jun 19, 2024
@AnilMaktala AnilMaktala removed their assignment Jul 16, 2024
@iartemiev
Copy link
Member

Hi @kita3222, we just added support for this feature.

Please run the following to update your dependencies:

npm install @aws-amplify/backend@latest @aws-amplify/backend-cli@latest aws-amplify@latest
npm update @aws-amplify/data-schema

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@jtweeks
Copy link

jtweeks commented Dec 16, 2024

I am still unable to assign a ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants