Skip to content

Types not generated for non null return types for mutations #792

@mohammedsahl

Description

@mohammedsahl

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • 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?

v18.16.1

Amplify CLI Version

12.10.1

What operating system are you using?

Mac

Amplify Codegen Command

codegen

Describe the bug

Having a non null return type for a mutation doesn't generate the appropriate return type in API.service.ts. If I have a mutation like

type Mutation {
  updateFoo(bar: String!): String!
    @function(name: "ResolverFn")
    @auth(rules: [{ allow: groups, groups: ["User"] }])
}

The generated code in API.service.ts looks like

async UpdateFoo(bar: string): Promise<UpdateFooMutation> {
  const statement = `mutation UpdateFoo($bar: String!) {
      updateFoo(bar: $bar)
    }`;
  const gqlAPIServiceArguments: any = {
    bar
  };
  const response = (await API.graphql(
    graphqlOperation(statement, gqlAPIServiceArguments)
  )) as any;
  return <UpdateFooMutation>response.data.updateFoo;
}

But theres no UpdateFooMutation created

Expected behavior

I would expect codegen to generate the NonNullReturnTypeMutation type in API.service.ts. In the context of the bug description above it would be UpdateFooMutation

Reproduction steps

  1. Add the following to schema.graphql
updateFoo(bar: String!): String!
  @function(name: "ResolverFn")
  @auth(rules: [{ allow: groups, groups: ["User"] }])
  1. Run amplify api gql-compile && amplify codegen

GraphQL schema(s)

# Put schemas below this line
type Mutation {
  updateFoo(bar: String!): String!
    @function(name: "ResolverFn")
    @auth(rules: [{ allow: groups, groups: ["User"] }])
}

Log output

No response

Additional information

I get the following GeneratedMutation in mutations.ts

export const updateFoo = /* GraphQL */ `mutation UpdateFoo($bar: String!) {
  updateFoo(bar: $bar)
}
` as GeneratedMutation<
  APITypes.UpdateFooMutationVariables,
  APITypes.UpdateFooMutation
>;

This is the generated code in mutation.graphql

mutation UpdateFoo($bar: String!) {
  updateFoo(bar: $bar)
}

This is the generated code in graphql-schema.ts

export type UpdateFooMutationVariables = {
  bar: string,
};

export type UpdateFooMutation = {
  updateFoo: string,
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions