99designs / 99designs/gqlgen

CollectFields doesn't traverse fragment spread without exhaustive list of interface chain

オープン
#2,684 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
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 はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。