graphql-go / graphql-go/graphql

FragmentDefintion does not contain info about "on"

Open
#455 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

Assume you have a fragment like so
```graphql
fragment actionFragment on SomeAction {
intField
}
```

Just from looking at the fragment, we can identify several things:
1. The fragment name `actionFragment`
1. The fragment Selection fields: `intField`
1. The Type that we are using the fragment on: `SomeAction`

However, the fragment defintion does not contain any info about point 3. The only way I currently see to access this info would be to extract the location like so

```go
loc := fragment.GetLoc()
raw := loc.Source.Body[loc.Start:loc.End]
```

This would leave me with a []byte like so:
```
([]uint8) (len=50 cap=128) {
00000000 66 72 61 67 6d 65 6e 74 20 61 63 74 69 6f 6e 46 |fragment actionF|
00000010 72 61 67 6d 65 6e 74 20 6f 6e 20 53 6f 6d 65 41 |ragment on SomeA|
00000020 63 74 69 6f 6e 20 7b 20 69 6e 74 46 69 65 6c 64 |ction { intField|
00000030 20 7d | }|
}
```

I could now extract the info myself using a RegExp, however, that seems rather fragile. Am I using it incorrectly or is this a bug that the `FragmentDefinition` does not contain any info about this?

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.