Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the graphql operation as a constant in the generated genqlient file #238

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ When releasing a new version:
### New features:

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

### Bug fixes:

Expand Down
38 changes: 22 additions & 16 deletions example/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion generate/operation.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// The query or mutation executed by {{.Name}}.
const {{.Name}}Operation = `{{$.Body}}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well put a doc-comment on this? Probably just saying it's the query executed by {{.Name}}.


{{.Doc}}
func {{.Name}}(
{{if ne .Config.ContextType "-" -}}
Expand All @@ -15,7 +18,7 @@ func {{.Name}}(
) (*{{.ResponseName}}, {{if .Config.Extensions -}}map[string]interface{},{{end}} error) {
req := &graphql.Request{
OpName: "{{.Name}}",
Query: `{{.Body}}`,
Query: {{.Name}}Operation,
{{if .Input -}}
Variables: &{{.Input.GoName}}{
{{range .Input.Fields -}}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading