Skip to content

Commit 587f770

Browse files
authored
Expose the graphql operation as a constant in the generated genqlient file (#238)
This allows client code to see the operation (query or mutation) exactly as genqlient sends it over the wire. This data was already available in the generated safelist.json file, but now it's easily available from Go code as well. Fixes #236 I have: - [x] Written a clear PR title and description (above) - [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla) - [x] Added tests covering my changes, if applicable - [x] Included a link to the issue fixed, if applicable - [x] Included documentation, for new features - [x] Added an entry to the changelog
1 parent 00f2760 commit 587f770

File tree

58 files changed

+779
-556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+779
-556
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ When releasing a new version:
2525
### New features:
2626

2727
- You can now bind all types from a package in `genqlient.yaml` using the new `package_bindings` option.
28+
- The graphql operation (query or mutation) as sent over the wire is now exposed via a constant in the generated genqlient .go file.
2829

2930
### Bug fixes:
3031

example/generated.go

Lines changed: 22 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/operation.go.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// The query or mutation executed by {{.Name}}.
2+
const {{.Name}}Operation = `{{$.Body}}`
3+
14
{{.Doc}}
25
func {{.Name}}(
36
{{if ne .Config.ContextType "-" -}}
@@ -15,7 +18,7 @@ func {{.Name}}(
1518
) (*{{.ResponseName}}, {{if .Config.Extensions -}}map[string]interface{},{{end}} error) {
1619
req := &graphql.Request{
1720
OpName: "{{.Name}}",
18-
Query: `{{.Body}}`,
21+
Query: {{.Name}}Operation,
1922
{{if .Input -}}
2023
Variables: &{{.Input.GoName}}{
2124
{{range .Input.Fields -}}

generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-CovariantInterfaceImplementation.graphql-CovariantInterfaceImplementation.graphql.go

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)