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
This commit is contained in:
Craig Silverstein
2022-11-21 08:35:09 -08:00
committed by GitHub
parent 00f27609f0
commit 587f77046b
58 changed files with 779 additions and 556 deletions
+22 -16
View File
@@ -69,6 +69,16 @@ func (v *getViewerViewerUser) GetMyName() string { return v.MyName }
// GetCreatedAt returns getViewerViewerUser.CreatedAt, and is useful for accessing the field via an interface.
func (v *getViewerViewerUser) GetCreatedAt() time.Time { return v.CreatedAt }
// The query or mutation executed by getUser.
const getUserOperation = `
query getUser ($Login: String!) {
user(login: $Login) {
theirName: name
createdAt
}
}
`
// getUser gets the given user's name from their username.
func getUser(
ctx context.Context,
@@ -77,14 +87,7 @@ func getUser(
) (*getUserResponse, error) {
req := &graphql.Request{
OpName: "getUser",
Query: `
query getUser ($Login: String!) {
user(login: $Login) {
theirName: name
createdAt
}
}
`,
Query: getUserOperation,
Variables: &__getUserInput{
Login: Login,
},
@@ -103,20 +106,23 @@ query getUser ($Login: String!) {
return &data, err
}
func getViewer(
ctx context.Context,
client graphql.Client,
) (*getViewerResponse, error) {
req := &graphql.Request{
OpName: "getViewer",
Query: `
// The query or mutation executed by getViewer.
const getViewerOperation = `
query getViewer {
viewer {
MyName: name
createdAt
}
}
`,
`
func getViewer(
ctx context.Context,
client graphql.Client,
) (*getViewerResponse, error) {
req := &graphql.Request{
OpName: "getViewer",
Query: getViewerOperation,
}
var err error