aws-amplify / aws-amplify/amplify-codegen

Types not generated for non null return types for mutations

Open
#792 1 comment 2 reactions 0 assignees View on GitHub
angular-js bug
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### 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](https://github.com/aws-amplify/amplify-codegen/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-codegen/blob/main/CONTRIBUTING.md#bugs).
- [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?

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 {
const statement = `mutation UpdateFoo($bar: String!) {
updateFoo(bar: $bar)
}`;
const gqlAPIServiceArguments: any = {
bar
};
const response = (await API.graphql(
graphqlOperation(statement, gqlAPIServiceArguments)
)) as any;
return 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"] }])
```
2. Run amplify api gql-compile && amplify codegen

### GraphQL schema(s)

```graphql
# 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,
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.