aws-amplify / aws-amplify/amplify-codegen
Querying multiple top-level fields only returns the the first one
- 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/master/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?
v16.13.1
### Amplify CLI Version
7.6.23
### What operating system are you using?
Mac OS
### Amplify Codegen Command
codegen, codegen types
### Describe the bug
Amplify generates types (API service in case of angular) which automatically returns first top-level field from the operation. When querying multiple top-level fields in one operation with custom query only the first one is returned.
```graphql
query Sessions($userId: ID!, $now: String!) {
upcoming: sessionsByUser(userID: $userId, startTime: { ge: $now }, sortDirection: ASC) {
items { ... }
nextToken
}
past: sessionsByUser(userID: $userId, startTime: { lt: $now }, sortDirection: DESC) {
items { ... }
nextToken
}
```
```typescript
// api.service.ts
async Sessions(userId: string, now: string): Promise {
// ...
return response.data.upcoming;
}
```
### Expected behavior
Generated method should return the whole data object if there's more than one top-level field.
```typescript
return response.data;
```
and also `SessionQuery` type should contain definition for those two connections, not just one `ModelSessionConnection`.
### Reproduction steps
1. Create custom query that will query multiple top-level fields (either different or same ones using alias)
2. Run `amplify codegen types`
3. Observe what has Amplify generated in configured `generatedFileName` location
### GraphQL schema(s)
```graphql
# Put schemas below this line
```
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.