Same field in two different fragments is returned multiple times by `collectFields`
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
### What happened?
For this query:
```
fragment TaskID on Task {
remoteId: id
remoteType: __typename
}
fragment Task on Task {
title
remoteId: id
completed
}
query {
queryTask {
...TaskID
...Task
}
}
```
the selection set returned by `collectFields` on `queryTask` contains `remoteId: id` field twice. Probably related to #1300, but seems like a different issue because aliases are used and the fragment is on the same type.
### What did you expect?
I expect that the `remoteId: id` field should be returned only once in the selection set returned by `collectFields`.
### Minimal graphql.schema and models to reproduce
```
type Task {
id: ID!
title: String!
completed: Boolean!
}
```
### versions
- `gqlgen version`? v0.12.2
- `go version`? go1.14 linux/amd64
- dep or go modules? go modules
Contributor guide
Research direction
The issue is in the `collectFields` function, likely in the code generation or runtime selection set merging logic. Start by examining the `graphql/execution/collectFields.go` or similar files in the gqlgen source. Look for how fields from fragments are merged, especially when aliases are used. Write a test that reproduces the duplicate field issue using the provided query and schema. Verify the fix by ensuring the selection set contains each field only once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, graphql
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100