-
Notifications
You must be signed in to change notification settings - Fork 283
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
Support specifying operation names. #12
Comments
@seanpile has already created PR #8 that resolves this issue. In it, he mentioned:
This package is still in an early period where we can change the API (see README), so what we need to do is determine which would be the overall best API. During the process of reviewing that PR, I've considered these two alternatives:
Same decision would apply to At this point, I'm quite torn between the two options. Which is a better API? Feedback appreciated. |
👍 for case 1, documenting that an empty string will generate a query without a name. Perhaps an exported const (e.g., |
I'd like to put a third option on the table: an "options" vararg. func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}, opts Option...) error { ... } Usage is then roughly like: client.Query(ctx, &structure, variables) // no name
client.Query(ctx, &structure, variables, graphql.NamedQuery("foobaz")) // named The Cheney-style "functional options" pattern is one nice way of implementing this. An interface with an unexported marker function, a handful of structs implementing it, and a type-switch inside the Query method has the same effect; they're just coded out a little differently. There are two reasons I like this option for this particular issue: because naming queries is indeed optional; and also, naming a query is not a dramatic change in how the function behaves (and thus, making a whole new function seems to communicate more significance than there is). |
Operation names are described at http://graphql.org/learn/queries/#operation-name:
Notably, it's most useful to be able to provide operation names for server-side logging and debugging reasons.
We should support this.
The text was updated successfully, but these errors were encountered: