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

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

Open
4 tasks done
mohammedsahl opened this issue Mar 6, 2024 · 1 comment
Open
4 tasks done

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

mohammedsahl opened this issue Mar 6, 2024 · 1 comment
Labels
angular-js bug Something isn't working

Comments

@mohammedsahl
Copy link

mohammedsahl commented Mar 6, 2024

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,
};
@dpilch
Copy link
Contributor

dpilch commented Apr 2, 2024

I was able to reproduce this issue. This will be resolved for customers using Amplify JS library V6 with #799.

An additional fix is needed for V5 customers.

@dpilch dpilch added bug Something isn't working angular-js labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular-js bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants