gh-projects icon indicating copy to clipboard operation
gh-projects copied to clipboard

Compact GraphQL queries

Open heaths opened this issue 3 years ago • 2 comments

Create a tool to compact GraphQL queries using go:generate and update gock matchers to then take compacted queries so we can assert variables as well.

heaths avatar Jun 19 '22 17:06 heaths

See https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module for how to track the tool dependency while using it only during tool runs. Also see https://spec.graphql.org/draft/#sec-Document: a .graphql file can contain multiple named definitions, or a single unnamed definition. Given this, might be worth a separate tool if none other can be found.

https://pkg.go.dev/github.com/wundergraph/graphql-go-tools may be of some use. It has separate parse and visitor modules that could be useful to generate not only compacted GraphQL constants, but also data structures if desired: generating data structures should be considered pri-2 though since I don't really need or even want them for this project. For example, several data structures are reused for multiple definitions that have a subset of nodes.

heaths avatar Jun 20 '22 18:06 heaths

For some inspiration, see https://go.dev/blog/generate and https://cs.opensource.google/go/x/tools/+/master:cmd/stringer/stringer.go

heaths avatar Jun 20 '22 21:06 heaths