diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c6a78278..1067018e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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: diff --git a/example/generated.go b/example/generated.go index 72ce68e8..11aa8678 100644 --- a/example/generated.go +++ b/example/generated.go @@ -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 diff --git a/generate/operation.go.tmpl b/generate/operation.go.tmpl index b379e9fb..d5d33f33 100644 --- a/generate/operation.go.tmpl +++ b/generate/operation.go.tmpl @@ -1,3 +1,6 @@ +// The query or mutation executed by {{.Name}}. +const {{.Name}}Operation = `{{$.Body}}` + {{.Doc}} func {{.Name}}( {{if ne .Config.ContextType "-" -}} @@ -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 -}} diff --git a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go index 7ab10c03..ba8d7578 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go @@ -1340,17 +1340,8 @@ func (v *ComplexInlineFragmentsRootTopic) GetSchoolGrade() string { return v.Sch // GetName returns ComplexInlineFragmentsRootTopic.Name, and is useful for accessing the field via an interface. func (v *ComplexInlineFragmentsRootTopic) GetName() string { return v.Name } -// We test all the spread cases from docs/DESIGN.md, see there for more context -// on each, as well as various other nonsense. But for abstract-in-abstract -// spreads, we can't test cases (4b) and (4c), where I implements J or vice -// versa, because gqlparser doesn't support interfaces that implement other -// interfaces yet. -func ComplexInlineFragments( - client graphql.Client, -) (*ComplexInlineFragmentsResponse, error) { - req := &graphql.Request{ - OpName: "ComplexInlineFragments", - Query: ` +// The query or mutation executed by ComplexInlineFragments. +const ComplexInlineFragmentsOperation = ` query ComplexInlineFragments { root { id @@ -1436,7 +1427,19 @@ query ComplexInlineFragments { } } } -`, +` + +// We test all the spread cases from docs/DESIGN.md, see there for more context +// on each, as well as various other nonsense. But for abstract-in-abstract +// spreads, we can't test cases (4b) and (4c), where I implements J or vice +// versa, because gqlparser doesn't support interfaces that implement other +// interfaces yet. +func ComplexInlineFragments( + client graphql.Client, +) (*ComplexInlineFragmentsResponse, error) { + req := &graphql.Request{ + OpName: "ComplexInlineFragments", + Query: ComplexInlineFragmentsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go index 43402302..da9158d4 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go @@ -1739,12 +1739,8 @@ type VideoFieldsThumbnail struct { // GetId returns VideoFieldsThumbnail.Id, and is useful for accessing the field via an interface. func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } -func ComplexNamedFragments( - client graphql.Client, -) (*ComplexNamedFragmentsResponse, error) { - req := &graphql.Request{ - OpName: "ComplexNamedFragments", - Query: ` +// The query or mutation executed by ComplexNamedFragments. +const ComplexNamedFragmentsOperation = ` query ComplexNamedFragments { ... on Query { ... QueryFragment @@ -1802,7 +1798,14 @@ fragment MoreVideoFields on Video { } } } -`, +` + +func ComplexNamedFragments( + client graphql.Client, +) (*ComplexNamedFragmentsResponse, error) { + req := &graphql.Request{ + OpName: "ComplexNamedFragments", + Query: ComplexNamedFragmentsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-CovariantInterfaceImplementation.graphql-CovariantInterfaceImplementation.graphql.go b/generate/testdata/snapshots/TestGenerate-CovariantInterfaceImplementation.graphql-CovariantInterfaceImplementation.graphql.go index fa45389b..ff193741 100644 --- a/generate/testdata/snapshots/TestGenerate-CovariantInterfaceImplementation.graphql-CovariantInterfaceImplementation.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CovariantInterfaceImplementation.graphql-CovariantInterfaceImplementation.graphql.go @@ -2346,12 +2346,8 @@ type TopicFieldsRelatedTopic struct { // GetId returns TopicFieldsRelatedTopic.Id, and is useful for accessing the field via an interface. func (v *TopicFieldsRelatedTopic) GetId() testutil.ID { return v.Id } -func CovariantInterfaceImplementation( - client graphql.Client, -) (*CovariantInterfaceImplementationResponse, error) { - req := &graphql.Request{ - OpName: "CovariantInterfaceImplementation", - Query: ` +// The query or mutation executed by CovariantInterfaceImplementation. +const CovariantInterfaceImplementationOperation = ` query CovariantInterfaceImplementation { randomItem { __typename @@ -2394,7 +2390,14 @@ fragment TopicFields on Topic { id } } -`, +` + +func CovariantInterfaceImplementation( + client graphql.Client, +) (*CovariantInterfaceImplementationResponse, error) { + req := &graphql.Request{ + OpName: "CovariantInterfaceImplementation", + Query: CovariantInterfaceImplementationOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go index 595a301c..c94287ed 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go @@ -174,20 +174,23 @@ func (v *__CustomMarshalInput) __premarshalJSON() (*__premarshal__CustomMarshalI return &retval, nil } -func CustomMarshal( - client graphql.Client, - date time.Time, -) (*CustomMarshalResponse, error) { - req := &graphql.Request{ - OpName: "CustomMarshal", - Query: ` +// The query or mutation executed by CustomMarshal. +const CustomMarshalOperation = ` query CustomMarshal ($date: Date!) { usersBornOn(date: $date) { id birthdate } } -`, +` + +func CustomMarshal( + client graphql.Client, + date time.Time, +) (*CustomMarshalResponse, error) { + req := &graphql.Request{ + OpName: "CustomMarshal", + Query: CustomMarshalOperation, Variables: &__CustomMarshalInput{ Date: date, }, diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go index 39544dda..7816b2ea 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go @@ -203,6 +203,14 @@ func (v *__CustomMarshalSliceInput) __premarshalJSON() (*__premarshal__CustomMar return &retval, nil } +// The query or mutation executed by CustomMarshalSlice. +const CustomMarshalSliceOperation = ` +query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { + acceptsListOfListOfListsOfDates(datesss: $datesss) + withPointer: acceptsListOfListOfListsOfDates(datesss: $datesssp) +} +` + func CustomMarshalSlice( client graphql.Client, datesss [][][]time.Time, @@ -210,12 +218,7 @@ func CustomMarshalSlice( ) (*CustomMarshalSliceResponse, error) { req := &graphql.Request{ OpName: "CustomMarshalSlice", - Query: ` -query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { - acceptsListOfListOfListsOfDates(datesss: $datesss) - withPointer: acceptsListOfListOfListsOfDates(datesss: $datesssp) -} -`, + Query: CustomMarshalSliceOperation, Variables: &__CustomMarshalSliceInput{ Datesss: datesss, Datesssp: datesssp, diff --git a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go index 94e069d1..e4e58e7d 100644 --- a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go @@ -28,6 +28,13 @@ type convertTimezoneResponse struct { // GetConvert returns convertTimezoneResponse.Convert, and is useful for accessing the field via an interface. func (v *convertTimezoneResponse) GetConvert() time.Time { return v.Convert } +// The query or mutation executed by convertTimezone. +const convertTimezoneOperation = ` +query convertTimezone ($dt: DateTime!, $tz: String) { + convert(dt: $dt, tz: $tz) +} +` + func convertTimezone( client graphql.Client, dt time.Time, @@ -35,11 +42,7 @@ func convertTimezone( ) (*convertTimezoneResponse, error) { req := &graphql.Request{ OpName: "convertTimezone", - Query: ` -query convertTimezone ($dt: DateTime!, $tz: String) { - convert(dt: $dt, tz: $tz) -} -`, + Query: convertTimezoneOperation, Variables: &__convertTimezoneInput{ Dt: dt, Tz: tz, diff --git a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go index 0b302932..5d1c9953 100644 --- a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go @@ -20,17 +20,20 @@ func (v *EmptyInterfaceResponse) GetGetComplexJunk() []map[string]*[]*map[string return v.GetComplexJunk } +// The query or mutation executed by EmptyInterface. +const EmptyInterfaceOperation = ` +query EmptyInterface { + getJunk + getComplexJunk +} +` + func EmptyInterface( client graphql.Client, ) (*EmptyInterfaceResponse, error) { req := &graphql.Request{ OpName: "EmptyInterface", - Query: ` -query EmptyInterface { - getJunk - getComplexJunk -} -`, + Query: EmptyInterfaceOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go index 0e8fbac9..a7d0d433 100644 --- a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go @@ -266,12 +266,8 @@ type VideoFieldsParentTopic struct { // GetVideoChildren returns VideoFieldsParentTopic.VideoChildren, and is useful for accessing the field via an interface. func (v *VideoFieldsParentTopic) GetVideoChildren() []ChildVideoFields { return v.VideoChildren } -func ComplexNamedFragments( - client graphql.Client, -) (*InnerQueryFragment, error) { - req := &graphql.Request{ - OpName: "ComplexNamedFragments", - Query: ` +// The query or mutation executed by ComplexNamedFragments. +const ComplexNamedFragmentsOperation = ` query ComplexNamedFragments { ... QueryFragment } @@ -306,7 +302,14 @@ fragment ChildVideoFields on Video { id name } -`, +` + +func ComplexNamedFragments( + client graphql.Client, +) (*InnerQueryFragment, error) { + req := &graphql.Request{ + OpName: "ComplexNamedFragments", + Query: ComplexNamedFragmentsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go index b1f28d81..3fc1252b 100644 --- a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go @@ -54,19 +54,22 @@ type __InputEnumQueryInput struct { // GetRole returns __InputEnumQueryInput.Role, and is useful for accessing the field via an interface. func (v *__InputEnumQueryInput) GetRole() Role { return v.Role } +// The query or mutation executed by InputEnumQuery. +const InputEnumQueryOperation = ` +query InputEnumQuery ($role: Role!) { + usersWithRole(role: $role) { + id + } +} +` + func InputEnumQuery( client graphql.Client, role Role, ) (*InputEnumQueryResponse, error) { req := &graphql.Request{ OpName: "InputEnumQuery", - Query: ` -query InputEnumQuery ($role: Role!) { - usersWithRole(role: $role) { - id - } -} -`, + Query: InputEnumQueryOperation, Variables: &__InputEnumQueryInput{ Role: role, }, diff --git a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go index 11c207fa..52f8d3d4 100644 --- a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go @@ -177,19 +177,22 @@ type __InputObjectQueryInput struct { // GetQuery returns __InputObjectQueryInput.Query, and is useful for accessing the field via an interface. func (v *__InputObjectQueryInput) GetQuery() UserQueryInput { return v.Query } +// The query or mutation executed by InputObjectQuery. +const InputObjectQueryOperation = ` +query InputObjectQuery ($query: UserQueryInput) { + user(query: $query) { + id + } +} +` + func InputObjectQuery( client graphql.Client, query UserQueryInput, ) (*InputObjectQueryResponse, error) { req := &graphql.Request{ OpName: "InputObjectQuery", - Query: ` -query InputObjectQuery ($query: UserQueryInput) { - user(query: $query) { - id - } -} -`, + Query: InputObjectQueryOperation, Variables: &__InputObjectQueryInput{ Query: query, }, diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go index f1847810..e7ba26e2 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go @@ -520,12 +520,8 @@ func (v *InterfaceListFieldWithPointerTopicChildrenVideo) GetId() testutil.ID { // GetName returns InterfaceListFieldWithPointerTopicChildrenVideo.Name, and is useful for accessing the field via an interface. func (v *InterfaceListFieldWithPointerTopicChildrenVideo) GetName() string { return v.Name } -func InterfaceListField( - client graphql.Client, -) (*InterfaceListFieldResponse, error) { - req := &graphql.Request{ - OpName: "InterfaceListField", - Query: ` +// The query or mutation executed by InterfaceListField. +const InterfaceListFieldOperation = ` query InterfaceListField { root { id @@ -546,7 +542,14 @@ query InterfaceListField { } } } -`, +` + +func InterfaceListField( + client graphql.Client, +) (*InterfaceListFieldResponse, error) { + req := &graphql.Request{ + OpName: "InterfaceListField", + Query: InterfaceListFieldOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go index ef6a32de..e49ae85f 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go @@ -506,12 +506,8 @@ func (v *InterfaceListOfListOfListsFieldWithPointerVideo) GetId() *testutil.ID { // GetName returns InterfaceListOfListOfListsFieldWithPointerVideo.Name, and is useful for accessing the field via an interface. func (v *InterfaceListOfListOfListsFieldWithPointerVideo) GetName() *string { return v.Name } -func InterfaceListOfListOfListsField( - client graphql.Client, -) (*InterfaceListOfListOfListsFieldResponse, error) { - req := &graphql.Request{ - OpName: "InterfaceListOfListOfListsField", - Query: ` +// The query or mutation executed by InterfaceListOfListOfListsField. +const InterfaceListOfListOfListsFieldOperation = ` query InterfaceListOfListOfListsField { listOfListsOfListsOfContent { __typename @@ -524,7 +520,14 @@ query InterfaceListOfListOfListsField { name } } -`, +` + +func InterfaceListOfListOfListsField( + client graphql.Client, +) (*InterfaceListOfListOfListsFieldResponse, error) { + req := &graphql.Request{ + OpName: "InterfaceListOfListOfListsField", + Query: InterfaceListOfListOfListsFieldOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go index 53617249..25d7077b 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go @@ -504,12 +504,8 @@ func (v *InterfaceNestingRootTopicChildrenVideo) GetParent() InterfaceNestingRoo return v.Parent } -func InterfaceNesting( - client graphql.Client, -) (*InterfaceNestingResponse, error) { - req := &graphql.Request{ - OpName: "InterfaceNesting", - Query: ` +// The query or mutation executed by InterfaceNesting. +const InterfaceNestingOperation = ` query InterfaceNesting { root { id @@ -526,7 +522,14 @@ query InterfaceNesting { } } } -`, +` + +func InterfaceNesting( + client graphql.Client, +) (*InterfaceNestingResponse, error) { + req := &graphql.Request{ + OpName: "InterfaceNesting", + Query: InterfaceNestingOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go index 4fa885f4..4648b125 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go @@ -626,12 +626,8 @@ func (v *InterfaceNoFragmentsQueryWithPointerVideo) GetId() *testutil.ID { retur // GetName returns InterfaceNoFragmentsQueryWithPointerVideo.Name, and is useful for accessing the field via an interface. func (v *InterfaceNoFragmentsQueryWithPointerVideo) GetName() *string { return v.Name } -func InterfaceNoFragmentsQuery( - client graphql.Client, -) (*InterfaceNoFragmentsQueryResponse, error) { - req := &graphql.Request{ - OpName: "InterfaceNoFragmentsQuery", - Query: ` +// The query or mutation executed by InterfaceNoFragmentsQuery. +const InterfaceNoFragmentsQueryOperation = ` query InterfaceNoFragmentsQuery { root { id @@ -653,7 +649,14 @@ query InterfaceNoFragmentsQuery { name } } -`, +` + +func InterfaceNoFragmentsQuery( + client graphql.Client, +) (*InterfaceNoFragmentsQueryResponse, error) { + req := &graphql.Request{ + OpName: "InterfaceNoFragmentsQuery", + Query: InterfaceNoFragmentsQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go index 818104a7..e08df1af 100644 --- a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go @@ -41,19 +41,22 @@ type __ListInputQueryInput struct { // GetNames returns __ListInputQueryInput.Names, and is useful for accessing the field via an interface. func (v *__ListInputQueryInput) GetNames() []string { return v.Names } +// The query or mutation executed by ListInputQuery. +const ListInputQueryOperation = ` +query ListInputQuery ($names: [String]) { + user(query: {names:$names}) { + id + } +} +` + func ListInputQuery( client graphql.Client, names []string, ) (*ListInputQueryResponse, error) { req := &graphql.Request{ OpName: "ListInputQuery", - Query: ` -query ListInputQuery ($names: [String]) { - user(query: {names:$names}) { - id - } -} -`, + Query: ListInputQueryOperation, Variables: &__ListInputQueryInput{ Names: names, }, diff --git a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go index b77ff404..14d135c4 100644 --- a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go @@ -16,16 +16,19 @@ func (v *ListOfListsOfListsResponse) GetListOfListsOfLists() [][][]string { return v.ListOfListsOfLists } +// The query or mutation executed by ListOfListsOfLists. +const ListOfListsOfListsOperation = ` +query ListOfListsOfLists { + listOfListsOfLists +} +` + func ListOfListsOfLists( client graphql.Client, ) (*ListOfListsOfListsResponse, error) { req := &graphql.Request{ OpName: "ListOfListsOfLists", - Query: ` -query ListOfListsOfLists { - listOfListsOfLists -} -`, + Query: ListOfListsOfListsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go index bb88e674..7ef5f060 100644 --- a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go @@ -325,14 +325,8 @@ func (v *__MultipleDirectivesInput) GetQuery() MyInput { return v.Query } // GetQueries returns __MultipleDirectivesInput.Queries, and is useful for accessing the field via an interface. func (v *__MultipleDirectivesInput) GetQueries() []*UserQueryInput { return v.Queries } -func MultipleDirectives( - client graphql.Client, - query MyInput, - queries []*UserQueryInput, -) (*MyMultipleDirectivesResponse, error) { - req := &graphql.Request{ - OpName: "MultipleDirectives", - Query: ` +// The query or mutation executed by MultipleDirectives. +const MultipleDirectivesOperation = ` query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { user(query: $query) { id @@ -341,7 +335,16 @@ query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { id } } -`, +` + +func MultipleDirectives( + client graphql.Client, + query MyInput, + queries []*UserQueryInput, +) (*MyMultipleDirectivesResponse, error) { + req := &graphql.Request{ + OpName: "MultipleDirectives", + Query: MultipleDirectivesOperation, Variables: &__MultipleDirectivesInput{ Query: query, Queries: queries, diff --git a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go index 1284f951..d402035f 100644 --- a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go @@ -219,17 +219,8 @@ func (v *__OmitEmptyQueryInput) GetTz() string { return v.Tz } // GetTzNoOmitEmpty returns __OmitEmptyQueryInput.TzNoOmitEmpty, and is useful for accessing the field via an interface. func (v *__OmitEmptyQueryInput) GetTzNoOmitEmpty() string { return v.TzNoOmitEmpty } -func OmitEmptyQuery( - client graphql.Client, - query UserQueryInput, - queries []UserQueryInput, - dt time.Time, - tz string, - tzNoOmitEmpty string, -) (*OmitEmptyQueryResponse, error) { - req := &graphql.Request{ - OpName: "OmitEmptyQuery", - Query: ` +// The query or mutation executed by OmitEmptyQuery. +const OmitEmptyQueryOperation = ` query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: DateTime, $tz: String, $tzNoOmitEmpty: String) { user(query: $query) { id @@ -240,7 +231,19 @@ query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: D maybeConvert(dt: $dt, tz: $tz) convert2: maybeConvert(dt: $dt, tz: $tzNoOmitEmpty) } -`, +` + +func OmitEmptyQuery( + client graphql.Client, + query UserQueryInput, + queries []UserQueryInput, + dt time.Time, + tz string, + tzNoOmitEmpty string, +) (*OmitEmptyQueryResponse, error) { + req := &graphql.Request{ + OpName: "OmitEmptyQuery", + Query: OmitEmptyQueryOperation, Variables: &__OmitEmptyQueryInput{ Query: query, Queries: queries, diff --git a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go index 879eaf2b..f519b05c 100644 --- a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go @@ -230,15 +230,8 @@ func (v *__PointersQueryInput) GetDt() time.Time { return v.Dt } // GetTz returns __PointersQueryInput.Tz, and is useful for accessing the field via an interface. func (v *__PointersQueryInput) GetTz() *string { return v.Tz } -func PointersQuery( - client graphql.Client, - query *UserQueryInput, - dt time.Time, - tz *string, -) (*PointersQueryResponse, error) { - req := &graphql.Request{ - OpName: "PointersQuery", - Query: ` +// The query or mutation executed by PointersQuery. +const PointersQueryOperation = ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { user(query: $query) { id @@ -252,7 +245,17 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { } maybeConvert(dt: $dt, tz: $tz) } -`, +` + +func PointersQuery( + client graphql.Client, + query *UserQueryInput, + dt time.Time, + tz *string, +) (*PointersQueryResponse, error) { + req := &graphql.Request{ + OpName: "PointersQuery", + Query: PointersQueryOperation, Variables: &__PointersQueryInput{ Query: query, Dt: dt, diff --git a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go index 8f0274ad..9330e378 100644 --- a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go @@ -227,15 +227,8 @@ func (v *__PointersQueryInput) GetDt() *time.Time { return v.Dt } // GetTz returns __PointersQueryInput.Tz, and is useful for accessing the field via an interface. func (v *__PointersQueryInput) GetTz() string { return v.Tz } -func PointersQuery( - client graphql.Client, - query *UserQueryInput, - dt *time.Time, - tz string, -) (*PointersQueryResponse, error) { - req := &graphql.Request{ - OpName: "PointersQuery", - Query: ` +// The query or mutation executed by PointersQuery. +const PointersQueryOperation = ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { user(query: $query) { id @@ -249,7 +242,17 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { } maybeConvert(dt: $dt, tz: $tz) } -`, +` + +func PointersQuery( + client graphql.Client, + query *UserQueryInput, + dt *time.Time, + tz string, +) (*PointersQueryResponse, error) { + req := &graphql.Request{ + OpName: "PointersQuery", + Query: PointersQueryOperation, Variables: &__PointersQueryInput{ Query: query, Dt: dt, diff --git a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go index 749e8796..1580b9c2 100644 --- a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go @@ -71,13 +71,8 @@ type __GetPokemonSiblingsInput struct { // GetInput returns __GetPokemonSiblingsInput.Input, and is useful for accessing the field via an interface. func (v *__GetPokemonSiblingsInput) GetInput() testutil.Pokemon { return v.Input } -func GetPokemonSiblings( - client graphql.Client, - input testutil.Pokemon, -) (*GetPokemonSiblingsResponse, error) { - req := &graphql.Request{ - OpName: "GetPokemonSiblings", - Query: ` +// The query or mutation executed by GetPokemonSiblings. +const GetPokemonSiblingsOperation = ` query GetPokemonSiblings ($input: PokemonInput!) { user(query: {hasPokemon:$input}) { id @@ -93,7 +88,15 @@ query GetPokemonSiblings ($input: PokemonInput!) { } } } -`, +` + +func GetPokemonSiblings( + client graphql.Client, + input testutil.Pokemon, +) (*GetPokemonSiblingsResponse, error) { + req := &graphql.Request{ + OpName: "GetPokemonSiblings", + Query: GetPokemonSiblingsOperation, Variables: &__GetPokemonSiblingsInput{ Input: input, }, diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go index 784bbb32..8ac66abe 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go @@ -40,19 +40,22 @@ func (v *QueryWithAliasUser) GetID() testutil.ID { return v.ID } // GetOtherID returns QueryWithAliasUser.OtherID, and is useful for accessing the field via an interface. func (v *QueryWithAliasUser) GetOtherID() testutil.ID { return v.OtherID } -func QueryWithAlias( - client graphql.Client, -) (*QueryWithAliasResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithAlias", - Query: ` +// The query or mutation executed by QueryWithAlias. +const QueryWithAliasOperation = ` query QueryWithAlias { User: user { ID: id otherID: id } } -`, +` + +func QueryWithAlias( + client graphql.Client, +) (*QueryWithAliasResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithAlias", + Query: QueryWithAliasOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go index 6e2213ac..80b898a3 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go @@ -40,19 +40,22 @@ func (v *QueryWithDoubleAliasUser) GetID() testutil.ID { return v.ID } // GetAlsoID returns QueryWithDoubleAliasUser.AlsoID, and is useful for accessing the field via an interface. func (v *QueryWithDoubleAliasUser) GetAlsoID() testutil.ID { return v.AlsoID } -func QueryWithDoubleAlias( - client graphql.Client, -) (*QueryWithDoubleAliasResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithDoubleAlias", - Query: ` +// The query or mutation executed by QueryWithDoubleAlias. +const QueryWithDoubleAliasOperation = ` query QueryWithDoubleAlias { user { ID: id AlsoID: id } } -`, +` + +func QueryWithDoubleAlias( + client graphql.Client, +) (*QueryWithDoubleAliasResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithDoubleAlias", + Query: QueryWithDoubleAliasOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go index 52f51996..e5d6e992 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go @@ -62,12 +62,8 @@ const ( RoleTeacher Role = "TEACHER" ) -func QueryWithEnums( - client graphql.Client, -) (*QueryWithEnumsResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithEnums", - Query: ` +// The query or mutation executed by QueryWithEnums. +const QueryWithEnumsOperation = ` query QueryWithEnums { user { roles @@ -76,7 +72,14 @@ query QueryWithEnums { roles } } -`, +` + +func QueryWithEnums( + client graphql.Client, +) (*QueryWithEnumsResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithEnums", + Query: QueryWithEnumsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go index e7347faf..dd946617 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go @@ -41,12 +41,8 @@ func (v *QueryWithSlicesUser) GetEmailsWithNulls() []string { return v.EmailsWit // GetEmailsWithNullsOrNull returns QueryWithSlicesUser.EmailsWithNullsOrNull, and is useful for accessing the field via an interface. func (v *QueryWithSlicesUser) GetEmailsWithNullsOrNull() []string { return v.EmailsWithNullsOrNull } -func QueryWithSlices( - client graphql.Client, -) (*QueryWithSlicesResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithSlices", - Query: ` +// The query or mutation executed by QueryWithSlices. +const QueryWithSlicesOperation = ` query QueryWithSlices { user { emails @@ -55,7 +51,14 @@ query QueryWithSlices { emailsWithNullsOrNull } } -`, +` + +func QueryWithSlices( + client graphql.Client, +) (*QueryWithSlicesResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithSlices", + Query: QueryWithSlicesOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go index 63ac7fbf..6d869448 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go @@ -43,12 +43,8 @@ func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetProvider() string { retur // GetEmail returns QueryWithStructsUserAuthMethodsAuthMethod.Email, and is useful for accessing the field via an interface. func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetEmail() string { return v.Email } -func QueryWithStructs( - client graphql.Client, -) (*QueryWithStructsResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithStructs", - Query: ` +// The query or mutation executed by QueryWithStructs. +const QueryWithStructsOperation = ` query QueryWithStructs { user { authMethods { @@ -57,7 +53,14 @@ query QueryWithStructs { } } } -`, +` + +func QueryWithStructs( + client graphql.Client, +) (*QueryWithStructsResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithStructs", + Query: QueryWithStructsOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go index b8cab24c..34c7aa50 100644 --- a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go @@ -68,13 +68,8 @@ type __RecursionInput struct { // GetInput returns __RecursionInput.Input, and is useful for accessing the field via an interface. func (v *__RecursionInput) GetInput() RecursiveInput { return v.Input } -func Recursion( - client graphql.Client, - input RecursiveInput, -) (*RecursionResponse, error) { - req := &graphql.Request{ - OpName: "Recursion", - Query: ` +// The query or mutation executed by Recursion. +const RecursionOperation = ` query Recursion ($input: RecursiveInput!) { recur(input: $input) { rec { @@ -86,7 +81,15 @@ query Recursion ($input: RecursiveInput!) { } } } -`, +` + +func Recursion( + client graphql.Client, + input RecursiveInput, +) (*RecursionResponse, error) { + req := &graphql.Request{ + OpName: "Recursion", + Query: RecursionOperation, Variables: &__RecursionInput{ Input: input, }, diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go index 19a572e1..ef669ea8 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go @@ -239,12 +239,8 @@ func (v *SimpleInlineFragmentResponse) __premarshalJSON() (*__premarshalSimpleIn return &retval, nil } -func SimpleInlineFragment( - client graphql.Client, -) (*SimpleInlineFragmentResponse, error) { - req := &graphql.Request{ - OpName: "SimpleInlineFragment", - Query: ` +// The query or mutation executed by SimpleInlineFragment. +const SimpleInlineFragmentOperation = ` query SimpleInlineFragment { randomItem { __typename @@ -258,7 +254,14 @@ query SimpleInlineFragment { } } } -`, +` + +func SimpleInlineFragment( + client graphql.Client, +) (*SimpleInlineFragmentResponse, error) { + req := &graphql.Request{ + OpName: "SimpleInlineFragment", + Query: SimpleInlineFragmentOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go index 7fe46d49..90662070 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go @@ -41,19 +41,22 @@ type __SimpleInputQueryInput struct { // GetName returns __SimpleInputQueryInput.Name, and is useful for accessing the field via an interface. func (v *__SimpleInputQueryInput) GetName() string { return v.Name } +// The query or mutation executed by SimpleInputQuery. +const SimpleInputQueryOperation = ` +query SimpleInputQuery ($name: String!) { + user(query: {name:$name}) { + id + } +} +` + func SimpleInputQuery( client graphql.Client, name string, ) (*SimpleInputQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleInputQuery", - Query: ` -query SimpleInputQuery ($name: String!) { - user(query: {name:$name}) { - id - } -} -`, + Query: SimpleInputQueryOperation, Variables: &__SimpleInputQueryInput{ Name: name, }, diff --git a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go index 15a13fb8..26ea8b58 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go @@ -41,6 +41,16 @@ type __SimpleMutationInput struct { // GetName returns __SimpleMutationInput.Name, and is useful for accessing the field via an interface. func (v *__SimpleMutationInput) GetName() string { return v.Name } +// The query or mutation executed by SimpleMutation. +const SimpleMutationOperation = ` +mutation SimpleMutation ($name: String!) { + createUser(name: $name) { + id + name + } +} +` + // SimpleMutation creates a user. // // It has a long doc-comment, to test that we handle that correctly. @@ -51,14 +61,7 @@ func SimpleMutation( ) (*SimpleMutationResponse, error) { req := &graphql.Request{ OpName: "SimpleMutation", - Query: ` -mutation SimpleMutation ($name: String!) { - createUser(name: $name) { - id - name - } -} -`, + Query: SimpleMutationOperation, Variables: &__SimpleMutationInput{ Name: name, }, diff --git a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go index 4c6aaffa..98829db4 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go @@ -546,12 +546,8 @@ type VideoFieldsThumbnail struct { // GetId returns VideoFieldsThumbnail.Id, and is useful for accessing the field via an interface. func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } -func SimpleNamedFragment( - client graphql.Client, -) (*SimpleNamedFragmentResponse, error) { - req := &graphql.Request{ - OpName: "SimpleNamedFragment", - Query: ` +// The query or mutation executed by SimpleNamedFragment. +const SimpleNamedFragmentOperation = ` query SimpleNamedFragment { randomItem { __typename @@ -573,7 +569,14 @@ fragment VideoFields on Video { id } } -`, +` + +func SimpleNamedFragment( + client graphql.Client, +) (*SimpleNamedFragmentResponse, error) { + req := &graphql.Request{ + OpName: "SimpleNamedFragment", + Query: SimpleNamedFragmentOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go index 645e1115..88cfa7fa 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go @@ -33,18 +33,21 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() testutil.ID { return v.Id } -func SimpleQuery( - client graphql.Client, -) (*SimpleQueryResponse, error) { - req := &graphql.Request{ - OpName: "SimpleQuery", - Query: ` +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` query SimpleQuery { user { id } } -`, +` + +func SimpleQuery( + client graphql.Client, +) (*SimpleQueryResponse, error) { + req := &graphql.Request{ + OpName: "SimpleQuery", + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go index b9a78041..c4ea74dd 100644 --- a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go @@ -424,12 +424,8 @@ type VideoFields struct { // GetDuration returns VideoFields.Duration, and is useful for accessing the field via an interface. func (v *VideoFields) GetDuration() int { return v.Duration } -func StructOption( - client graphql.Client, -) (*StructOptionResponse, error) { - req := &graphql.Request{ - OpName: "StructOption", - Query: ` +// The query or mutation executed by StructOption. +const StructOptionOperation = ` query StructOption { root { id @@ -457,7 +453,14 @@ query StructOption { fragment VideoFields on Video { duration } -`, +` + +func StructOption( + client graphql.Client, +) (*StructOptionResponse, error) { + req := &graphql.Request{ + OpName: "StructOption", + Query: StructOptionOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go index 899cc2da..b1b499eb 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go @@ -37,19 +37,22 @@ func (v *TypeNameQueryUser) GetTypename() string { return v.Typename } // GetId returns TypeNameQueryUser.Id, and is useful for accessing the field via an interface. func (v *TypeNameQueryUser) GetId() testutil.ID { return v.Id } -func TypeNameQuery( - client graphql.Client, -) (*TypeNameQueryResponse, error) { - req := &graphql.Request{ - OpName: "TypeNameQuery", - Query: ` +// The query or mutation executed by TypeNameQuery. +const TypeNameQueryOperation = ` query TypeNameQuery { user { __typename id } } -`, +` + +func TypeNameQuery( + client graphql.Client, +) (*TypeNameQueryResponse, error) { + req := &graphql.Request{ + OpName: "TypeNameQuery", + Query: TypeNameQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go index 0149b955..fd3b5361 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go @@ -264,12 +264,8 @@ func (v *User) GetId() testutil.ID { return v.Id } // GetName returns User.Name, and is useful for accessing the field via an interface. func (v *User) GetName() string { return v.Name } -func TypeNames( - client graphql.Client, -) (*Resp, error) { - req := &graphql.Request{ - OpName: "TypeNames", - Query: ` +// The query or mutation executed by TypeNames. +const TypeNamesOperation = ` query TypeNames { user { id @@ -285,7 +281,14 @@ query TypeNames { name } } -`, +` + +func TypeNames( + client graphql.Client, +) (*Resp, error) { + req := &graphql.Request{ + OpName: "TypeNames", + Query: TypeNamesOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go index 2df6bf63..f3bfa4c1 100644 --- a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go @@ -174,18 +174,21 @@ func (v *UnionNoFragmentsQueryResponse) __premarshalJSON() (*__premarshalUnionNo return &retval, nil } -func UnionNoFragmentsQuery( - client graphql.Client, -) (*UnionNoFragmentsQueryResponse, error) { - req := &graphql.Request{ - OpName: "UnionNoFragmentsQuery", - Query: ` +// The query or mutation executed by UnionNoFragmentsQuery. +const UnionNoFragmentsQueryOperation = ` query UnionNoFragmentsQuery { randomLeaf { __typename } } -`, +` + +func UnionNoFragmentsQuery( + client graphql.Client, +) (*UnionNoFragmentsQueryResponse, error) { + req := &graphql.Request{ + OpName: "UnionNoFragmentsQuery", + Query: UnionNoFragmentsQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go index 06b39fe6..fd4bdf30 100644 --- a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go @@ -62,12 +62,8 @@ func (v *UsesEnumTwiceQueryResponse) GetMe() UsesEnumTwiceQueryMeUser { return v // GetOtherUser returns UsesEnumTwiceQueryResponse.OtherUser, and is useful for accessing the field via an interface. func (v *UsesEnumTwiceQueryResponse) GetOtherUser() UsesEnumTwiceQueryOtherUser { return v.OtherUser } -func UsesEnumTwiceQuery( - client graphql.Client, -) (*UsesEnumTwiceQueryResponse, error) { - req := &graphql.Request{ - OpName: "UsesEnumTwiceQuery", - Query: ` +// The query or mutation executed by UsesEnumTwiceQuery. +const UsesEnumTwiceQueryOperation = ` query UsesEnumTwiceQuery { Me: user { roles @@ -76,7 +72,14 @@ query UsesEnumTwiceQuery { roles } } -`, +` + +func UsesEnumTwiceQuery( + client graphql.Client, +) (*UsesEnumTwiceQueryResponse, error) { + req := &graphql.Request{ + OpName: "UsesEnumTwiceQuery", + Query: UsesEnumTwiceQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go index ddae85b1..b5a5599f 100644 --- a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go @@ -177,19 +177,22 @@ type unexportedUser struct { // GetId returns unexportedUser.Id, and is useful for accessing the field via an interface. func (v *unexportedUser) GetId() testutil.ID { return v.Id } +// The query or mutation executed by unexported. +const unexportedOperation = ` +query unexported ($query: UserQueryInput) { + user(query: $query) { + id + } +} +` + func unexported( client graphql.Client, query UserQueryInput, ) (*unexportedResponse, error) { req := &graphql.Request{ OpName: "unexported", - Query: ` -query unexported ($query: UserQueryInput) { - user(query: $query) { - id - } -} -`, + Query: unexportedOperation, Variables: &__unexportedInput{ Query: query, }, diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go index d5ac56db..5dd0b268 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go @@ -35,18 +35,21 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } -func SimpleQuery( - ctx context.Context, -) (*SimpleQueryResponse, error) { - req := &graphql.Request{ - OpName: "SimpleQuery", - Query: ` +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` query SimpleQuery { user { id } } -`, +` + +func SimpleQuery( + ctx context.Context, +) (*SimpleQueryResponse, error) { + req := &graphql.Request{ + OpName: "SimpleQuery", + Query: SimpleQueryOperation, } var err error var client graphql.Client diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go index 61b5518f..0121661b 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go @@ -38,18 +38,21 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } -func SimpleQuery( - ctx testutil.MyContext, -) (*SimpleQueryResponse, error) { - req := &graphql.Request{ - OpName: "SimpleQuery", - Query: ` +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` query SimpleQuery { user { id } } -`, +` + +func SimpleQuery( + ctx testutil.MyContext, +) (*SimpleQueryResponse, error) { + req := &graphql.Request{ + OpName: "SimpleQuery", + Query: SimpleQueryOperation, } var err error var client graphql.Client diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go index e35911a6..ae5d59a5 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go @@ -33,16 +33,19 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } -func SimpleQuery() (*SimpleQueryResponse, error) { - req := &graphql.Request{ - OpName: "SimpleQuery", - Query: ` +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` query SimpleQuery { user { id } } -`, +` + +func SimpleQuery() (*SimpleQueryResponse, error) { + req := &graphql.Request{ + OpName: "SimpleQuery", + Query: SimpleQueryOperation, } var err error var client graphql.Client diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go index 790ecb8d..7b9fa54e 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go @@ -38,19 +38,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx testutil.MyContext, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContextWithAlias-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContextWithAlias-testdata-queries-generated.go index 7664d61e..e3a0cafc 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContextWithAlias-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContextWithAlias-testdata-queries-generated.go @@ -38,19 +38,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx junkfunname.MyContext, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go index bb9d5d5d..b86415e2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go index bb9d5d5d..b86415e2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go index 691c2ba4..1c28ab57 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, map[string]interface{}, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go index 5318ac79..1c0821c6 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go @@ -32,18 +32,21 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } -func SimpleQuery( - client graphql.Client, -) (*SimpleQueryResponse, error) { - req := &graphql.Request{ - OpName: "SimpleQuery", - Query: ` +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` query SimpleQuery { user { id } } -`, +` + +func SimpleQuery( + client graphql.Client, +) (*SimpleQueryResponse, error) { + req := &graphql.Request{ + OpName: "SimpleQuery", + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-OptionalPointer-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-OptionalPointer-testdata-queries-generated.go index 72a5a552..d2aa7457 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-OptionalPointer-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-OptionalPointer-testdata-queries-generated.go @@ -77,6 +77,15 @@ type __ListInputQueryInput struct { // GetNames returns __ListInputQueryInput.Names, and is useful for accessing the field via an interface. func (v *__ListInputQueryInput) GetNames() []*string { return v.Names } +// The query or mutation executed by ListInputQuery. +const ListInputQueryOperation = ` +query ListInputQuery ($names: [String]) { + user(query: {names:$names}) { + id + } +} +` + func ListInputQuery( ctx context.Context, client graphql.Client, @@ -84,13 +93,7 @@ func ListInputQuery( ) (*ListInputQueryResponse, error) { req := &graphql.Request{ OpName: "ListInputQuery", - Query: ` -query ListInputQuery ($names: [String]) { - user(query: {names:$names}) { - id - } -} -`, + Query: ListInputQueryOperation, Variables: &__ListInputQueryInput{ Names: names, }, @@ -109,13 +112,8 @@ query ListInputQuery ($names: [String]) { return &data, err } -func QueryWithSlices( - ctx context.Context, - client graphql.Client, -) (*QueryWithSlicesResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithSlices", - Query: ` +// The query or mutation executed by QueryWithSlices. +const QueryWithSlicesOperation = ` query QueryWithSlices { user { emails @@ -124,7 +122,15 @@ query QueryWithSlices { emailsWithNullsOrNull } } -`, +` + +func QueryWithSlices( + ctx context.Context, + client graphql.Client, +) (*QueryWithSlicesResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithSlices", + Query: QueryWithSlicesOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-OptionalValue-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-OptionalValue-testdata-queries-generated.go index 7d6fafe3..e40ef8f7 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-OptionalValue-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-OptionalValue-testdata-queries-generated.go @@ -77,6 +77,15 @@ type __ListInputQueryInput struct { // GetNames returns __ListInputQueryInput.Names, and is useful for accessing the field via an interface. func (v *__ListInputQueryInput) GetNames() []string { return v.Names } +// The query or mutation executed by ListInputQuery. +const ListInputQueryOperation = ` +query ListInputQuery ($names: [String]) { + user(query: {names:$names}) { + id + } +} +` + func ListInputQuery( ctx context.Context, client graphql.Client, @@ -84,13 +93,7 @@ func ListInputQuery( ) (*ListInputQueryResponse, error) { req := &graphql.Request{ OpName: "ListInputQuery", - Query: ` -query ListInputQuery ($names: [String]) { - user(query: {names:$names}) { - id - } -} -`, + Query: ListInputQueryOperation, Variables: &__ListInputQueryInput{ Names: names, }, @@ -109,13 +112,8 @@ query ListInputQuery ($names: [String]) { return &data, err } -func QueryWithSlices( - ctx context.Context, - client graphql.Client, -) (*QueryWithSlicesResponse, error) { - req := &graphql.Request{ - OpName: "QueryWithSlices", - Query: ` +// The query or mutation executed by QueryWithSlices. +const QueryWithSlicesOperation = ` query QueryWithSlices { user { emails @@ -124,7 +122,15 @@ query QueryWithSlices { emailsWithNullsOrNull } } -`, +` + +func QueryWithSlices( + ctx context.Context, + client graphql.Client, +) (*QueryWithSlicesResponse, error) { + req := &graphql.Request{ + OpName: "QueryWithSlices", + Query: QueryWithSlicesOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-PackageBindings-testdata-queries b/generate/testdata/snapshots/TestGenerateWithConfig-PackageBindings-testdata-queries index aa424915..90516894 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-PackageBindings-testdata-queries +++ b/generate/testdata/snapshots/TestGenerateWithConfig-PackageBindings-testdata-queries @@ -35,19 +35,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() testutil.ID { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go index d6dea59b..61ccf497 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go b/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go index 31993fd2..1cb9f38e 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go index d6dea59b..61ccf497 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go index d6dea59b..61ccf497 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go @@ -34,19 +34,22 @@ type SimpleQueryUser struct { // GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface. func (v *SimpleQueryUser) GetId() string { return v.Id } +// The query or mutation executed by SimpleQuery. +const SimpleQueryOperation = ` +query SimpleQuery { + user { + id + } +} +` + func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { req := &graphql.Request{ OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, + Query: SimpleQueryOperation, } var err error diff --git a/internal/integration/generated.go b/internal/integration/generated.go index 13cbc2a4..922536dc 100644 --- a/internal/integration/generated.go +++ b/internal/integration/generated.go @@ -3078,6 +3078,16 @@ type simpleQueryResponse struct { // GetMe returns simpleQueryResponse.Me, and is useful for accessing the field via an interface. func (v *simpleQueryResponse) GetMe() simpleQueryMeUser { return v.Me } +// The query or mutation executed by createUser. +const createUserOperation = ` +mutation createUser ($user: NewUser!) { + createUser(input: $user) { + id + name + } +} +` + func createUser( ctx context.Context, client graphql.Client, @@ -3085,14 +3095,7 @@ func createUser( ) (*createUserResponse, map[string]interface{}, error) { req := &graphql.Request{ OpName: "createUser", - Query: ` -mutation createUser ($user: NewUser!) { - createUser(input: $user) { - id - name - } -} -`, + Query: createUserOperation, Variables: &__createUserInput{ User: user, }, @@ -3111,20 +3114,23 @@ mutation createUser ($user: NewUser!) { return &data, resp.Extensions, err } -func failingQuery( - ctx context.Context, - client graphql.Client, -) (*failingQueryResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "failingQuery", - Query: ` +// The query or mutation executed by failingQuery. +const failingQueryOperation = ` query failingQuery { fail me { id } } -`, +` + +func failingQuery( + ctx context.Context, + client graphql.Client, +) (*failingQueryResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "failingQuery", + Query: failingQueryOperation, } var err error @@ -3140,14 +3146,8 @@ query failingQuery { return &data, resp.Extensions, err } -func queryWithCustomMarshal( - ctx context.Context, - client graphql.Client, - date time.Time, -) (*queryWithCustomMarshalResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithCustomMarshal", - Query: ` +// The query or mutation executed by queryWithCustomMarshal. +const queryWithCustomMarshalOperation = ` query queryWithCustomMarshal ($date: Date!) { usersBornOn(date: $date) { id @@ -3155,7 +3155,16 @@ query queryWithCustomMarshal ($date: Date!) { birthdate } } -`, +` + +func queryWithCustomMarshal( + ctx context.Context, + client graphql.Client, + date time.Time, +) (*queryWithCustomMarshalResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithCustomMarshal", + Query: queryWithCustomMarshalOperation, Variables: &__queryWithCustomMarshalInput{ Date: date, }, @@ -3174,6 +3183,17 @@ query queryWithCustomMarshal ($date: Date!) { return &data, resp.Extensions, err } +// The query or mutation executed by queryWithCustomMarshalOptional. +const queryWithCustomMarshalOptionalOperation = ` +query queryWithCustomMarshalOptional ($date: Date, $id: ID) { + userSearch(birthdate: $date, id: $id) { + id + name + birthdate + } +} +` + func queryWithCustomMarshalOptional( ctx context.Context, client graphql.Client, @@ -3182,15 +3202,7 @@ func queryWithCustomMarshalOptional( ) (*queryWithCustomMarshalOptionalResponse, map[string]interface{}, error) { req := &graphql.Request{ OpName: "queryWithCustomMarshalOptional", - Query: ` -query queryWithCustomMarshalOptional ($date: Date, $id: ID) { - userSearch(birthdate: $date, id: $id) { - id - name - birthdate - } -} -`, + Query: queryWithCustomMarshalOptionalOperation, Variables: &__queryWithCustomMarshalOptionalInput{ Date: date, Id: id, @@ -3210,14 +3222,8 @@ query queryWithCustomMarshalOptional ($date: Date, $id: ID) { return &data, resp.Extensions, err } -func queryWithCustomMarshalSlice( - ctx context.Context, - client graphql.Client, - dates []time.Time, -) (*queryWithCustomMarshalSliceResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithCustomMarshalSlice", - Query: ` +// The query or mutation executed by queryWithCustomMarshalSlice. +const queryWithCustomMarshalSliceOperation = ` query queryWithCustomMarshalSlice ($dates: [Date!]!) { usersBornOnDates(dates: $dates) { id @@ -3225,7 +3231,16 @@ query queryWithCustomMarshalSlice ($dates: [Date!]!) { birthdate } } -`, +` + +func queryWithCustomMarshalSlice( + ctx context.Context, + client graphql.Client, + dates []time.Time, +) (*queryWithCustomMarshalSliceResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithCustomMarshalSlice", + Query: queryWithCustomMarshalSliceOperation, Variables: &__queryWithCustomMarshalSliceInput{ Dates: dates, }, @@ -3244,14 +3259,8 @@ query queryWithCustomMarshalSlice ($dates: [Date!]!) { return &data, resp.Extensions, err } -func queryWithFlatten( - ctx context.Context, - client graphql.Client, - ids []string, -) (*QueryFragment, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithFlatten", - Query: ` +// The query or mutation executed by queryWithFlatten. +const queryWithFlattenOperation = ` query queryWithFlatten ($ids: [ID!]!) { ... QueryFragment } @@ -3293,7 +3302,16 @@ fragment FriendsFields on User { id name } -`, +` + +func queryWithFlatten( + ctx context.Context, + client graphql.Client, + ids []string, +) (*QueryFragment, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithFlatten", + Query: queryWithFlattenOperation, Variables: &__queryWithFlattenInput{ Ids: ids, }, @@ -3312,14 +3330,8 @@ fragment FriendsFields on User { return &data, resp.Extensions, err } -func queryWithFragments( - ctx context.Context, - client graphql.Client, - ids []string, -) (*queryWithFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithFragments", - Query: ` +// The query or mutation executed by queryWithFragments. +const queryWithFragmentsOperation = ` query queryWithFragments ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3355,7 +3367,16 @@ query queryWithFragments ($ids: [ID!]!) { } } } -`, +` + +func queryWithFragments( + ctx context.Context, + client graphql.Client, + ids []string, +) (*queryWithFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithFragments", + Query: queryWithFragmentsOperation, Variables: &__queryWithFragmentsInput{ Ids: ids, }, @@ -3374,14 +3395,8 @@ query queryWithFragments ($ids: [ID!]!) { return &data, resp.Extensions, err } -func queryWithInterfaceListField( - ctx context.Context, - client graphql.Client, - ids []string, -) (*queryWithInterfaceListFieldResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithInterfaceListField", - Query: ` +// The query or mutation executed by queryWithInterfaceListField. +const queryWithInterfaceListFieldOperation = ` query queryWithInterfaceListField ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3389,7 +3404,16 @@ query queryWithInterfaceListField ($ids: [ID!]!) { name } } -`, +` + +func queryWithInterfaceListField( + ctx context.Context, + client graphql.Client, + ids []string, +) (*queryWithInterfaceListFieldResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithInterfaceListField", + Query: queryWithInterfaceListFieldOperation, Variables: &__queryWithInterfaceListFieldInput{ Ids: ids, }, @@ -3408,14 +3432,8 @@ query queryWithInterfaceListField ($ids: [ID!]!) { return &data, resp.Extensions, err } -func queryWithInterfaceListPointerField( - ctx context.Context, - client graphql.Client, - ids []string, -) (*queryWithInterfaceListPointerFieldResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithInterfaceListPointerField", - Query: ` +// The query or mutation executed by queryWithInterfaceListPointerField. +const queryWithInterfaceListPointerFieldOperation = ` query queryWithInterfaceListPointerField ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3423,7 +3441,16 @@ query queryWithInterfaceListPointerField ($ids: [ID!]!) { name } } -`, +` + +func queryWithInterfaceListPointerField( + ctx context.Context, + client graphql.Client, + ids []string, +) (*queryWithInterfaceListPointerFieldResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithInterfaceListPointerField", + Query: queryWithInterfaceListPointerFieldOperation, Variables: &__queryWithInterfaceListPointerFieldInput{ Ids: ids, }, @@ -3442,14 +3469,8 @@ query queryWithInterfaceListPointerField ($ids: [ID!]!) { return &data, resp.Extensions, err } -func queryWithInterfaceNoFragments( - ctx context.Context, - client graphql.Client, - id string, -) (*queryWithInterfaceNoFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithInterfaceNoFragments", - Query: ` +// The query or mutation executed by queryWithInterfaceNoFragments. +const queryWithInterfaceNoFragmentsOperation = ` query queryWithInterfaceNoFragments ($id: ID!) { being(id: $id) { __typename @@ -3461,7 +3482,16 @@ query queryWithInterfaceNoFragments ($id: ID!) { name } } -`, +` + +func queryWithInterfaceNoFragments( + ctx context.Context, + client graphql.Client, + id string, +) (*queryWithInterfaceNoFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithInterfaceNoFragments", + Query: queryWithInterfaceNoFragmentsOperation, Variables: &__queryWithInterfaceNoFragmentsInput{ Id: id, }, @@ -3480,14 +3510,8 @@ query queryWithInterfaceNoFragments ($id: ID!) { return &data, resp.Extensions, err } -func queryWithNamedFragments( - ctx context.Context, - client graphql.Client, - ids []string, -) (*queryWithNamedFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithNamedFragments", - Query: ` +// The query or mutation executed by queryWithNamedFragments. +const queryWithNamedFragmentsOperation = ` query queryWithNamedFragments ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3523,7 +3547,16 @@ fragment MoreUserFields on User { color } } -`, +` + +func queryWithNamedFragments( + ctx context.Context, + client graphql.Client, + ids []string, +) (*queryWithNamedFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithNamedFragments", + Query: queryWithNamedFragmentsOperation, Variables: &__queryWithNamedFragmentsInput{ Ids: ids, }, @@ -3542,14 +3575,8 @@ fragment MoreUserFields on User { return &data, resp.Extensions, err } -func queryWithOmitempty( - ctx context.Context, - client graphql.Client, - id string, -) (*queryWithOmitemptyResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithOmitempty", - Query: ` +// The query or mutation executed by queryWithOmitempty. +const queryWithOmitemptyOperation = ` query queryWithOmitempty ($id: ID) { user(id: $id) { id @@ -3557,7 +3584,16 @@ query queryWithOmitempty ($id: ID) { luckyNumber } } -`, +` + +func queryWithOmitempty( + ctx context.Context, + client graphql.Client, + id string, +) (*queryWithOmitemptyResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithOmitempty", + Query: queryWithOmitemptyOperation, Variables: &__queryWithOmitemptyInput{ Id: id, }, @@ -3576,14 +3612,8 @@ query queryWithOmitempty ($id: ID) { return &data, resp.Extensions, err } -func queryWithVariables( - ctx context.Context, - client graphql.Client, - id string, -) (*queryWithVariablesResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "queryWithVariables", - Query: ` +// The query or mutation executed by queryWithVariables. +const queryWithVariablesOperation = ` query queryWithVariables ($id: ID!) { user(id: $id) { id @@ -3591,7 +3621,16 @@ query queryWithVariables ($id: ID!) { luckyNumber } } -`, +` + +func queryWithVariables( + ctx context.Context, + client graphql.Client, + id string, +) (*queryWithVariablesResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "queryWithVariables", + Query: queryWithVariablesOperation, Variables: &__queryWithVariablesInput{ Id: id, }, @@ -3610,13 +3649,8 @@ query queryWithVariables ($id: ID!) { return &data, resp.Extensions, err } -func simpleQuery( - ctx context.Context, - client graphql.Client, -) (*simpleQueryResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "simpleQuery", - Query: ` +// The query or mutation executed by simpleQuery. +const simpleQueryOperation = ` query simpleQuery { me { id @@ -3624,7 +3658,15 @@ query simpleQuery { luckyNumber } } -`, +` + +func simpleQuery( + ctx context.Context, + client graphql.Client, +) (*simpleQueryResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "simpleQuery", + Query: simpleQueryOperation, } var err error @@ -3640,13 +3682,8 @@ query simpleQuery { return &data, resp.Extensions, err } -func simpleQueryExt( - ctx context.Context, - client graphql.Client, -) (*simpleQueryExtResponse, map[string]interface{}, error) { - req := &graphql.Request{ - OpName: "simpleQueryExt", - Query: ` +// The query or mutation executed by simpleQueryExt. +const simpleQueryExtOperation = ` query simpleQueryExt { me { id @@ -3654,7 +3691,15 @@ query simpleQueryExt { luckyNumber } } -`, +` + +func simpleQueryExt( + ctx context.Context, + client graphql.Client, +) (*simpleQueryExtResponse, map[string]interface{}, error) { + req := &graphql.Request{ + OpName: "simpleQueryExt", + Query: simpleQueryExtOperation, } var err error