amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

Adding a required "simple" data type return type on a graphql query makes codegen produce invalid typescript code

Open hisham opened this issue 3 years ago • 1 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

14.15.3

Amplify CLI Version

7.6.5

What operating system are you using?

mac

Amplify Categories

api

Amplify Commands

codegen

Describe the bug

Try this graphql query

  updateDate(
    newDate: AWSDateTime!
  ): AWSDateTime!
    @function(name: "MyGraphQLResolverFn-${env}")

The typescript codegen code produced will be:

  async UpdateDate(
    newDate: string
  ): Promise<UpdateDateQuery>

But the type UpdateDateQuery won't be defined in API.service.ts

If I remove the exclamation mark in the AWSDateTime return type, then return type is accurately Promise<string | null>. So why can't I get it to return Promise<string>?

Expected behavior

generated code should return Promise<string>

Reproduction steps

See above description

GraphQL schema(s)

See above

Log output

# Put your logs below this line


Additional information

No response

hisham avatar Jan 04 '22 22:01 hisham