CollectFields doesn't traverse fragment spread without exhaustive list of interface chain
- 主要言語
- Go
- スター
- 10.8k
- フォーク
- 1.3k
- 平均マージ
- 2日 36分
- マージ済み PR(30日)
- 26
説明
### What happened?
I am facing unexpected behaviour when client sends request with fragments. Here is an example schema:
```graphql
interface Node {
id: ID!
}
type Foo implements Node {
id: ID!
foo: String
}
type Bar implements Node {
id: ID!
bar: String
}
type Query {
node(id: ID!): Node
}
```
Query without fragment:
```graphql
query TestWithoutFragment {
node {
id
... on Foo {
foo
}
... on Bar {
bar
}
}
}
```
Query with fragment:
```graphql
fragment TestFragment on Node {
id
... on Foo {
foo
}
... on Bar {
bar
}
}
query TestWithFragment {
node {
...NodeFragment
}
}
```
`graphql.CollectFieldsCtx(ctx, []string{"Foo"})` doesn't return anything for the query with fragment. It is required to include the interface as well (`graphql.CollectFieldsCtx(ctx, []string{"Foo", "Node"})`).
### What did you expect?
Consistent behaviour of CollectFields regardless if client request is querying fields directly or through fragment. I believe that fragments should be always traversed (https://github.com/99designs/gqlgen/blob/ee6add4bddd7ee05e31a37815f281c320eb44e26/graphql/executable_schema.go#LL79C13-L79C13). It can cause unexpected issues across the code base when introducing interfaces.
### versions
- v0.17.20
- go version go1.20.5 darwin/arm64
コントリビューションガイド
評価
この issue はまだ評価されていません。