From f4d6b11fd4bdc39dd00600ae0523d844bee7a6b7 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Fri, 25 Mar 2022 15:58:34 +0100 Subject: [PATCH 1/9] Adding GraphQL Extensions This enables accessing the Extensions field, as defined in the response format: https://spec.graphql.org/October2021/#sec-Response-Format Extensions can be enabled using configuration option use_extensions. This will change the return parameters of the generated client functions. Making it a breaking change if enabled. Since extensions are untyped as defined in the spec, the Client will return an interface of type map[string]interface{}. --- docs/genqlient.yaml | 10 + example/generated.go | 60 +- example/genqlient.yaml | 1 - generate/config.go | 1 + generate/generate_test.go | 4 + generate/operation.go.tmpl | 33 +- generate/testdata/queries/foo.go | 69 ++ ....graphql-ComplexInlineFragments.graphql.go | 25 +- ...s.graphql-ComplexNamedFragments.graphql.go | 25 +- ...omMarshal.graphql-CustomMarshal.graphql.go | 33 +- ...lice.graphql-CustomMarshalSlice.graphql.go | 35 +- ...erate-DateTime.graphql-DateTime.graphql.go | 33 +- ...nterface.graphql-EmptyInterface.graphql.go | 25 +- ...enerate-Flatten.graphql-Flatten.graphql.go | 25 +- ...ate-InputEnum.graphql-InputEnum.graphql.go | 33 +- ...InputObject.graphql-InputObject.graphql.go | 33 +- ...ield.graphql-InterfaceListField.graphql.go | 25 +- ...nterfaceListOfListsOfListsField.graphql.go | 25 +- ...esting.graphql-InterfaceNesting.graphql.go | 25 +- ...ts.graphql-InterfaceNoFragments.graphql.go | 25 +- ...ate-ListInput.graphql-ListInput.graphql.go | 33 +- ...ists.graphql-ListOfListsOfLists.graphql.go | 25 +- ...ives.graphql-MultipleDirectives.graphql.go | 35 +- ...ate-Omitempty.graphql-Omitempty.graphql.go | 41 +- ...erate-Pointers.graphql-Pointers.graphql.go | 37 +- ...rsInline.graphql-PointersInline.graphql.go | 37 +- ...enerate-Pokemon.graphql-Pokemon.graphql.go | 33 +- ...ithAlias.graphql-QueryWithAlias.graphql.go | 25 +- ...as.graphql-QueryWithDoubleAlias.graphql.go | 25 +- ...ithEnums.graphql-QueryWithEnums.graphql.go | 25 +- ...hSlices.graphql-QueryWithSlices.graphql.go | 25 +- ...tructs.graphql-QueryWithStructs.graphql.go | 25 +- ...ate-Recursion.graphql-Recursion.graphql.go | 33 +- ...nt.graphql-SimpleInlineFragment.graphql.go | 25 +- ...SimpleInput.graphql-SimpleInput.graphql.go | 33 +- ...Mutation.graphql-SimpleMutation.graphql.go | 33 +- ...ent.graphql-SimpleNamedFragment.graphql.go | 25 +- ...SimpleQuery.graphql-SimpleQuery.graphql.go | 25 +- ...ructOption.graphql-StructOption.graphql.go | 25 +- ...erate-TypeName.graphql-TypeName.graphql.go | 25 +- ...ate-TypeNames.graphql-TypeNames.graphql.go | 25 +- ...gments.graphql-UnionNoFragments.graphql.go | 25 +- ...EnumTwice.graphql-UsesEnumTwice.graphql.go | 25 +- ...e-unexported.graphql-unexported.graphql.go | 33 +- ...ClientGetter-testdata-queries-generated.go | 36 +- ...ustomContext-testdata-queries-generated.go | 36 +- ...NoContext#01-testdata-queries-generated.go | 69 ++ ...terNoContext-testdata-queries-generated.go | 36 +- ...ustomContext-testdata-queries-generated.go | 27 +- ...efaultConfig-testdata-queries-generated.go | 27 +- ...rtOperations-testdata-queries-generated.go | 27 +- ...g-Extensions-testdata-queries-generated.go | 66 ++ ...ig-NoContext-testdata-queries-generated.go | 25 +- ...fig-PackageName-testdata-queries-myfile.go | 27 +- ...s-testdata-queries-generated-structrefs.go | 27 +- ...ubpackage-testdata-queries-mypkg-myfile.go | 27 +- ...ageConfig-testdata-queries-mypkg-myfile.go | 27 +- graphql/client.go | 52 +- internal/integration/generated.go | 495 +++++++++----- internal/integration/genqlient.yaml | 1 + internal/integration/integration_test.go | 57 +- internal/integration/roundtrip.go | 6 +- internal/integration/server/gqlgen_exec.go | 632 ++++++++++++++---- internal/integration/server/server.go | 5 + 64 files changed, 2027 insertions(+), 921 deletions(-) create mode 100644 generate/testdata/queries/foo.go create mode 100644 generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go create mode 100644 generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go diff --git a/docs/genqlient.yaml b/docs/genqlient.yaml index f68ff657..d30235b6 100644 --- a/docs/genqlient.yaml +++ b/docs/genqlient.yaml @@ -87,6 +87,16 @@ client_getter: "github.com/you/yourpkg.GetClient" # Defaults to false. use_struct_references: boolean +# If set, generated code will have a third return parameter of type +# map[string]interface{}. This will contain the optional values +# of the Extensions field send from Servers. +# ref.: https://spec.graphql.org/October2021/#sec-Response-Format +# +# This can be useful for extending the GraphQL Protocol. +# +# Defaults to false. +use_extensions: boolean + # A map from GraphQL type name to Go fully-qualified type name to override # the Go type genqlient will use for this GraphQL type. diff --git a/example/generated.go b/example/generated.go index 85b041eb..a0476bdf 100644 --- a/example/generated.go +++ b/example/generated.go @@ -75,16 +75,9 @@ func getUser( client graphql.Client, Login string, ) (*getUserResponse, error) { - __input := __getUserInput{ - Login: Login, - } - var err error - - var retval getUserResponse - err = client.MakeRequest( - ctx, - "getUser", - ` + req := &graphql.Payload{ + OpName: "getUser", + Query: ` query getUser ($Login: String!) { user(login: $Login) { theirName: name @@ -92,23 +85,33 @@ query getUser ($Login: String!) { } } `, - &retval, - &__input, + Variables: &__getUserInput{ + Login: Login, + }, + } + var err error + + resp := &graphql.Response{ + Data: &getUserResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*getUserResponse) + return retval, err } func getViewer( ctx context.Context, client graphql.Client, ) (*getViewerResponse, error) { - var err error - - var retval getViewerResponse - err = client.MakeRequest( - ctx, - "getViewer", - ` + req := &graphql.Payload{ + OpName: "getViewer", + Query: ` query getViewer { viewer { MyName: name @@ -116,8 +119,19 @@ query getViewer { } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &getViewerResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*getViewerResponse) + return retval, err } diff --git a/example/genqlient.yaml b/example/genqlient.yaml index 74f0533e..11cd0348 100644 --- a/example/genqlient.yaml +++ b/example/genqlient.yaml @@ -2,7 +2,6 @@ schema: schema.graphql operations: - genqlient.graphql generated: generated.go - # needed since it doesn't match the directory name: package: main diff --git a/generate/config.go b/generate/config.go index 21fde5dc..5f019c30 100644 --- a/generate/config.go +++ b/generate/config.go @@ -27,6 +27,7 @@ type Config struct { ClientGetter string `yaml:"client_getter"` Bindings map[string]*TypeBinding `yaml:"bindings"` StructReferences bool `yaml:"use_struct_references"` + Extensions bool `yaml:"use_extensions"` // Set to true to use features that aren't fully ready to use. // diff --git a/generate/generate_test.go b/generate/generate_test.go index 49ba55b8..762cb47b 100644 --- a/generate/generate_test.go +++ b/generate/generate_test.go @@ -191,6 +191,10 @@ func TestGenerateWithConfig(t *testing.T) { ClientGetter: "github.com/Khan/genqlient/internal/testutil.GetClientFromNowhere", ContextType: "-", }}, + {"Extensions", "", &Config{ + Generated: "generated.go", + Extensions: true, + }}, } sourceFilename := "SimpleQuery.graphql" diff --git a/generate/operation.go.tmpl b/generate/operation.go.tmpl index 47a0c939..71f992a6 100644 --- a/generate/operation.go.tmpl +++ b/generate/operation.go.tmpl @@ -12,34 +12,41 @@ func {{.Name}}( {{.GraphQLName}} {{.GoType.Reference}}, {{end -}} {{end -}} -) (*{{.ResponseName}}, error) { - {{- if .Input -}} +) (*{{.ResponseName}}, {{if .Config.Extensions -}}map[string]interface{},{{end}} error) { + req := &graphql.Payload{ + OpName: "{{.Name}}", + Query: `{{.Body}}`, + {{if .Input -}} {{/* We need to avoid conflicting with any of the function's argument names which are derived from the GraphQL argument names; notably `input` is a common one. So we use a name that's not legal in GraphQL, namely one starting with a double-underscore. */ -}} - __input := {{.Input.GoName}}{ + Variables: &{{.Input.GoName}}{ {{range .Input.Fields -}} {{.GoName}}: {{.GraphQLName}}, {{end -}} - } + }, {{end -}} - + } var err error {{if .Config.ClientGetter -}} - client, err := {{ref .Config.ClientGetter}}({{if ne .Config.ContextType "-"}}ctx{{else}}{{end}}) + var client graphql.Client + + client, err = {{ref .Config.ClientGetter}}({{if ne .Config.ContextType "-"}}ctx{{else}}{{end}}) if err != nil { - return nil, err + return nil, {{if .Config.Extensions -}}nil,{{end -}} err } {{end}} + resp := &graphql.Response{ + Data: &{{.ResponseName}}{}, + } - var retval {{.ResponseName}} err = client.MakeRequest( {{if ne .Config.ContextType "-"}}ctx{{else}}nil{{end}}, - "{{.Name}}", - `{{.Body}}`, - &retval, - {{if .Input}}&__input{{else}}nil{{end}}, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*{{.ResponseName}}) + return retval, {{if .Config.Extensions -}}resp.Extensions,{{end -}} err } diff --git a/generate/testdata/queries/foo.go b/generate/testdata/queries/foo.go new file mode 100644 index 00000000..70ccf2d6 --- /dev/null +++ b/generate/testdata/queries/foo.go @@ -0,0 +1,69 @@ +// Code generated by github.com/Khan/genqlient, DO NOT EDIT. + +package queries + +import ( + "context" + + "github.com/Khan/genqlient/graphql" +) + +// SimpleQueryResponse is returned by SimpleQuery on success. +type SimpleQueryResponse struct { + // user looks up a user by some stuff. + // + // See UserQueryInput for what stuff is supported. + // If query is null, returns the current user. + User SimpleQueryUser `json:"user"` +} + +// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface. +func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User } + +// SimpleQueryUser includes the requested fields of the GraphQL type User. +// The GraphQL type's documentation follows. +// +// A User is a user! +type SimpleQueryUser struct { + // id is the user's ID. + // + // It is stable, unique, and opaque, like all good IDs. + Id string `json:"id"` +} + +// 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, + client graphql.Client, +) (*SimpleQueryResponse, error) { + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` +query SimpleQuery { + user { + id + } +} +`, + } + var err error + var client graphql.Client + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, + ) + if err != nil { + return nil, err + } + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err +} diff --git a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go index 1e562dc2..f9ab687e 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go @@ -1348,13 +1348,9 @@ func (v *ComplexInlineFragmentsRootTopic) GetName() string { return v.Name } func ComplexInlineFragments( client graphql.Client, ) (*ComplexInlineFragmentsResponse, error) { - var err error - - var retval ComplexInlineFragmentsResponse - err = client.MakeRequest( - nil, - "ComplexInlineFragments", - ` + req := &graphql.Payload{ + OpName: "ComplexInlineFragments", + Query: ` query ComplexInlineFragments { root { id @@ -1441,9 +1437,20 @@ query ComplexInlineFragments { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &ComplexInlineFragmentsResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*ComplexInlineFragmentsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go index 566d18b4..f65fdb70 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go @@ -1742,13 +1742,9 @@ func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } func ComplexNamedFragments( client graphql.Client, ) (*ComplexNamedFragmentsResponse, error) { - var err error - - var retval ComplexNamedFragmentsResponse - err = client.MakeRequest( - nil, - "ComplexNamedFragments", - ` + req := &graphql.Payload{ + OpName: "ComplexNamedFragments", + Query: ` query ComplexNamedFragments { ... on Query { ... QueryFragment @@ -1807,9 +1803,20 @@ fragment MoreVideoFields on Video { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &ComplexNamedFragmentsResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*ComplexNamedFragmentsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go index e8c450dd..21476ac9 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go @@ -178,16 +178,9 @@ func CustomMarshal( client graphql.Client, date time.Time, ) (*CustomMarshalResponse, error) { - __input := __CustomMarshalInput{ - Date: date, - } - var err error - - var retval CustomMarshalResponse - err = client.MakeRequest( - nil, - "CustomMarshal", - ` + req := &graphql.Payload{ + OpName: "CustomMarshal", + Query: ` query CustomMarshal ($date: Date!) { usersBornOn(date: $date) { id @@ -195,9 +188,23 @@ query CustomMarshal ($date: Date!) { } } `, - &retval, - &__input, + Variables: &__CustomMarshalInput{ + Date: date, + }, + } + var err error + + resp := &graphql.Response{ + Data: &CustomMarshalResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*CustomMarshalResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go index 0156935d..630dd484 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go @@ -208,25 +208,32 @@ func CustomMarshalSlice( datesss [][][]time.Time, datesssp [][][]*time.Time, ) (*CustomMarshalSliceResponse, error) { - __input := __CustomMarshalSliceInput{ - Datesss: datesss, - Datesssp: datesssp, - } - var err error - - var retval CustomMarshalSliceResponse - err = client.MakeRequest( - nil, - "CustomMarshalSlice", - ` + req := &graphql.Payload{ + OpName: "CustomMarshalSlice", + Query: ` query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { acceptsListOfListOfListsOfDates(datesss: $datesss) withPointer: acceptsListOfListOfListsOfDates(datesss: $datesssp) } `, - &retval, - &__input, + Variables: &__CustomMarshalSliceInput{ + Datesss: datesss, + Datesssp: datesssp, + }, + } + var err error + + resp := &graphql.Response{ + Data: &CustomMarshalSliceResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*CustomMarshalSliceResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go index 581ec42c..8721f24d 100644 --- a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go @@ -33,24 +33,31 @@ func convertTimezone( dt time.Time, tz string, ) (*convertTimezoneResponse, error) { - __input := __convertTimezoneInput{ - Dt: dt, - Tz: tz, + req := &graphql.Payload{ + OpName: "convertTimezone", + Query: ` +query convertTimezone ($dt: DateTime!, $tz: String) { + convert(dt: $dt, tz: $tz) +} +`, + Variables: &__convertTimezoneInput{ + Dt: dt, + Tz: tz, + }, } var err error - var retval convertTimezoneResponse + resp := &graphql.Response{ + Data: &convertTimezoneResponse{}, + } + err = client.MakeRequest( nil, - "convertTimezone", - ` -query convertTimezone ($dt: DateTime!, $tz: String) { - convert(dt: $dt, tz: $tz) -} -`, - &retval, - &__input, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*convertTimezoneResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go index 96726d9b..e7658b99 100644 --- a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go @@ -23,21 +23,28 @@ func (v *EmptyInterfaceResponse) GetGetComplexJunk() []map[string]*[]*map[string func EmptyInterface( client graphql.Client, ) (*EmptyInterfaceResponse, error) { - var err error - - var retval EmptyInterfaceResponse - err = client.MakeRequest( - nil, - "EmptyInterface", - ` + req := &graphql.Payload{ + OpName: "EmptyInterface", + Query: ` query EmptyInterface { getJunk getComplexJunk } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &EmptyInterfaceResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*EmptyInterfaceResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go index cdb16ccd..84dbed23 100644 --- a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go @@ -269,13 +269,9 @@ func (v *VideoFieldsParentTopic) GetVideoChildren() []ChildVideoFields { return func ComplexNamedFragments( client graphql.Client, ) (*InnerQueryFragment, error) { - var err error - - var retval InnerQueryFragment - err = client.MakeRequest( - nil, - "ComplexNamedFragments", - ` + req := &graphql.Payload{ + OpName: "ComplexNamedFragments", + Query: ` query ComplexNamedFragments { ... QueryFragment } @@ -311,9 +307,20 @@ fragment ChildVideoFields on Video { name } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &InnerQueryFragment{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InnerQueryFragment) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go index fc8bde65..26fa1d11 100644 --- a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go @@ -58,25 +58,32 @@ func InputEnumQuery( client graphql.Client, role Role, ) (*InputEnumQueryResponse, error) { - __input := __InputEnumQueryInput{ - Role: role, - } - var err error - - var retval InputEnumQueryResponse - err = client.MakeRequest( - nil, - "InputEnumQuery", - ` + req := &graphql.Payload{ + OpName: "InputEnumQuery", + Query: ` query InputEnumQuery ($role: Role!) { usersWithRole(role: $role) { id } } `, - &retval, - &__input, + Variables: &__InputEnumQueryInput{ + Role: role, + }, + } + var err error + + resp := &graphql.Response{ + Data: &InputEnumQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InputEnumQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go index 4d2cc3c0..5baa712e 100644 --- a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go @@ -181,25 +181,32 @@ func InputObjectQuery( client graphql.Client, query UserQueryInput, ) (*InputObjectQueryResponse, error) { - __input := __InputObjectQueryInput{ - Query: query, - } - var err error - - var retval InputObjectQueryResponse - err = client.MakeRequest( - nil, - "InputObjectQuery", - ` + req := &graphql.Payload{ + OpName: "InputObjectQuery", + Query: ` query InputObjectQuery ($query: UserQueryInput) { user(query: $query) { id } } `, - &retval, - &__input, + Variables: &__InputObjectQueryInput{ + Query: query, + }, + } + var err error + + resp := &graphql.Response{ + Data: &InputObjectQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InputObjectQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go index 048b6085..652a2478 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go @@ -523,13 +523,9 @@ func (v *InterfaceListFieldWithPointerTopicChildrenVideo) GetName() string { ret func InterfaceListField( client graphql.Client, ) (*InterfaceListFieldResponse, error) { - var err error - - var retval InterfaceListFieldResponse - err = client.MakeRequest( - nil, - "InterfaceListField", - ` + req := &graphql.Payload{ + OpName: "InterfaceListField", + Query: ` query InterfaceListField { root { id @@ -551,9 +547,20 @@ query InterfaceListField { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &InterfaceListFieldResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InterfaceListFieldResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go index 8e29f76e..b3555044 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go @@ -509,13 +509,9 @@ func (v *InterfaceListOfListOfListsFieldWithPointerVideo) GetName() *string { re func InterfaceListOfListOfListsField( client graphql.Client, ) (*InterfaceListOfListOfListsFieldResponse, error) { - var err error - - var retval InterfaceListOfListOfListsFieldResponse - err = client.MakeRequest( - nil, - "InterfaceListOfListOfListsField", - ` + req := &graphql.Payload{ + OpName: "InterfaceListOfListOfListsField", + Query: ` query InterfaceListOfListOfListsField { listOfListsOfListsOfContent { __typename @@ -529,9 +525,20 @@ query InterfaceListOfListOfListsField { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &InterfaceListOfListOfListsFieldResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InterfaceListOfListOfListsFieldResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go index f69273fd..cfbaf162 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go @@ -507,13 +507,9 @@ func (v *InterfaceNestingRootTopicChildrenVideo) GetParent() InterfaceNestingRoo func InterfaceNesting( client graphql.Client, ) (*InterfaceNestingResponse, error) { - var err error - - var retval InterfaceNestingResponse - err = client.MakeRequest( - nil, - "InterfaceNesting", - ` + req := &graphql.Payload{ + OpName: "InterfaceNesting", + Query: ` query InterfaceNesting { root { id @@ -531,9 +527,20 @@ query InterfaceNesting { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &InterfaceNestingResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InterfaceNestingResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go index 6e600494..e8d15fd4 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go @@ -629,13 +629,9 @@ func (v *InterfaceNoFragmentsQueryWithPointerVideo) GetName() *string { return v func InterfaceNoFragmentsQuery( client graphql.Client, ) (*InterfaceNoFragmentsQueryResponse, error) { - var err error - - var retval InterfaceNoFragmentsQueryResponse - err = client.MakeRequest( - nil, - "InterfaceNoFragmentsQuery", - ` + req := &graphql.Payload{ + OpName: "InterfaceNoFragmentsQuery", + Query: ` query InterfaceNoFragmentsQuery { root { id @@ -658,9 +654,20 @@ query InterfaceNoFragmentsQuery { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &InterfaceNoFragmentsQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*InterfaceNoFragmentsQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go index 4bf5172c..96b7731b 100644 --- a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go @@ -45,25 +45,32 @@ func ListInputQuery( client graphql.Client, names []string, ) (*ListInputQueryResponse, error) { - __input := __ListInputQueryInput{ - Names: names, - } - var err error - - var retval ListInputQueryResponse - err = client.MakeRequest( - nil, - "ListInputQuery", - ` + req := &graphql.Payload{ + OpName: "ListInputQuery", + Query: ` query ListInputQuery ($names: [String]) { user(query: {names:$names}) { id } } `, - &retval, - &__input, + Variables: &__ListInputQueryInput{ + Names: names, + }, + } + var err error + + resp := &graphql.Response{ + Data: &ListInputQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*ListInputQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go index f6399add..1df2ab19 100644 --- a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go @@ -19,20 +19,27 @@ func (v *ListOfListsOfListsResponse) GetListOfListsOfLists() [][][]string { func ListOfListsOfLists( client graphql.Client, ) (*ListOfListsOfListsResponse, error) { - var err error - - var retval ListOfListsOfListsResponse - err = client.MakeRequest( - nil, - "ListOfListsOfLists", - ` + req := &graphql.Payload{ + OpName: "ListOfListsOfLists", + Query: ` query ListOfListsOfLists { listOfListsOfLists } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &ListOfListsOfListsResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*ListOfListsOfListsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go index 6e39da0a..cdba3004 100644 --- a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go @@ -330,17 +330,9 @@ func MultipleDirectives( query MyInput, queries []*UserQueryInput, ) (*MyMultipleDirectivesResponse, error) { - __input := __MultipleDirectivesInput{ - Query: query, - Queries: queries, - } - var err error - - var retval MyMultipleDirectivesResponse - err = client.MakeRequest( - nil, - "MultipleDirectives", - ` + req := &graphql.Payload{ + OpName: "MultipleDirectives", + Query: ` query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { user(query: $query) { id @@ -350,9 +342,24 @@ query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { } } `, - &retval, - &__input, + Variables: &__MultipleDirectivesInput{ + Query: query, + Queries: queries, + }, + } + var err error + + resp := &graphql.Response{ + Data: &MyMultipleDirectivesResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*MyMultipleDirectivesResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go index 24139846..8d357ee6 100644 --- a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go @@ -227,20 +227,9 @@ func OmitEmptyQuery( tz string, tzNoOmitEmpty string, ) (*OmitEmptyQueryResponse, error) { - __input := __OmitEmptyQueryInput{ - Query: query, - Queries: queries, - Dt: dt, - Tz: tz, - TzNoOmitEmpty: tzNoOmitEmpty, - } - var err error - - var retval OmitEmptyQueryResponse - err = client.MakeRequest( - nil, - "OmitEmptyQuery", - ` + req := &graphql.Payload{ + OpName: "OmitEmptyQuery", + Query: ` query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: DateTime, $tz: String, $tzNoOmitEmpty: String) { user(query: $query) { id @@ -252,9 +241,27 @@ query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: D convert2: maybeConvert(dt: $dt, tz: $tzNoOmitEmpty) } `, - &retval, - &__input, + Variables: &__OmitEmptyQueryInput{ + Query: query, + Queries: queries, + Dt: dt, + Tz: tz, + TzNoOmitEmpty: tzNoOmitEmpty, + }, + } + var err error + + resp := &graphql.Response{ + Data: &OmitEmptyQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*OmitEmptyQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go index 3378941a..409297e8 100644 --- a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go @@ -236,18 +236,9 @@ func PointersQuery( dt time.Time, tz *string, ) (*PointersQueryResponse, error) { - __input := __PointersQueryInput{ - Query: query, - Dt: dt, - Tz: tz, - } - var err error - - var retval PointersQueryResponse - err = client.MakeRequest( - nil, - "PointersQuery", - ` + req := &graphql.Payload{ + OpName: "PointersQuery", + Query: ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { user(query: $query) { id @@ -262,9 +253,25 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { maybeConvert(dt: $dt, tz: $tz) } `, - &retval, - &__input, + Variables: &__PointersQueryInput{ + Query: query, + Dt: dt, + Tz: tz, + }, + } + var err error + + resp := &graphql.Response{ + Data: &PointersQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*PointersQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go index a01827a8..04c552a5 100644 --- a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go @@ -233,18 +233,9 @@ func PointersQuery( dt *time.Time, tz string, ) (*PointersQueryResponse, error) { - __input := __PointersQueryInput{ - Query: query, - Dt: dt, - Tz: tz, - } - var err error - - var retval PointersQueryResponse - err = client.MakeRequest( - nil, - "PointersQuery", - ` + req := &graphql.Payload{ + OpName: "PointersQuery", + Query: ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { user(query: $query) { id @@ -259,9 +250,25 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { maybeConvert(dt: $dt, tz: $tz) } `, - &retval, - &__input, + Variables: &__PointersQueryInput{ + Query: query, + Dt: dt, + Tz: tz, + }, + } + var err error + + resp := &graphql.Response{ + Data: &PointersQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*PointersQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go index edc9fcf3..14b42928 100644 --- a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go @@ -75,16 +75,9 @@ func GetPokemonSiblings( client graphql.Client, input testutil.Pokemon, ) (*GetPokemonSiblingsResponse, error) { - __input := __GetPokemonSiblingsInput{ - Input: input, - } - var err error - - var retval GetPokemonSiblingsResponse - err = client.MakeRequest( - nil, - "GetPokemonSiblings", - ` + req := &graphql.Payload{ + OpName: "GetPokemonSiblings", + Query: ` query GetPokemonSiblings ($input: PokemonInput!) { user(query: {hasPokemon:$input}) { id @@ -101,9 +94,23 @@ query GetPokemonSiblings ($input: PokemonInput!) { } } `, - &retval, - &__input, + Variables: &__GetPokemonSiblingsInput{ + Input: input, + }, + } + var err error + + resp := &graphql.Response{ + Data: &GetPokemonSiblingsResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*GetPokemonSiblingsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go index 6af1bfcd..552baf1a 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go @@ -43,13 +43,9 @@ func (v *QueryWithAliasUser) GetOtherID() testutil.ID { return v.OtherID } func QueryWithAlias( client graphql.Client, ) (*QueryWithAliasResponse, error) { - var err error - - var retval QueryWithAliasResponse - err = client.MakeRequest( - nil, - "QueryWithAlias", - ` + req := &graphql.Payload{ + OpName: "QueryWithAlias", + Query: ` query QueryWithAlias { User: user { ID: id @@ -57,9 +53,20 @@ query QueryWithAlias { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &QueryWithAliasResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryWithAliasResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go index 0544f5aa..51d9ce47 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go @@ -43,13 +43,9 @@ func (v *QueryWithDoubleAliasUser) GetAlsoID() testutil.ID { return v.AlsoID } func QueryWithDoubleAlias( client graphql.Client, ) (*QueryWithDoubleAliasResponse, error) { - var err error - - var retval QueryWithDoubleAliasResponse - err = client.MakeRequest( - nil, - "QueryWithDoubleAlias", - ` + req := &graphql.Payload{ + OpName: "QueryWithDoubleAlias", + Query: ` query QueryWithDoubleAlias { user { ID: id @@ -57,9 +53,20 @@ query QueryWithDoubleAlias { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &QueryWithDoubleAliasResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryWithDoubleAliasResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go index f14f00f6..c0226153 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go @@ -65,13 +65,9 @@ const ( func QueryWithEnums( client graphql.Client, ) (*QueryWithEnumsResponse, error) { - var err error - - var retval QueryWithEnumsResponse - err = client.MakeRequest( - nil, - "QueryWithEnums", - ` + req := &graphql.Payload{ + OpName: "QueryWithEnums", + Query: ` query QueryWithEnums { user { roles @@ -81,9 +77,20 @@ query QueryWithEnums { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &QueryWithEnumsResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryWithEnumsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go index f83f4f6f..21069a5d 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go @@ -44,13 +44,9 @@ func (v *QueryWithSlicesUser) GetEmailsWithNullsOrNull() []string { return v.Ema func QueryWithSlices( client graphql.Client, ) (*QueryWithSlicesResponse, error) { - var err error - - var retval QueryWithSlicesResponse - err = client.MakeRequest( - nil, - "QueryWithSlices", - ` + req := &graphql.Payload{ + OpName: "QueryWithSlices", + Query: ` query QueryWithSlices { user { emails @@ -60,9 +56,20 @@ query QueryWithSlices { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &QueryWithSlicesResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryWithSlicesResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go index 0c6e9be2..33a7fa6b 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go @@ -46,13 +46,9 @@ func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetEmail() string { return v func QueryWithStructs( client graphql.Client, ) (*QueryWithStructsResponse, error) { - var err error - - var retval QueryWithStructsResponse - err = client.MakeRequest( - nil, - "QueryWithStructs", - ` + req := &graphql.Payload{ + OpName: "QueryWithStructs", + Query: ` query QueryWithStructs { user { authMethods { @@ -62,9 +58,20 @@ query QueryWithStructs { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &QueryWithStructsResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryWithStructsResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go index 65477080..ce07a485 100644 --- a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go @@ -72,16 +72,9 @@ func Recursion( client graphql.Client, input RecursiveInput, ) (*RecursionResponse, error) { - __input := __RecursionInput{ - Input: input, - } - var err error - - var retval RecursionResponse - err = client.MakeRequest( - nil, - "Recursion", - ` + req := &graphql.Payload{ + OpName: "Recursion", + Query: ` query Recursion ($input: RecursiveInput!) { recur(input: $input) { rec { @@ -94,9 +87,23 @@ query Recursion ($input: RecursiveInput!) { } } `, - &retval, - &__input, + Variables: &__RecursionInput{ + Input: input, + }, + } + var err error + + resp := &graphql.Response{ + Data: &RecursionResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*RecursionResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go index b3cf78a5..2227003f 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go @@ -242,13 +242,9 @@ func (v *SimpleInlineFragmentResponse) __premarshalJSON() (*__premarshalSimpleIn func SimpleInlineFragment( client graphql.Client, ) (*SimpleInlineFragmentResponse, error) { - var err error - - var retval SimpleInlineFragmentResponse - err = client.MakeRequest( - nil, - "SimpleInlineFragment", - ` + req := &graphql.Payload{ + OpName: "SimpleInlineFragment", + Query: ` query SimpleInlineFragment { randomItem { __typename @@ -263,9 +259,20 @@ query SimpleInlineFragment { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleInlineFragmentResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleInlineFragmentResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go index 78d62091..f689b585 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go @@ -45,25 +45,32 @@ func SimpleInputQuery( client graphql.Client, name string, ) (*SimpleInputQueryResponse, error) { - __input := __SimpleInputQueryInput{ - Name: name, - } - var err error - - var retval SimpleInputQueryResponse - err = client.MakeRequest( - nil, - "SimpleInputQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleInputQuery", + Query: ` query SimpleInputQuery ($name: String!) { user(query: {name:$name}) { id } } `, - &retval, - &__input, + Variables: &__SimpleInputQueryInput{ + Name: name, + }, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleInputQueryResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleInputQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go index 8601bc41..66f3a4ce 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go @@ -49,16 +49,9 @@ func SimpleMutation( client graphql.Client, name string, ) (*SimpleMutationResponse, error) { - __input := __SimpleMutationInput{ - Name: name, - } - var err error - - var retval SimpleMutationResponse - err = client.MakeRequest( - nil, - "SimpleMutation", - ` + req := &graphql.Payload{ + OpName: "SimpleMutation", + Query: ` mutation SimpleMutation ($name: String!) { createUser(name: $name) { id @@ -66,9 +59,23 @@ mutation SimpleMutation ($name: String!) { } } `, - &retval, - &__input, + Variables: &__SimpleMutationInput{ + Name: name, + }, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleMutationResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleMutationResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go index 1773fbae..5ca9c01d 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go @@ -549,13 +549,9 @@ func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } func SimpleNamedFragment( client graphql.Client, ) (*SimpleNamedFragmentResponse, error) { - var err error - - var retval SimpleNamedFragmentResponse - err = client.MakeRequest( - nil, - "SimpleNamedFragment", - ` + req := &graphql.Payload{ + OpName: "SimpleNamedFragment", + Query: ` query SimpleNamedFragment { randomItem { __typename @@ -578,9 +574,20 @@ fragment VideoFields on Video { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleNamedFragmentResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleNamedFragmentResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go index 2d9ead51..fd843199 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go @@ -36,22 +36,29 @@ func (v *SimpleQueryUser) GetId() testutil.ID { return v.Id } func SimpleQuery( client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - nil, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go index 75fe942c..06ec1c7c 100644 --- a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go @@ -427,13 +427,9 @@ func (v *VideoFields) GetDuration() int { return v.Duration } func StructOption( client graphql.Client, ) (*StructOptionResponse, error) { - var err error - - var retval StructOptionResponse - err = client.MakeRequest( - nil, - "StructOption", - ` + req := &graphql.Payload{ + OpName: "StructOption", + Query: ` query StructOption { root { id @@ -462,9 +458,20 @@ fragment VideoFields on Video { duration } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &StructOptionResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*StructOptionResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go index da9892c9..efd07c7e 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go @@ -40,13 +40,9 @@ func (v *TypeNameQueryUser) GetId() testutil.ID { return v.Id } func TypeNameQuery( client graphql.Client, ) (*TypeNameQueryResponse, error) { - var err error - - var retval TypeNameQueryResponse - err = client.MakeRequest( - nil, - "TypeNameQuery", - ` + req := &graphql.Payload{ + OpName: "TypeNameQuery", + Query: ` query TypeNameQuery { user { __typename @@ -54,9 +50,20 @@ query TypeNameQuery { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &TypeNameQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*TypeNameQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go index f79932fb..9e8cac34 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go @@ -267,13 +267,9 @@ func (v *User) GetName() string { return v.Name } func TypeNames( client graphql.Client, ) (*Resp, error) { - var err error - - var retval Resp - err = client.MakeRequest( - nil, - "TypeNames", - ` + req := &graphql.Payload{ + OpName: "TypeNames", + Query: ` query TypeNames { user { id @@ -290,9 +286,20 @@ query TypeNames { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &Resp{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*Resp) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go index d6d75ab1..5c6868d5 100644 --- a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go @@ -177,22 +177,29 @@ func (v *UnionNoFragmentsQueryResponse) __premarshalJSON() (*__premarshalUnionNo func UnionNoFragmentsQuery( client graphql.Client, ) (*UnionNoFragmentsQueryResponse, error) { - var err error - - var retval UnionNoFragmentsQueryResponse - err = client.MakeRequest( - nil, - "UnionNoFragmentsQuery", - ` + req := &graphql.Payload{ + OpName: "UnionNoFragmentsQuery", + Query: ` query UnionNoFragmentsQuery { randomLeaf { __typename } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &UnionNoFragmentsQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*UnionNoFragmentsQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go index 5864d356..324232a5 100644 --- a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go @@ -65,13 +65,9 @@ func (v *UsesEnumTwiceQueryResponse) GetOtherUser() UsesEnumTwiceQueryOtherUser func UsesEnumTwiceQuery( client graphql.Client, ) (*UsesEnumTwiceQueryResponse, error) { - var err error - - var retval UsesEnumTwiceQueryResponse - err = client.MakeRequest( - nil, - "UsesEnumTwiceQuery", - ` + req := &graphql.Payload{ + OpName: "UsesEnumTwiceQuery", + Query: ` query UsesEnumTwiceQuery { Me: user { roles @@ -81,9 +77,20 @@ query UsesEnumTwiceQuery { } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &UsesEnumTwiceQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*UsesEnumTwiceQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go index 81eebc2d..a4fdb723 100644 --- a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go @@ -181,25 +181,32 @@ func unexported( client graphql.Client, query UserQueryInput, ) (*unexportedResponse, error) { - __input := __unexportedInput{ - Query: query, - } - var err error - - var retval unexportedResponse - err = client.MakeRequest( - nil, - "unexported", - ` + req := &graphql.Payload{ + OpName: "unexported", + Query: ` query unexported ($query: UserQueryInput) { user(query: $query) { id } } `, - &retval, - &__input, + Variables: &__unexportedInput{ + Query: query, + }, + } + var err error + + resp := &graphql.Response{ + Data: &unexportedResponse{}, + } + + err = client.MakeRequest( + nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*unexportedResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go index 360947fa..bec4045d 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go @@ -5,6 +5,7 @@ package queries import ( "context" + "github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/internal/testutil" ) @@ -37,26 +38,35 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( ctx context.Context, ) (*SimpleQueryResponse, error) { + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` +query SimpleQuery { + user { + id + } +} +`, + } var err error - client, err := testutil.GetClientFromContext(ctx) + var client graphql.Client + + client, err = testutil.GetClientFromContext(ctx) if err != nil { return nil, err } - var retval SimpleQueryResponse + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + err = client.MakeRequest( ctx, - "SimpleQuery", - ` -query SimpleQuery { - user { - id - } -} -`, - &retval, - nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go index 36e6798c..d76501d1 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go @@ -5,6 +5,7 @@ package queries import ( "context" + "github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/internal/testutil" ) @@ -40,26 +41,35 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( ctx testutil.MyContext, ) (*SimpleQueryResponse, error) { + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` +query SimpleQuery { + user { + id + } +} +`, + } var err error - client, err := testutil.GetClientFromMyContext(ctx) + var client graphql.Client + + client, err = testutil.GetClientFromMyContext(ctx) if err != nil { return nil, err } - var retval SimpleQueryResponse + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + err = client.MakeRequest( ctx, - "SimpleQuery", - ` -query SimpleQuery { - user { - id - } -} -`, - &retval, - nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go new file mode 100644 index 00000000..44ee04ec --- /dev/null +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go @@ -0,0 +1,69 @@ +// Code generated by github.com/Khan/genqlient, DO NOT EDIT. + +package queries + +import ( + "context" + + "github.com/Khan/genqlient/graphql" +) + +// SimpleQueryResponse is returned by SimpleQuery on success. +type SimpleQueryResponse struct { + // user looks up a user by some stuff. + // + // See UserQueryInput for what stuff is supported. + // If query is null, returns the current user. + User SimpleQueryUser `json:"user"` +} + +// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface. +func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User } + +// SimpleQueryUser includes the requested fields of the GraphQL type User. +// The GraphQL type's documentation follows. +// +// A User is a user! +type SimpleQueryUser struct { + // id is the user's ID. + // + // It is stable, unique, and opaque, like all good IDs. + Id string `json:"id"` +} + +// 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, + client graphql.Client, +) (*SimpleQueryResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` +query SimpleQuery { + user { + id + } +} +`, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, + ) + if err != nil { + return nil, nil, err + } + + retval := resp.Data.(*SimpleQueryResponse) + return retval, resp.Extensions, err +} + diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go index 9d3e1395..da22afb4 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go @@ -3,6 +3,7 @@ package queries import ( + "github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/internal/testutil" ) @@ -33,26 +34,35 @@ type SimpleQueryUser struct { func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery() (*SimpleQueryResponse, error) { - var err error - client, err := testutil.GetClientFromNowhere() - if err != nil { - return nil, err - } - - var retval SimpleQueryResponse - err = client.MakeRequest( - nil, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, + } + var err error + var client graphql.Client + + client, err = testutil.GetClientFromNowhere() + if err != nil { + return nil, err + } + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go index d15c27ac..df3597a2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go @@ -42,22 +42,29 @@ func SimpleQuery( ctx testutil.MyContext, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go index 6b08b6b0..6aaf238e 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go index 6b08b6b0..6aaf238e 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go new file mode 100644 index 00000000..f7eaa8f3 --- /dev/null +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go @@ -0,0 +1,66 @@ +// Code generated by github.com/Khan/genqlient, DO NOT EDIT. + +package queries + +import ( + "context" + + "github.com/Khan/genqlient/graphql" +) + +// SimpleQueryResponse is returned by SimpleQuery on success. +type SimpleQueryResponse struct { + // user looks up a user by some stuff. + // + // See UserQueryInput for what stuff is supported. + // If query is null, returns the current user. + User SimpleQueryUser `json:"user"` +} + +// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface. +func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User } + +// SimpleQueryUser includes the requested fields of the GraphQL type User. +// The GraphQL type's documentation follows. +// +// A User is a user! +type SimpleQueryUser struct { + // id is the user's ID. + // + // It is stable, unique, and opaque, like all good IDs. + Id string `json:"id"` +} + +// 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, + client graphql.Client, +) (*SimpleQueryResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` +query SimpleQuery { + user { + id + } +} +`, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, + ) + + retval := resp.Data.(*SimpleQueryResponse) + return retval, resp.Extensions, err +} + diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go index 16d05387..9d62c480 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go @@ -35,22 +35,29 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - nil, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( nil, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go index 9006b4b3..48d86cc9 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } 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 24b17f31..f0bfaf97 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } 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 9006b4b3..48d86cc9 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } 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 9006b4b3..48d86cc9 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go @@ -38,22 +38,29 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - var err error - - var retval SimpleQueryResponse - err = client.MakeRequest( - ctx, - "SimpleQuery", - ` + req := &graphql.Payload{ + OpName: "SimpleQuery", + Query: ` query SimpleQuery { user { id } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &SimpleQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*SimpleQueryResponse) + return retval, err } diff --git a/graphql/client.go b/graphql/client.go index 832bb923..a2233147 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -40,9 +40,8 @@ type Client interface { // (Errors are returned.) But again, MakeRequest may customize this. MakeRequest( ctx context.Context, - opName string, - query string, - retval, input interface{}, + req *Payload, + resp *Response, ) error } @@ -75,7 +74,9 @@ type Doer interface { Do(*http.Request) (*http.Response, error) } -type payload struct { +// Payload contains all the values required to build queries executed by +// the graphql.Client. +type Payload struct { Query string `json:"query"` Variables interface{} `json:"variables,omitempty"` // OpName is only required if there are multiple queries in the document, @@ -83,57 +84,54 @@ type payload struct { OpName string `json:"operationName"` } -type response struct { - Data interface{} `json:"data"` - Errors gqlerror.List `json:"errors"` +// Response that contains data returned by the GraphQL API. Extensions and +// Errors might not be set, depending on the values returned by the Request. +type Response struct { + Data interface{} `json:"data"` + Extensions map[string]interface{} `json:"extensions,omitempty"` + Errors gqlerror.List `json:"errors,omitempty"` } -func (c *client) MakeRequest(ctx context.Context, opName string, query string, retval interface{}, variables interface{}) error { - body, err := json.Marshal(payload{ - Query: query, - Variables: variables, - OpName: opName, - }) +func (c *client) MakeRequest(ctx context.Context, req *Payload, resp *Response) error { + body, err := json.Marshal(req) if err != nil { return err } - req, err := http.NewRequest( + httpReq, err := http.NewRequest( c.method, c.endpoint, bytes.NewReader(body)) if err != nil { return err } - req.Header.Set("Content-Type", "application/json") + httpReq.Header.Set("Content-Type", "application/json") if ctx != nil { - req = req.WithContext(ctx) + httpReq = httpReq.WithContext(ctx) } - resp, err := c.httpClient.Do(req) + + httpResp, err := c.httpClient.Do(httpReq) if err != nil { return err } - defer resp.Body.Close() + defer httpResp.Body.Close() - if resp.StatusCode != http.StatusOK { + if httpResp.StatusCode != http.StatusOK { var respBody []byte - respBody, err = io.ReadAll(resp.Body) + respBody, err = io.ReadAll(httpResp.Body) if err != nil { respBody = []byte(fmt.Sprintf("", err)) } - return fmt.Errorf("returned error %v: %s", resp.Status, respBody) + return fmt.Errorf("returned error %v: %s", httpResp.Status, respBody) } - var dataAndErrors response - dataAndErrors.Data = retval - err = json.NewDecoder(resp.Body).Decode(&dataAndErrors) + err = json.NewDecoder(httpResp.Body).Decode(resp) if err != nil { return err } - - if len(dataAndErrors.Errors) > 0 { - return dataAndErrors.Errors + if len(resp.Errors) > 0 { + return resp.Errors } return nil } diff --git a/internal/integration/generated.go b/internal/integration/generated.go index 086e78f7..006a8a4c 100644 --- a/internal/integration/generated.go +++ b/internal/integration/generated.go @@ -2995,6 +2995,30 @@ func (v *queryWithVariablesUser) GetName() string { return v.Name } // GetLuckyNumber returns queryWithVariablesUser.LuckyNumber, and is useful for accessing the field via an interface. func (v *queryWithVariablesUser) GetLuckyNumber() int { return v.LuckyNumber } +// simpleQueryExtMeUser includes the requested fields of the GraphQL type User. +type simpleQueryExtMeUser struct { + Id string `json:"id"` + Name string `json:"name"` + LuckyNumber int `json:"luckyNumber"` +} + +// GetId returns simpleQueryExtMeUser.Id, and is useful for accessing the field via an interface. +func (v *simpleQueryExtMeUser) GetId() string { return v.Id } + +// GetName returns simpleQueryExtMeUser.Name, and is useful for accessing the field via an interface. +func (v *simpleQueryExtMeUser) GetName() string { return v.Name } + +// GetLuckyNumber returns simpleQueryExtMeUser.LuckyNumber, and is useful for accessing the field via an interface. +func (v *simpleQueryExtMeUser) GetLuckyNumber() int { return v.LuckyNumber } + +// simpleQueryExtResponse is returned by simpleQueryExt on success. +type simpleQueryExtResponse struct { + Me simpleQueryExtMeUser `json:"me"` +} + +// GetMe returns simpleQueryExtResponse.Me, and is useful for accessing the field via an interface. +func (v *simpleQueryExtResponse) GetMe() simpleQueryExtMeUser { return v.Me } + // simpleQueryMeUser includes the requested fields of the GraphQL type User. type simpleQueryMeUser struct { Id string `json:"id"` @@ -3022,14 +3046,10 @@ func (v *simpleQueryResponse) GetMe() simpleQueryMeUser { return v.Me } func failingQuery( ctx context.Context, client graphql.Client, -) (*failingQueryResponse, error) { - var err error - - var retval failingQueryResponse - err = client.MakeRequest( - ctx, - "failingQuery", - ` +) (*failingQueryResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "failingQuery", + Query: ` query failingQuery { fail me { @@ -3037,27 +3057,31 @@ query failingQuery { } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &failingQueryResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*failingQueryResponse) + return retval, resp.Extensions, err } func queryWithCustomMarshal( ctx context.Context, client graphql.Client, date time.Time, -) (*queryWithCustomMarshalResponse, error) { - __input := __queryWithCustomMarshalInput{ - Date: date, - } - var err error - - var retval queryWithCustomMarshalResponse - err = client.MakeRequest( - ctx, - "queryWithCustomMarshal", - ` +) (*queryWithCustomMarshalResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithCustomMarshal", + Query: ` query queryWithCustomMarshal ($date: Date!) { usersBornOn(date: $date) { id @@ -3066,10 +3090,24 @@ query queryWithCustomMarshal ($date: Date!) { } } `, - &retval, - &__input, + Variables: &__queryWithCustomMarshalInput{ + Date: date, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithCustomMarshalResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithCustomMarshalResponse) + return retval, resp.Extensions, err } func queryWithCustomMarshalOptional( @@ -3077,18 +3115,10 @@ func queryWithCustomMarshalOptional( client graphql.Client, date *time.Time, id *string, -) (*queryWithCustomMarshalOptionalResponse, error) { - __input := __queryWithCustomMarshalOptionalInput{ - Date: date, - Id: id, - } - var err error - - var retval queryWithCustomMarshalOptionalResponse - err = client.MakeRequest( - ctx, - "queryWithCustomMarshalOptional", - ` +) (*queryWithCustomMarshalOptionalResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithCustomMarshalOptional", + Query: ` query queryWithCustomMarshalOptional ($date: Date, $id: ID) { userSearch(birthdate: $date, id: $id) { id @@ -3097,27 +3127,35 @@ query queryWithCustomMarshalOptional ($date: Date, $id: ID) { } } `, - &retval, - &__input, + Variables: &__queryWithCustomMarshalOptionalInput{ + Date: date, + Id: id, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithCustomMarshalOptionalResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithCustomMarshalOptionalResponse) + return retval, resp.Extensions, err } func queryWithCustomMarshalSlice( ctx context.Context, client graphql.Client, dates []time.Time, -) (*queryWithCustomMarshalSliceResponse, error) { - __input := __queryWithCustomMarshalSliceInput{ - Dates: dates, - } - var err error - - var retval queryWithCustomMarshalSliceResponse - err = client.MakeRequest( - ctx, - "queryWithCustomMarshalSlice", - ` +) (*queryWithCustomMarshalSliceResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithCustomMarshalSlice", + Query: ` query queryWithCustomMarshalSlice ($dates: [Date!]!) { usersBornOnDates(dates: $dates) { id @@ -3126,27 +3164,34 @@ query queryWithCustomMarshalSlice ($dates: [Date!]!) { } } `, - &retval, - &__input, + Variables: &__queryWithCustomMarshalSliceInput{ + Dates: dates, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithCustomMarshalSliceResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithCustomMarshalSliceResponse) + return retval, resp.Extensions, err } func queryWithFlatten( ctx context.Context, client graphql.Client, ids []string, -) (*QueryFragment, error) { - __input := __queryWithFlattenInput{ - Ids: ids, - } - var err error - - var retval QueryFragment - err = client.MakeRequest( - ctx, - "queryWithFlatten", - ` +) (*QueryFragment, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithFlatten", + Query: ` query queryWithFlatten ($ids: [ID!]!) { ... QueryFragment } @@ -3189,27 +3234,34 @@ fragment FriendsFields on User { name } `, - &retval, - &__input, + Variables: &__queryWithFlattenInput{ + Ids: ids, + }, + } + var err error + + resp := &graphql.Response{ + Data: &QueryFragment{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*QueryFragment) + return retval, resp.Extensions, err } func queryWithFragments( ctx context.Context, client graphql.Client, ids []string, -) (*queryWithFragmentsResponse, error) { - __input := __queryWithFragmentsInput{ - Ids: ids, - } - var err error - - var retval queryWithFragmentsResponse - err = client.MakeRequest( - ctx, - "queryWithFragments", - ` +) (*queryWithFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithFragments", + Query: ` query queryWithFragments ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3246,27 +3298,34 @@ query queryWithFragments ($ids: [ID!]!) { } } `, - &retval, - &__input, + Variables: &__queryWithFragmentsInput{ + Ids: ids, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithFragmentsResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithFragmentsResponse) + return retval, resp.Extensions, err } func queryWithInterfaceListField( ctx context.Context, client graphql.Client, ids []string, -) (*queryWithInterfaceListFieldResponse, error) { - __input := __queryWithInterfaceListFieldInput{ - Ids: ids, - } - var err error - - var retval queryWithInterfaceListFieldResponse - err = client.MakeRequest( - ctx, - "queryWithInterfaceListField", - ` +) (*queryWithInterfaceListFieldResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithInterfaceListField", + Query: ` query queryWithInterfaceListField ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3275,27 +3334,34 @@ query queryWithInterfaceListField ($ids: [ID!]!) { } } `, - &retval, - &__input, + Variables: &__queryWithInterfaceListFieldInput{ + Ids: ids, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithInterfaceListFieldResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithInterfaceListFieldResponse) + return retval, resp.Extensions, err } func queryWithInterfaceListPointerField( ctx context.Context, client graphql.Client, ids []string, -) (*queryWithInterfaceListPointerFieldResponse, error) { - __input := __queryWithInterfaceListPointerFieldInput{ - Ids: ids, - } - var err error - - var retval queryWithInterfaceListPointerFieldResponse - err = client.MakeRequest( - ctx, - "queryWithInterfaceListPointerField", - ` +) (*queryWithInterfaceListPointerFieldResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithInterfaceListPointerField", + Query: ` query queryWithInterfaceListPointerField ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3304,27 +3370,34 @@ query queryWithInterfaceListPointerField ($ids: [ID!]!) { } } `, - &retval, - &__input, + Variables: &__queryWithInterfaceListPointerFieldInput{ + Ids: ids, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithInterfaceListPointerFieldResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithInterfaceListPointerFieldResponse) + return retval, resp.Extensions, err } func queryWithInterfaceNoFragments( ctx context.Context, client graphql.Client, id string, -) (*queryWithInterfaceNoFragmentsResponse, error) { - __input := __queryWithInterfaceNoFragmentsInput{ - Id: id, - } - var err error - - var retval queryWithInterfaceNoFragmentsResponse - err = client.MakeRequest( - ctx, - "queryWithInterfaceNoFragments", - ` +) (*queryWithInterfaceNoFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithInterfaceNoFragments", + Query: ` query queryWithInterfaceNoFragments ($id: ID!) { being(id: $id) { __typename @@ -3337,27 +3410,34 @@ query queryWithInterfaceNoFragments ($id: ID!) { } } `, - &retval, - &__input, + Variables: &__queryWithInterfaceNoFragmentsInput{ + Id: id, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithInterfaceNoFragmentsResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithInterfaceNoFragmentsResponse) + return retval, resp.Extensions, err } func queryWithNamedFragments( ctx context.Context, client graphql.Client, ids []string, -) (*queryWithNamedFragmentsResponse, error) { - __input := __queryWithNamedFragmentsInput{ - Ids: ids, - } - var err error - - var retval queryWithNamedFragmentsResponse - err = client.MakeRequest( - ctx, - "queryWithNamedFragments", - ` +) (*queryWithNamedFragmentsResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithNamedFragments", + Query: ` query queryWithNamedFragments ($ids: [ID!]!) { beings(ids: $ids) { __typename @@ -3394,27 +3474,34 @@ fragment MoreUserFields on User { } } `, - &retval, - &__input, + Variables: &__queryWithNamedFragmentsInput{ + Ids: ids, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithNamedFragmentsResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithNamedFragmentsResponse) + return retval, resp.Extensions, err } func queryWithOmitempty( ctx context.Context, client graphql.Client, id string, -) (*queryWithOmitemptyResponse, error) { - __input := __queryWithOmitemptyInput{ - Id: id, - } - var err error - - var retval queryWithOmitemptyResponse - err = client.MakeRequest( - ctx, - "queryWithOmitempty", - ` +) (*queryWithOmitemptyResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithOmitempty", + Query: ` query queryWithOmitempty ($id: ID) { user(id: $id) { id @@ -3423,27 +3510,34 @@ query queryWithOmitempty ($id: ID) { } } `, - &retval, - &__input, + Variables: &__queryWithOmitemptyInput{ + Id: id, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithOmitemptyResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithOmitemptyResponse) + return retval, resp.Extensions, err } func queryWithVariables( ctx context.Context, client graphql.Client, id string, -) (*queryWithVariablesResponse, error) { - __input := __queryWithVariablesInput{ - Id: id, - } - var err error - - var retval queryWithVariablesResponse - err = client.MakeRequest( - ctx, - "queryWithVariables", - ` +) (*queryWithVariablesResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "queryWithVariables", + Query: ` query queryWithVariables ($id: ID!) { user(id: $id) { id @@ -3452,24 +3546,66 @@ query queryWithVariables ($id: ID!) { } } `, - &retval, - &__input, + Variables: &__queryWithVariablesInput{ + Id: id, + }, + } + var err error + + resp := &graphql.Response{ + Data: &queryWithVariablesResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*queryWithVariablesResponse) + return retval, resp.Extensions, err } func simpleQuery( ctx context.Context, client graphql.Client, -) (*simpleQueryResponse, error) { +) (*simpleQueryResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "simpleQuery", + Query: ` +query simpleQuery { + me { + id + name + luckyNumber + } +} +`, + } var err error - var retval simpleQueryResponse + resp := &graphql.Response{ + Data: &simpleQueryResponse{}, + } + err = client.MakeRequest( ctx, - "simpleQuery", - ` -query simpleQuery { + req, + resp, + ) + + retval := resp.Data.(*simpleQueryResponse) + return retval, resp.Extensions, err +} + +func simpleQueryExt( + ctx context.Context, + client graphql.Client, +) (*simpleQueryExtResponse, map[string]interface{}, error) { + req := &graphql.Payload{ + OpName: "simpleQueryExt", + Query: ` +query simpleQueryExt { me { id name @@ -3477,8 +3613,19 @@ query simpleQuery { } } `, - &retval, - nil, + } + var err error + + resp := &graphql.Response{ + Data: &simpleQueryExtResponse{}, + } + + err = client.MakeRequest( + ctx, + req, + resp, ) - return &retval, err + + retval := resp.Data.(*simpleQueryExtResponse) + return retval, resp.Extensions, err } diff --git a/internal/integration/genqlient.yaml b/internal/integration/genqlient.yaml index 50c2cf4e..db6f988f 100644 --- a/internal/integration/genqlient.yaml +++ b/internal/integration/genqlient.yaml @@ -2,6 +2,7 @@ schema: schema.graphql operations: "*_test.go" generated: generated.go allow_broken_features: true +use_extensions: true bindings: Date: type: time.Time diff --git a/internal/integration/integration_test.go b/internal/integration/integration_test.go index 55162ad8..e41ced5e 100644 --- a/internal/integration/integration_test.go +++ b/internal/integration/integration_test.go @@ -27,7 +27,7 @@ func TestSimpleQuery(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := simpleQuery(ctx, client) + resp, _, err := simpleQuery(ctx, client) require.NoError(t, err) assert.Equal(t, "1", resp.Me.Id) @@ -44,7 +44,7 @@ func TestServerError(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := failingQuery(ctx, client) + resp, _, err := failingQuery(ctx, client) // As long as we get some response back, we should still return a full // response -- and indeed in this case it should even have another field // (which didn't err) set. @@ -57,7 +57,7 @@ func TestNetworkError(t *testing.T) { ctx := context.Background() client := newRoundtripClient(t, "https://nothing.invalid/graphql") - resp, err := failingQuery(ctx, client) + resp, _, err := failingQuery(ctx, client) // As we guarantee in the README, even on network error you always get a // non-nil response; this is so you can write e.g. // resp, err := failingQuery(ctx) @@ -82,19 +82,34 @@ func TestVariables(t *testing.T) { // worry about it. client := graphql.NewClient(server.URL, http.DefaultClient) - resp, err := queryWithVariables(ctx, client, "2") + resp, _, err := queryWithVariables(ctx, client, "2") require.NoError(t, err) assert.Equal(t, "2", resp.User.Id) assert.Equal(t, "Raven", resp.User.Name) assert.Equal(t, -1, resp.User.LuckyNumber) - resp, err = queryWithVariables(ctx, client, "374892379482379") + resp, _, err = queryWithVariables(ctx, client, "374892379482379") require.NoError(t, err) assert.Zero(t, resp.User) } +func TestExtensions(t *testing.T) { + _ = `# @genqlient + query simpleQueryExt { me { id name luckyNumber } }` + + ctx := context.Background() + server := server.RunServer() + defer server.Close() + client := newRoundtripClient(t, server.URL) + + _, extensions, err := simpleQueryExt(ctx, client) + require.NoError(t, err) + assert.NotNil(t, extensions) + assert.Equal(t, extensions["foobar"], "test") +} + func TestOmitempty(t *testing.T) { _ = `# @genqlient(omitempty: true) query queryWithOmitempty($id: ID) { @@ -106,7 +121,7 @@ func TestOmitempty(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithOmitempty(ctx, client, "2") + resp, _, err := queryWithOmitempty(ctx, client, "2") require.NoError(t, err) assert.Equal(t, "2", resp.User.Id) @@ -114,7 +129,7 @@ func TestOmitempty(t *testing.T) { assert.Equal(t, -1, resp.User.LuckyNumber) // should return default user, not the user with ID "" - resp, err = queryWithOmitempty(ctx, client, "") + resp, _, err = queryWithOmitempty(ctx, client, "") require.NoError(t, err) assert.Equal(t, "1", resp.User.Id) @@ -133,7 +148,7 @@ func TestCustomMarshal(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithCustomMarshal(ctx, client, + resp, _, err := queryWithCustomMarshal(ctx, client, time.Date(2025, time.January, 1, 12, 34, 56, 789, time.UTC)) require.NoError(t, err) @@ -145,7 +160,7 @@ func TestCustomMarshal(t *testing.T) { time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC), user.Birthdate) - resp, err = queryWithCustomMarshal(ctx, client, + resp, _, err = queryWithCustomMarshal(ctx, client, time.Date(2021, time.January, 1, 12, 34, 56, 789, time.UTC)) require.NoError(t, err) assert.Len(t, resp.UsersBornOn, 0) @@ -162,7 +177,7 @@ func TestCustomMarshalSlice(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithCustomMarshalSlice(ctx, client, + resp, _, err := queryWithCustomMarshalSlice(ctx, client, []time.Time{time.Date(2025, time.January, 1, 12, 34, 56, 789, time.UTC)}) require.NoError(t, err) @@ -174,7 +189,7 @@ func TestCustomMarshalSlice(t *testing.T) { time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC), user.Birthdate) - resp, err = queryWithCustomMarshalSlice(ctx, client, + resp, _, err = queryWithCustomMarshalSlice(ctx, client, []time.Time{time.Date(2021, time.January, 1, 12, 34, 56, 789, time.UTC)}) require.NoError(t, err) assert.Len(t, resp.UsersBornOnDates, 0) @@ -197,7 +212,7 @@ func TestCustomMarshalOptional(t *testing.T) { client := newRoundtripClient(t, server.URL) date := time.Date(2025, time.January, 1, 12, 34, 56, 789, time.UTC) - resp, err := queryWithCustomMarshalOptional(ctx, client, &date, nil) + resp, _, err := queryWithCustomMarshalOptional(ctx, client, &date, nil) require.NoError(t, err) assert.Len(t, resp.UserSearch, 1) @@ -209,7 +224,7 @@ func TestCustomMarshalOptional(t *testing.T) { user.Birthdate) id := "2" - resp, err = queryWithCustomMarshalOptional(ctx, client, nil, &id) + resp, _, err = queryWithCustomMarshalOptional(ctx, client, nil, &id) require.NoError(t, err) assert.Len(t, resp.UserSearch, 1) user = resp.UserSearch[0] @@ -230,7 +245,7 @@ func TestInterfaceNoFragments(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithInterfaceNoFragments(ctx, client, "1") + resp, _, err := queryWithInterfaceNoFragments(ctx, client, "1") require.NoError(t, err) // We should get the following response: @@ -250,7 +265,7 @@ func TestInterfaceNoFragments(t *testing.T) { assert.Equal(t, "1", user.Id) assert.Equal(t, "Yours Truly", user.Name) - resp, err = queryWithInterfaceNoFragments(ctx, client, "3") + resp, _, err = queryWithInterfaceNoFragments(ctx, client, "3") require.NoError(t, err) // We should get the following response: @@ -269,7 +284,7 @@ func TestInterfaceNoFragments(t *testing.T) { assert.Equal(t, "3", animal.Id) assert.Equal(t, "Fido", animal.Name) - resp, err = queryWithInterfaceNoFragments(ctx, client, "4757233945723") + resp, _, err = queryWithInterfaceNoFragments(ctx, client, "4757233945723") require.NoError(t, err) // We should get the following response: @@ -293,7 +308,7 @@ func TestInterfaceListField(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithInterfaceListField(ctx, client, + resp, _, err := queryWithInterfaceListField(ctx, client, []string{"1", "3", "12847394823"}) require.NoError(t, err) @@ -340,7 +355,7 @@ func TestInterfaceListPointerField(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithInterfaceListPointerField(ctx, client, + resp, _, err := queryWithInterfaceListPointerField(ctx, client, []string{"1", "3", "12847394823"}) require.NoError(t, err) @@ -394,7 +409,7 @@ func TestFragments(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithFragments(ctx, client, []string{"1", "3", "12847394823"}) + resp, _, err := queryWithFragments(ctx, client, []string{"1", "3", "12847394823"}) require.NoError(t, err) require.Len(t, resp.Beings, 3) @@ -487,7 +502,7 @@ func TestNamedFragments(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithNamedFragments(ctx, client, []string{"1", "3", "12847394823"}) + resp, _, err := queryWithNamedFragments(ctx, client, []string{"1", "3", "12847394823"}) require.NoError(t, err) require.Len(t, resp.Beings, 3) @@ -616,7 +631,7 @@ func TestFlatten(t *testing.T) { defer server.Close() client := newRoundtripClient(t, server.URL) - resp, err := queryWithFlatten(ctx, client, []string{"1", "3", "12847394823"}) + resp, _, err := queryWithFlatten(ctx, client, []string{"1", "3", "12847394823"}) require.NoError(t, err) require.Len(t, resp.Beings, 3) diff --git a/internal/integration/roundtrip.go b/internal/integration/roundtrip.go index 0fec83d3..583b4441 100644 --- a/internal/integration/roundtrip.go +++ b/internal/integration/roundtrip.go @@ -88,16 +88,16 @@ func (c *roundtripClient) roundtripResponse(resp interface{}) { assert.Equal(c.t, string(body), string(bodyAgain)) } -func (c *roundtripClient) MakeRequest(ctx context.Context, opName, query string, retval, variables interface{}) error { +func (c *roundtripClient) MakeRequest(ctx context.Context, req *graphql.Payload, resp *graphql.Response) error { // TODO(benkraft): Also check the variables round-trip. This is a bit less // important since most of the code is the same (and input types are // strictly simpler), and a bit hard to do because when asserting about // structs we need to worry about things like equality of time.Time values. - err := c.wrapped.MakeRequest(ctx, opName, query, retval, variables) + err := c.wrapped.MakeRequest(ctx, req, resp) if err != nil { return err } - c.roundtripResponse(retval) + c.roundtripResponse(resp.Data) return nil } diff --git a/internal/integration/server/gqlgen_exec.go b/internal/integration/server/gqlgen_exec.go index 14a76075..d0e4fd99 100644 --- a/internal/integration/server/gqlgen_exec.go +++ b/internal/integration/server/gqlgen_exec.go @@ -531,21 +531,6 @@ func (ec *executionContext) field_Query_usersBornOn_args(ctx context.Context, ra return args, nil } -func (ec *executionContext) field___Field_args_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { - var err error - args := map[string]interface{}{} - var arg0 *bool - if tmp, ok := rawArgs["includeDeprecated"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) - arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) - if err != nil { - return nil, err - } - } - args["includeDeprecated"] = arg0 - return args, nil -} - func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -1484,14 +1469,14 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field Object: "__Directive", Field: field, Args: nil, - IsMethod: false, + IsMethod: true, IsResolver: false, } ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Description(), nil }) if err != nil { ec.Error(ctx, err) @@ -1500,9 +1485,9 @@ func (ec *executionContext) ___Directive_description(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { @@ -1656,14 +1641,14 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field Object: "__EnumValue", Field: field, Args: nil, - IsMethod: false, + IsMethod: true, IsResolver: false, } ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Description(), nil }) if err != nil { ec.Error(ctx, err) @@ -1672,9 +1657,9 @@ func (ec *executionContext) ___EnumValue_description(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { @@ -1790,14 +1775,14 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap Object: "__Field", Field: field, Args: nil, - IsMethod: false, + IsMethod: true, IsResolver: false, } ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Description(), nil }) if err != nil { ec.Error(ctx, err) @@ -1806,9 +1791,9 @@ func (ec *executionContext) ___Field_description(ctx context.Context, field grap if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { @@ -1827,13 +1812,6 @@ func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.Col } ctx = graphql.WithFieldContext(ctx, fc) - rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field___Field_args_args(ctx, rawArgs) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - fc.Args = args resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children return obj.Args, nil @@ -2001,14 +1979,14 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field Object: "__InputValue", Field: field, Args: nil, - IsMethod: false, + IsMethod: true, IsResolver: false, } ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Description(), nil }) if err != nil { ec.Error(ctx, err) @@ -2017,9 +1995,9 @@ func (ec *executionContext) ___InputValue_description(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { @@ -2089,6 +2067,38 @@ func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, fiel return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } +func (ec *executionContext) ___Schema_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "__Schema", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -2352,9 +2362,9 @@ func (ec *executionContext) ___Type_description(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalOString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { @@ -2563,6 +2573,38 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } +func (ec *executionContext) ___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "__Type", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SpecifiedByURL(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + // endregion **************************** field.gotpl ***************************** // region **************************** input.gotpl ***************************** @@ -2618,7 +2660,6 @@ var animalImplementors = []string{"Animal", "Being"} func (ec *executionContext) _Animal(ctx context.Context, sel ast.SelectionSet, obj *Animal) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, animalImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2626,24 +2667,49 @@ func (ec *executionContext) _Animal(ctx context.Context, sel ast.SelectionSet, o case "__typename": out.Values[i] = graphql.MarshalString("Animal") case "id": - out.Values[i] = ec._Animal_id(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Animal_id(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "name": - out.Values[i] = ec._Animal_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Animal_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "species": - out.Values[i] = ec._Animal_species(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Animal_species(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "owner": - out.Values[i] = ec._Animal_owner(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Animal_owner(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "hair": - out.Values[i] = ec._Animal_hair(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Animal_hair(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -2659,7 +2725,6 @@ var beingsHairImplementors = []string{"BeingsHair"} func (ec *executionContext) _BeingsHair(ctx context.Context, sel ast.SelectionSet, obj *BeingsHair) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, beingsHairImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2667,7 +2732,12 @@ func (ec *executionContext) _BeingsHair(ctx context.Context, sel ast.SelectionSe case "__typename": out.Values[i] = graphql.MarshalString("BeingsHair") case "hasHair": - out.Values[i] = ec._BeingsHair_hasHair(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._BeingsHair_hasHair(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } @@ -2686,7 +2756,6 @@ var hairImplementors = []string{"Hair"} func (ec *executionContext) _Hair(ctx context.Context, sel ast.SelectionSet, obj *Hair) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, hairImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2694,7 +2763,12 @@ func (ec *executionContext) _Hair(ctx context.Context, sel ast.SelectionSet, obj case "__typename": out.Values[i] = graphql.MarshalString("Hair") case "color": - out.Values[i] = ec._Hair_color(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Hair_color(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -2710,7 +2784,6 @@ var queryImplementors = []string{"Query"} func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, queryImplementors) - ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ Object: "Query", }) @@ -2718,12 +2791,18 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") case "me": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2731,10 +2810,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_me(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "user": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2742,10 +2830,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_user(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "being": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2753,10 +2850,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_being(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "beings": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2767,10 +2873,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr atomic.AddUint32(&invalids, 1) } return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "lotteryWinner": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2778,10 +2893,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_lotteryWinner(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "usersBornOn": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2792,10 +2916,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr atomic.AddUint32(&invalids, 1) } return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "usersBornOnDates": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2806,10 +2939,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr atomic.AddUint32(&invalids, 1) } return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "userSearch": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2817,10 +2959,19 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_userSearch(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "fail": field := field - out.Concurrently(i, func() (res graphql.Marshaler) { + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -2828,11 +2979,29 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }() res = ec._Query_fail(ctx, field) return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) }) case "__type": - out.Values[i] = ec._Query___type(ctx, field) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___type(ctx, field) + } + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, innerFunc) + case "__schema": - out.Values[i] = ec._Query___schema(ctx, field) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___schema(ctx, field) + } + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, innerFunc) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -2848,7 +3017,6 @@ var userImplementors = []string{"User", "Being", "Lucky"} func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *User) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, userImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2856,23 +3024,53 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj case "__typename": out.Values[i] = graphql.MarshalString("User") case "id": - out.Values[i] = ec._User_id(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_id(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "name": - out.Values[i] = ec._User_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "luckyNumber": - out.Values[i] = ec._User_luckyNumber(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_luckyNumber(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "hair": - out.Values[i] = ec._User_hair(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_hair(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "birthdate": - out.Values[i] = ec._User_birthdate(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_birthdate(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "friends": - out.Values[i] = ec._User_friends(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec._User_friends(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } @@ -2891,7 +3089,6 @@ var __DirectiveImplementors = []string{"__Directive"} func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __DirectiveImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2899,24 +3096,49 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS case "__typename": out.Values[i] = graphql.MarshalString("__Directive") case "name": - out.Values[i] = ec.___Directive_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Directive_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "description": - out.Values[i] = ec.___Directive_description(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Directive_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "locations": - out.Values[i] = ec.___Directive_locations(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Directive_locations(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "args": - out.Values[i] = ec.___Directive_args(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Directive_args(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "isRepeatable": - out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Directive_isRepeatable(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } @@ -2935,7 +3157,6 @@ var __EnumValueImplementors = []string{"__EnumValue"} func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __EnumValueImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2943,19 +3164,39 @@ func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionS case "__typename": out.Values[i] = graphql.MarshalString("__EnumValue") case "name": - out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___EnumValue_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "description": - out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___EnumValue_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "isDeprecated": - out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___EnumValue_isDeprecated(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "deprecationReason": - out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___EnumValue_deprecationReason(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -2971,7 +3212,6 @@ var __FieldImplementors = []string{"__Field"} func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -2979,29 +3219,59 @@ func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, case "__typename": out.Values[i] = graphql.MarshalString("__Field") case "name": - out.Values[i] = ec.___Field_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "description": - out.Values[i] = ec.___Field_description(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "args": - out.Values[i] = ec.___Field_args(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_args(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "type": - out.Values[i] = ec.___Field_type(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_type(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "isDeprecated": - out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_isDeprecated(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "deprecationReason": - out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Field_deprecationReason(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -3017,7 +3287,6 @@ var __InputValueImplementors = []string{"__InputValue"} func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -3025,19 +3294,39 @@ func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.Selection case "__typename": out.Values[i] = graphql.MarshalString("__InputValue") case "name": - out.Values[i] = ec.___InputValue_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___InputValue_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "description": - out.Values[i] = ec.___InputValue_description(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___InputValue_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "type": - out.Values[i] = ec.___InputValue_type(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___InputValue_type(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "defaultValue": - out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___InputValue_defaultValue(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -3053,29 +3342,60 @@ var __SchemaImplementors = []string{"__Schema"} func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("__Schema") + case "description": + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "types": - out.Values[i] = ec.___Schema_types(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_types(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "queryType": - out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_queryType(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "mutationType": - out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_mutationType(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "subscriptionType": - out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_subscriptionType(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "directives": - out.Values[i] = ec.___Schema_directives(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Schema_directives(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } @@ -3094,7 +3414,6 @@ var __TypeImplementors = []string{"__Type"} func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) - out := graphql.NewFieldSet(fields) var invalids uint32 for i, field := range fields { @@ -3102,26 +3421,78 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o case "__typename": out.Values[i] = graphql.MarshalString("__Type") case "kind": - out.Values[i] = ec.___Type_kind(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_kind(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + if out.Values[i] == graphql.Null { invalids++ } case "name": - out.Values[i] = ec.___Type_name(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_name(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "description": - out.Values[i] = ec.___Type_description(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_description(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "fields": - out.Values[i] = ec.___Type_fields(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_fields(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "interfaces": - out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_interfaces(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "possibleTypes": - out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_possibleTypes(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "enumValues": - out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_enumValues(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "inputFields": - out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_inputFields(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + case "ofType": - out.Values[i] = ec.___Type_ofType(ctx, field, obj) + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_ofType(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + + case "specifiedByURL": + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + return ec.___Type_specifiedByURL(ctx, field, obj) + } + + out.Values[i] = innerFunc(ctx) + default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -3208,11 +3579,7 @@ func (ec *executionContext) marshalNDate2string(ctx context.Context, sel ast.Sel func (ec *executionContext) unmarshalNDate2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { var vSlice []interface{} if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } + vSlice = graphql.CoerceList(v) } var err error res := make([]string, len(vSlice)) @@ -3259,11 +3626,7 @@ func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.Selec func (ec *executionContext) unmarshalNID2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { var vSlice []interface{} if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } + vSlice = graphql.CoerceList(v) } var err error res := make([]string, len(vSlice)) @@ -3452,11 +3815,7 @@ func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Conte func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { var vSlice []interface{} if v != nil { - if tmp1, ok := v.([]interface{}); ok { - vSlice = tmp1 - } else { - vSlice = []interface{}{v} - } + vSlice = graphql.CoerceList(v) } var err error res := make([]string, len(vSlice)) @@ -3663,7 +4022,8 @@ func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interf } func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { - return graphql.MarshalBoolean(v) + res := graphql.MarshalBoolean(v) + return res } func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { @@ -3678,7 +4038,8 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast if v == nil { return graphql.Null } - return graphql.MarshalBoolean(*v) + res := graphql.MarshalBoolean(*v) + return res } func (ec *executionContext) unmarshalODate2ᚖstring(ctx context.Context, v interface{}) (*string, error) { @@ -3693,7 +4054,8 @@ func (ec *executionContext) marshalODate2ᚖstring(ctx context.Context, sel ast. if v == nil { return graphql.Null } - return graphql.MarshalString(*v) + res := graphql.MarshalString(*v) + return res } func (ec *executionContext) marshalOHair2ᚖgithubᚗcomᚋKhanᚋgenqlientᚋinternalᚋintegrationᚋserverᚐHair(ctx context.Context, sel ast.SelectionSet, v *Hair) graphql.Marshaler { @@ -3715,7 +4077,8 @@ func (ec *executionContext) marshalOID2ᚖstring(ctx context.Context, sel ast.Se if v == nil { return graphql.Null } - return graphql.MarshalID(*v) + res := graphql.MarshalID(*v) + return res } func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { @@ -3730,7 +4093,8 @@ func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.Sele if v == nil { return graphql.Null } - return graphql.MarshalInt(*v) + res := graphql.MarshalInt(*v) + return res } func (ec *executionContext) marshalOLucky2githubᚗcomᚋKhanᚋgenqlientᚋinternalᚋintegrationᚋserverᚐLucky(ctx context.Context, sel ast.SelectionSet, v Lucky) graphql.Marshaler { @@ -3740,15 +4104,6 @@ func (ec *executionContext) marshalOLucky2githubᚗcomᚋKhanᚋgenqlientᚋinte return ec._Lucky(ctx, sel, v) } -func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { - res, err := graphql.UnmarshalString(v) - return res, graphql.ErrorOnPath(ctx, err) -} - -func (ec *executionContext) marshalOString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { - return graphql.MarshalString(v) -} - func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { if v == nil { return nil, nil @@ -3761,7 +4116,8 @@ func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel as if v == nil { return graphql.Null } - return graphql.MarshalString(*v) + res := graphql.MarshalString(*v) + return res } func (ec *executionContext) marshalOUser2ᚕᚖgithubᚗcomᚋKhanᚋgenqlientᚋinternalᚋintegrationᚋserverᚐUser(ctx context.Context, sel ast.SelectionSet, v []*User) graphql.Marshaler { diff --git a/internal/integration/server/server.go b/internal/integration/server/server.go index 69883565..e94adb4e 100644 --- a/internal/integration/server/server.go +++ b/internal/integration/server/server.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http/httptest" + "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/handler" "github.com/99designs/gqlgen/graphql/handler/transport" ) @@ -131,6 +132,10 @@ func (r *queryResolver) Fail(ctx context.Context) (*bool, error) { func RunServer() *httptest.Server { gqlgenServer := handler.New(NewExecutableSchema(Config{Resolvers: &resolver{}})) gqlgenServer.AddTransport(transport.POST{}) + gqlgenServer.AroundResponses(func(ctx context.Context, next graphql.ResponseHandler) *graphql.Response { + graphql.RegisterExtension(ctx, "foobar", "test") + return next(ctx) + }) return httptest.NewServer(gqlgenServer) } From 0533d6b7d28f6fa2b8a85e29eb6ed66d69fe5b18 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Wed, 30 Mar 2022 14:51:22 +0200 Subject: [PATCH 2/9] Removing testing file --- generate/testdata/queries/foo.go | 69 ------------------- ...NoContext#01-testdata-queries-generated.go | 69 ------------------- 2 files changed, 138 deletions(-) delete mode 100644 generate/testdata/queries/foo.go delete mode 100644 generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go diff --git a/generate/testdata/queries/foo.go b/generate/testdata/queries/foo.go deleted file mode 100644 index 70ccf2d6..00000000 --- a/generate/testdata/queries/foo.go +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated by github.com/Khan/genqlient, DO NOT EDIT. - -package queries - -import ( - "context" - - "github.com/Khan/genqlient/graphql" -) - -// SimpleQueryResponse is returned by SimpleQuery on success. -type SimpleQueryResponse struct { - // user looks up a user by some stuff. - // - // See UserQueryInput for what stuff is supported. - // If query is null, returns the current user. - User SimpleQueryUser `json:"user"` -} - -// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface. -func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User } - -// SimpleQueryUser includes the requested fields of the GraphQL type User. -// The GraphQL type's documentation follows. -// -// A User is a user! -type SimpleQueryUser struct { - // id is the user's ID. - // - // It is stable, unique, and opaque, like all good IDs. - Id string `json:"id"` -} - -// 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, - client graphql.Client, -) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ - OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, - } - var err error - var client graphql.Client - - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } - - err = client.MakeRequest( - ctx, - req, - resp, - ) - if err != nil { - return nil, err - } - - retval := resp.Data.(*SimpleQueryResponse) - return retval, err -} diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go deleted file mode 100644 index 44ee04ec..00000000 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext#01-testdata-queries-generated.go +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated by github.com/Khan/genqlient, DO NOT EDIT. - -package queries - -import ( - "context" - - "github.com/Khan/genqlient/graphql" -) - -// SimpleQueryResponse is returned by SimpleQuery on success. -type SimpleQueryResponse struct { - // user looks up a user by some stuff. - // - // See UserQueryInput for what stuff is supported. - // If query is null, returns the current user. - User SimpleQueryUser `json:"user"` -} - -// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface. -func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User } - -// SimpleQueryUser includes the requested fields of the GraphQL type User. -// The GraphQL type's documentation follows. -// -// A User is a user! -type SimpleQueryUser struct { - // id is the user's ID. - // - // It is stable, unique, and opaque, like all good IDs. - Id string `json:"id"` -} - -// 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, - client graphql.Client, -) (*SimpleQueryResponse, map[string]interface{}, error) { - req := &graphql.Payload{ - OpName: "SimpleQuery", - Query: ` -query SimpleQuery { - user { - id - } -} -`, - } - var err error - - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } - - err = client.MakeRequest( - ctx, - req, - resp, - ) - if err != nil { - return nil, nil, err - } - - retval := resp.Data.(*SimpleQueryResponse) - return retval, resp.Extensions, err -} - From e9e5ad15e944de7fcc5e18364d7c4c94e41bfe08 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Wed, 30 Mar 2022 16:15:18 +0200 Subject: [PATCH 3/9] Rename Payload to Request --- example/generated.go | 4 +-- generate/operation.go.tmpl | 2 +- ....graphql-ComplexInlineFragments.graphql.go | 2 +- ...s.graphql-ComplexNamedFragments.graphql.go | 2 +- ...omMarshal.graphql-CustomMarshal.graphql.go | 2 +- ...lice.graphql-CustomMarshalSlice.graphql.go | 2 +- ...erate-DateTime.graphql-DateTime.graphql.go | 2 +- ...nterface.graphql-EmptyInterface.graphql.go | 2 +- ...enerate-Flatten.graphql-Flatten.graphql.go | 2 +- ...ate-InputEnum.graphql-InputEnum.graphql.go | 2 +- ...InputObject.graphql-InputObject.graphql.go | 2 +- ...ield.graphql-InterfaceListField.graphql.go | 2 +- ...nterfaceListOfListsOfListsField.graphql.go | 2 +- ...esting.graphql-InterfaceNesting.graphql.go | 2 +- ...ts.graphql-InterfaceNoFragments.graphql.go | 2 +- ...ate-ListInput.graphql-ListInput.graphql.go | 2 +- ...ists.graphql-ListOfListsOfLists.graphql.go | 2 +- ...ives.graphql-MultipleDirectives.graphql.go | 2 +- ...ate-Omitempty.graphql-Omitempty.graphql.go | 2 +- ...erate-Pointers.graphql-Pointers.graphql.go | 2 +- ...rsInline.graphql-PointersInline.graphql.go | 2 +- ...enerate-Pokemon.graphql-Pokemon.graphql.go | 2 +- ...ithAlias.graphql-QueryWithAlias.graphql.go | 2 +- ...as.graphql-QueryWithDoubleAlias.graphql.go | 2 +- ...ithEnums.graphql-QueryWithEnums.graphql.go | 2 +- ...hSlices.graphql-QueryWithSlices.graphql.go | 2 +- ...tructs.graphql-QueryWithStructs.graphql.go | 2 +- ...ate-Recursion.graphql-Recursion.graphql.go | 2 +- ...nt.graphql-SimpleInlineFragment.graphql.go | 2 +- ...SimpleInput.graphql-SimpleInput.graphql.go | 2 +- ...Mutation.graphql-SimpleMutation.graphql.go | 2 +- ...ent.graphql-SimpleNamedFragment.graphql.go | 2 +- ...SimpleQuery.graphql-SimpleQuery.graphql.go | 2 +- ...ructOption.graphql-StructOption.graphql.go | 2 +- ...erate-TypeName.graphql-TypeName.graphql.go | 2 +- ...ate-TypeNames.graphql-TypeNames.graphql.go | 2 +- ...gments.graphql-UnionNoFragments.graphql.go | 2 +- ...EnumTwice.graphql-UsesEnumTwice.graphql.go | 2 +- ...e-unexported.graphql-unexported.graphql.go | 2 +- ...ClientGetter-testdata-queries-generated.go | 2 +- ...ustomContext-testdata-queries-generated.go | 2 +- ...terNoContext-testdata-queries-generated.go | 2 +- ...ustomContext-testdata-queries-generated.go | 2 +- ...efaultConfig-testdata-queries-generated.go | 2 +- ...rtOperations-testdata-queries-generated.go | 2 +- ...g-Extensions-testdata-queries-generated.go | 2 +- ...ig-NoContext-testdata-queries-generated.go | 2 +- ...fig-PackageName-testdata-queries-myfile.go | 2 +- ...s-testdata-queries-generated-structrefs.go | 2 +- ...ubpackage-testdata-queries-mypkg-myfile.go | 2 +- ...ageConfig-testdata-queries-mypkg-myfile.go | 2 +- graphql/client.go | 8 +++--- internal/integration/generated.go | 28 +++++++++---------- internal/integration/roundtrip.go | 2 +- 54 files changed, 71 insertions(+), 71 deletions(-) diff --git a/example/generated.go b/example/generated.go index a0476bdf..301b3847 100644 --- a/example/generated.go +++ b/example/generated.go @@ -75,7 +75,7 @@ func getUser( client graphql.Client, Login string, ) (*getUserResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "getUser", Query: ` query getUser ($Login: String!) { @@ -109,7 +109,7 @@ func getViewer( ctx context.Context, client graphql.Client, ) (*getViewerResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "getViewer", Query: ` query getViewer { diff --git a/generate/operation.go.tmpl b/generate/operation.go.tmpl index 71f992a6..9126e68b 100644 --- a/generate/operation.go.tmpl +++ b/generate/operation.go.tmpl @@ -13,7 +13,7 @@ func {{.Name}}( {{end -}} {{end -}} ) (*{{.ResponseName}}, {{if .Config.Extensions -}}map[string]interface{},{{end}} error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "{{.Name}}", Query: `{{.Body}}`, {{if .Input -}} diff --git a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go index f9ab687e..22440799 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go @@ -1348,7 +1348,7 @@ func (v *ComplexInlineFragmentsRootTopic) GetName() string { return v.Name } func ComplexInlineFragments( client graphql.Client, ) (*ComplexInlineFragmentsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "ComplexInlineFragments", Query: ` query ComplexInlineFragments { diff --git a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go index f65fdb70..93b39ca8 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go @@ -1742,7 +1742,7 @@ func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } func ComplexNamedFragments( client graphql.Client, ) (*ComplexNamedFragmentsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "ComplexNamedFragments", Query: ` query ComplexNamedFragments { diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go index 21476ac9..a777fcb1 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go @@ -178,7 +178,7 @@ func CustomMarshal( client graphql.Client, date time.Time, ) (*CustomMarshalResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "CustomMarshal", Query: ` query CustomMarshal ($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 630dd484..529f0402 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go @@ -208,7 +208,7 @@ func CustomMarshalSlice( datesss [][][]time.Time, datesssp [][][]*time.Time, ) (*CustomMarshalSliceResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "CustomMarshalSlice", Query: ` query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { diff --git a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go index 8721f24d..cd243589 100644 --- a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go @@ -33,7 +33,7 @@ func convertTimezone( dt time.Time, tz string, ) (*convertTimezoneResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "convertTimezone", Query: ` query convertTimezone ($dt: DateTime!, $tz: String) { diff --git a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go index e7658b99..89a575cd 100644 --- a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go @@ -23,7 +23,7 @@ func (v *EmptyInterfaceResponse) GetGetComplexJunk() []map[string]*[]*map[string func EmptyInterface( client graphql.Client, ) (*EmptyInterfaceResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "EmptyInterface", Query: ` query EmptyInterface { diff --git a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go index 84dbed23..1db1d545 100644 --- a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go @@ -269,7 +269,7 @@ func (v *VideoFieldsParentTopic) GetVideoChildren() []ChildVideoFields { return func ComplexNamedFragments( client graphql.Client, ) (*InnerQueryFragment, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "ComplexNamedFragments", Query: ` query ComplexNamedFragments { diff --git a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go index 26fa1d11..3bccd3c1 100644 --- a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go @@ -58,7 +58,7 @@ func InputEnumQuery( client graphql.Client, role Role, ) (*InputEnumQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InputEnumQuery", Query: ` query InputEnumQuery ($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 5baa712e..920de9d9 100644 --- a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go @@ -181,7 +181,7 @@ func InputObjectQuery( client graphql.Client, query UserQueryInput, ) (*InputObjectQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InputObjectQuery", Query: ` query InputObjectQuery ($query: UserQueryInput) { diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go index 652a2478..a85d291f 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go @@ -523,7 +523,7 @@ func (v *InterfaceListFieldWithPointerTopicChildrenVideo) GetName() string { ret func InterfaceListField( client graphql.Client, ) (*InterfaceListFieldResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InterfaceListField", Query: ` query InterfaceListField { diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go index b3555044..bc48e9cf 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go @@ -509,7 +509,7 @@ func (v *InterfaceListOfListOfListsFieldWithPointerVideo) GetName() *string { re func InterfaceListOfListOfListsField( client graphql.Client, ) (*InterfaceListOfListOfListsFieldResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InterfaceListOfListOfListsField", Query: ` query InterfaceListOfListOfListsField { diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go index cfbaf162..1f19dad9 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go @@ -507,7 +507,7 @@ func (v *InterfaceNestingRootTopicChildrenVideo) GetParent() InterfaceNestingRoo func InterfaceNesting( client graphql.Client, ) (*InterfaceNestingResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InterfaceNesting", Query: ` query InterfaceNesting { diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go index e8d15fd4..65d2e164 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go @@ -629,7 +629,7 @@ func (v *InterfaceNoFragmentsQueryWithPointerVideo) GetName() *string { return v func InterfaceNoFragmentsQuery( client graphql.Client, ) (*InterfaceNoFragmentsQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "InterfaceNoFragmentsQuery", Query: ` query InterfaceNoFragmentsQuery { diff --git a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go index 96b7731b..387de625 100644 --- a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go @@ -45,7 +45,7 @@ func ListInputQuery( client graphql.Client, names []string, ) (*ListInputQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "ListInputQuery", Query: ` query ListInputQuery ($names: [String]) { diff --git a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go index 1df2ab19..a1e30863 100644 --- a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go @@ -19,7 +19,7 @@ func (v *ListOfListsOfListsResponse) GetListOfListsOfLists() [][][]string { func ListOfListsOfLists( client graphql.Client, ) (*ListOfListsOfListsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "ListOfListsOfLists", Query: ` query ListOfListsOfLists { diff --git a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go index cdba3004..c4ad14de 100644 --- a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go @@ -330,7 +330,7 @@ func MultipleDirectives( query MyInput, queries []*UserQueryInput, ) (*MyMultipleDirectivesResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "MultipleDirectives", Query: ` query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { diff --git a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go index 8d357ee6..b04eaf3d 100644 --- a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go @@ -227,7 +227,7 @@ func OmitEmptyQuery( tz string, tzNoOmitEmpty string, ) (*OmitEmptyQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "OmitEmptyQuery", Query: ` query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: DateTime, $tz: String, $tzNoOmitEmpty: String) { diff --git a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go index 409297e8..8285c95d 100644 --- a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go @@ -236,7 +236,7 @@ func PointersQuery( dt time.Time, tz *string, ) (*PointersQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "PointersQuery", Query: ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { diff --git a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go index 04c552a5..b2921e7d 100644 --- a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go @@ -233,7 +233,7 @@ func PointersQuery( dt *time.Time, tz string, ) (*PointersQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "PointersQuery", Query: ` query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { diff --git a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go index 14b42928..d34529fc 100644 --- a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go @@ -75,7 +75,7 @@ func GetPokemonSiblings( client graphql.Client, input testutil.Pokemon, ) (*GetPokemonSiblingsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "GetPokemonSiblings", Query: ` query GetPokemonSiblings ($input: PokemonInput!) { diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go index 552baf1a..a26c6732 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go @@ -43,7 +43,7 @@ func (v *QueryWithAliasUser) GetOtherID() testutil.ID { return v.OtherID } func QueryWithAlias( client graphql.Client, ) (*QueryWithAliasResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "QueryWithAlias", Query: ` query QueryWithAlias { diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go index 51d9ce47..795941e1 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go @@ -43,7 +43,7 @@ func (v *QueryWithDoubleAliasUser) GetAlsoID() testutil.ID { return v.AlsoID } func QueryWithDoubleAlias( client graphql.Client, ) (*QueryWithDoubleAliasResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "QueryWithDoubleAlias", Query: ` query QueryWithDoubleAlias { diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go index c0226153..791cda21 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go @@ -65,7 +65,7 @@ const ( func QueryWithEnums( client graphql.Client, ) (*QueryWithEnumsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "QueryWithEnums", Query: ` query QueryWithEnums { diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go index 21069a5d..16b11665 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go @@ -44,7 +44,7 @@ func (v *QueryWithSlicesUser) GetEmailsWithNullsOrNull() []string { return v.Ema func QueryWithSlices( client graphql.Client, ) (*QueryWithSlicesResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "QueryWithSlices", Query: ` query QueryWithSlices { diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go index 33a7fa6b..4fb2b47e 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go @@ -46,7 +46,7 @@ func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetEmail() string { return v func QueryWithStructs( client graphql.Client, ) (*QueryWithStructsResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "QueryWithStructs", Query: ` query QueryWithStructs { diff --git a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go index ce07a485..61eafc1f 100644 --- a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go @@ -72,7 +72,7 @@ func Recursion( client graphql.Client, input RecursiveInput, ) (*RecursionResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "Recursion", Query: ` query Recursion ($input: RecursiveInput!) { diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go index 2227003f..a21e7f41 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go @@ -242,7 +242,7 @@ func (v *SimpleInlineFragmentResponse) __premarshalJSON() (*__premarshalSimpleIn func SimpleInlineFragment( client graphql.Client, ) (*SimpleInlineFragmentResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleInlineFragment", Query: ` query SimpleInlineFragment { diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go index f689b585..20d13207 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go @@ -45,7 +45,7 @@ func SimpleInputQuery( client graphql.Client, name string, ) (*SimpleInputQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleInputQuery", Query: ` query SimpleInputQuery ($name: String!) { diff --git a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go index 66f3a4ce..283a8a53 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go @@ -49,7 +49,7 @@ func SimpleMutation( client graphql.Client, name string, ) (*SimpleMutationResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleMutation", Query: ` mutation SimpleMutation ($name: String!) { diff --git a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go index 5ca9c01d..175c50a9 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go @@ -549,7 +549,7 @@ func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } func SimpleNamedFragment( client graphql.Client, ) (*SimpleNamedFragmentResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleNamedFragment", Query: ` query SimpleNamedFragment { diff --git a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go index fd843199..589a50a3 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go @@ -36,7 +36,7 @@ func (v *SimpleQueryUser) GetId() testutil.ID { return v.Id } func SimpleQuery( client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go index 06ec1c7c..de07f933 100644 --- a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go @@ -427,7 +427,7 @@ func (v *VideoFields) GetDuration() int { return v.Duration } func StructOption( client graphql.Client, ) (*StructOptionResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "StructOption", Query: ` query StructOption { diff --git a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go index efd07c7e..ba8d8e64 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go @@ -40,7 +40,7 @@ func (v *TypeNameQueryUser) GetId() testutil.ID { return v.Id } func TypeNameQuery( client graphql.Client, ) (*TypeNameQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "TypeNameQuery", Query: ` query TypeNameQuery { diff --git a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go index 9e8cac34..fc35a5d8 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go @@ -267,7 +267,7 @@ func (v *User) GetName() string { return v.Name } func TypeNames( client graphql.Client, ) (*Resp, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "TypeNames", Query: ` query TypeNames { diff --git a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go index 5c6868d5..44d17710 100644 --- a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go @@ -177,7 +177,7 @@ func (v *UnionNoFragmentsQueryResponse) __premarshalJSON() (*__premarshalUnionNo func UnionNoFragmentsQuery( client graphql.Client, ) (*UnionNoFragmentsQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "UnionNoFragmentsQuery", Query: ` query UnionNoFragmentsQuery { diff --git a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go index 324232a5..8cbc3bdd 100644 --- a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go @@ -65,7 +65,7 @@ func (v *UsesEnumTwiceQueryResponse) GetOtherUser() UsesEnumTwiceQueryOtherUser func UsesEnumTwiceQuery( client graphql.Client, ) (*UsesEnumTwiceQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "UsesEnumTwiceQuery", Query: ` query UsesEnumTwiceQuery { diff --git a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go index a4fdb723..d26881bd 100644 --- a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go @@ -181,7 +181,7 @@ func unexported( client graphql.Client, query UserQueryInput, ) (*unexportedResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "unexported", Query: ` query unexported ($query: UserQueryInput) { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go index bec4045d..8cea8275 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go @@ -38,7 +38,7 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( ctx context.Context, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go index d76501d1..485e0b74 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go @@ -41,7 +41,7 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( ctx testutil.MyContext, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go index da22afb4..602ac866 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go @@ -34,7 +34,7 @@ type SimpleQueryUser struct { func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery() (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go index df3597a2..7a345af2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go @@ -42,7 +42,7 @@ func SimpleQuery( ctx testutil.MyContext, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go index 6aaf238e..035ca9e8 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go index 6aaf238e..035ca9e8 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go index f7eaa8f3..3246165d 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go index 9d62c480..b689d31b 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go @@ -35,7 +35,7 @@ func (v *SimpleQueryUser) GetId() string { return v.Id } func SimpleQuery( client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go index 48d86cc9..e88ab2c2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { 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 f0bfaf97..85356e26 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { 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 48d86cc9..e88ab2c2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { 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 48d86cc9..e88ab2c2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go @@ -38,7 +38,7 @@ func SimpleQuery( ctx context.Context, client graphql.Client, ) (*SimpleQueryResponse, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "SimpleQuery", Query: ` query SimpleQuery { diff --git a/graphql/client.go b/graphql/client.go index a2233147..1d9486ee 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -40,7 +40,7 @@ type Client interface { // (Errors are returned.) But again, MakeRequest may customize this. MakeRequest( ctx context.Context, - req *Payload, + req *Request, resp *Response, ) error } @@ -74,9 +74,9 @@ type Doer interface { Do(*http.Request) (*http.Response, error) } -// Payload contains all the values required to build queries executed by +// Request contains all the values required to build queries executed by // the graphql.Client. -type Payload struct { +type Request struct { Query string `json:"query"` Variables interface{} `json:"variables,omitempty"` // OpName is only required if there are multiple queries in the document, @@ -92,7 +92,7 @@ type Response struct { Errors gqlerror.List `json:"errors,omitempty"` } -func (c *client) MakeRequest(ctx context.Context, req *Payload, resp *Response) error { +func (c *client) MakeRequest(ctx context.Context, req *Request, resp *Response) error { body, err := json.Marshal(req) if err != nil { return err diff --git a/internal/integration/generated.go b/internal/integration/generated.go index 006a8a4c..08593b2b 100644 --- a/internal/integration/generated.go +++ b/internal/integration/generated.go @@ -3047,7 +3047,7 @@ func failingQuery( ctx context.Context, client graphql.Client, ) (*failingQueryResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "failingQuery", Query: ` query failingQuery { @@ -3079,7 +3079,7 @@ func queryWithCustomMarshal( client graphql.Client, date time.Time, ) (*queryWithCustomMarshalResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithCustomMarshal", Query: ` query queryWithCustomMarshal ($date: Date!) { @@ -3116,7 +3116,7 @@ func queryWithCustomMarshalOptional( date *time.Time, id *string, ) (*queryWithCustomMarshalOptionalResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithCustomMarshalOptional", Query: ` query queryWithCustomMarshalOptional ($date: Date, $id: ID) { @@ -3153,7 +3153,7 @@ func queryWithCustomMarshalSlice( client graphql.Client, dates []time.Time, ) (*queryWithCustomMarshalSliceResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithCustomMarshalSlice", Query: ` query queryWithCustomMarshalSlice ($dates: [Date!]!) { @@ -3189,7 +3189,7 @@ func queryWithFlatten( client graphql.Client, ids []string, ) (*QueryFragment, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithFlatten", Query: ` query queryWithFlatten ($ids: [ID!]!) { @@ -3259,7 +3259,7 @@ func queryWithFragments( client graphql.Client, ids []string, ) (*queryWithFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithFragments", Query: ` query queryWithFragments ($ids: [ID!]!) { @@ -3323,7 +3323,7 @@ func queryWithInterfaceListField( client graphql.Client, ids []string, ) (*queryWithInterfaceListFieldResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithInterfaceListField", Query: ` query queryWithInterfaceListField ($ids: [ID!]!) { @@ -3359,7 +3359,7 @@ func queryWithInterfaceListPointerField( client graphql.Client, ids []string, ) (*queryWithInterfaceListPointerFieldResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithInterfaceListPointerField", Query: ` query queryWithInterfaceListPointerField ($ids: [ID!]!) { @@ -3395,7 +3395,7 @@ func queryWithInterfaceNoFragments( client graphql.Client, id string, ) (*queryWithInterfaceNoFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithInterfaceNoFragments", Query: ` query queryWithInterfaceNoFragments ($id: ID!) { @@ -3435,7 +3435,7 @@ func queryWithNamedFragments( client graphql.Client, ids []string, ) (*queryWithNamedFragmentsResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithNamedFragments", Query: ` query queryWithNamedFragments ($ids: [ID!]!) { @@ -3499,7 +3499,7 @@ func queryWithOmitempty( client graphql.Client, id string, ) (*queryWithOmitemptyResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithOmitempty", Query: ` query queryWithOmitempty ($id: ID) { @@ -3535,7 +3535,7 @@ func queryWithVariables( client graphql.Client, id string, ) (*queryWithVariablesResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "queryWithVariables", Query: ` query queryWithVariables ($id: ID!) { @@ -3570,7 +3570,7 @@ func simpleQuery( ctx context.Context, client graphql.Client, ) (*simpleQueryResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "simpleQuery", Query: ` query simpleQuery { @@ -3602,7 +3602,7 @@ func simpleQueryExt( ctx context.Context, client graphql.Client, ) (*simpleQueryExtResponse, map[string]interface{}, error) { - req := &graphql.Payload{ + req := &graphql.Request{ OpName: "simpleQueryExt", Query: ` query simpleQueryExt { diff --git a/internal/integration/roundtrip.go b/internal/integration/roundtrip.go index 583b4441..4653b18e 100644 --- a/internal/integration/roundtrip.go +++ b/internal/integration/roundtrip.go @@ -88,7 +88,7 @@ func (c *roundtripClient) roundtripResponse(resp interface{}) { assert.Equal(c.t, string(body), string(bodyAgain)) } -func (c *roundtripClient) MakeRequest(ctx context.Context, req *graphql.Payload, resp *graphql.Response) error { +func (c *roundtripClient) MakeRequest(ctx context.Context, req *graphql.Request, resp *graphql.Response) error { // TODO(benkraft): Also check the variables round-trip. This is a bit less // important since most of the code is the same (and input types are // strictly simpler), and a bit hard to do because when asserting about From 5e47208da0e7cb6e5cc8a77f77538a794dac9bc1 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Wed, 30 Mar 2022 16:25:28 +0200 Subject: [PATCH 4/9] Hold reference to avoid casting Remove not more required comment regarding naming collision --- example/generated.go | 16 +-- generate/operation.go.tmpl | 14 +-- ....graphql-ComplexInlineFragments.graphql.go | 8 +- ...s.graphql-ComplexNamedFragments.graphql.go | 8 +- ...omMarshal.graphql-CustomMarshal.graphql.go | 8 +- ...lice.graphql-CustomMarshalSlice.graphql.go | 8 +- ...erate-DateTime.graphql-DateTime.graphql.go | 8 +- ...nterface.graphql-EmptyInterface.graphql.go | 8 +- ...enerate-Flatten.graphql-Flatten.graphql.go | 8 +- ...ate-InputEnum.graphql-InputEnum.graphql.go | 8 +- ...InputObject.graphql-InputObject.graphql.go | 8 +- ...ield.graphql-InterfaceListField.graphql.go | 8 +- ...nterfaceListOfListsOfListsField.graphql.go | 8 +- ...esting.graphql-InterfaceNesting.graphql.go | 8 +- ...ts.graphql-InterfaceNoFragments.graphql.go | 8 +- ...ate-ListInput.graphql-ListInput.graphql.go | 8 +- ...ists.graphql-ListOfListsOfLists.graphql.go | 8 +- ...ives.graphql-MultipleDirectives.graphql.go | 8 +- ...ate-Omitempty.graphql-Omitempty.graphql.go | 8 +- ...erate-Pointers.graphql-Pointers.graphql.go | 8 +- ...rsInline.graphql-PointersInline.graphql.go | 8 +- ...enerate-Pokemon.graphql-Pokemon.graphql.go | 8 +- ...ithAlias.graphql-QueryWithAlias.graphql.go | 8 +- ...as.graphql-QueryWithDoubleAlias.graphql.go | 8 +- ...ithEnums.graphql-QueryWithEnums.graphql.go | 8 +- ...hSlices.graphql-QueryWithSlices.graphql.go | 8 +- ...tructs.graphql-QueryWithStructs.graphql.go | 8 +- ...ate-Recursion.graphql-Recursion.graphql.go | 8 +- ...nt.graphql-SimpleInlineFragment.graphql.go | 8 +- ...SimpleInput.graphql-SimpleInput.graphql.go | 8 +- ...Mutation.graphql-SimpleMutation.graphql.go | 8 +- ...ent.graphql-SimpleNamedFragment.graphql.go | 8 +- ...SimpleQuery.graphql-SimpleQuery.graphql.go | 8 +- ...ructOption.graphql-StructOption.graphql.go | 8 +- ...erate-TypeName.graphql-TypeName.graphql.go | 8 +- ...ate-TypeNames.graphql-TypeNames.graphql.go | 8 +- ...gments.graphql-UnionNoFragments.graphql.go | 8 +- ...EnumTwice.graphql-UsesEnumTwice.graphql.go | 8 +- ...e-unexported.graphql-unexported.graphql.go | 8 +- ...ClientGetter-testdata-queries-generated.go | 8 +- ...ustomContext-testdata-queries-generated.go | 8 +- ...terNoContext-testdata-queries-generated.go | 8 +- ...ustomContext-testdata-queries-generated.go | 8 +- ...efaultConfig-testdata-queries-generated.go | 8 +- ...rtOperations-testdata-queries-generated.go | 8 +- ...g-Extensions-testdata-queries-generated.go | 8 +- ...ig-NoContext-testdata-queries-generated.go | 8 +- ...fig-PackageName-testdata-queries-myfile.go | 8 +- ...s-testdata-queries-generated-structrefs.go | 8 +- ...ubpackage-testdata-queries-mypkg-myfile.go | 8 +- ...ageConfig-testdata-queries-mypkg-myfile.go | 8 +- internal/integration/generated.go | 112 +++++++----------- 52 files changed, 199 insertions(+), 335 deletions(-) diff --git a/example/generated.go b/example/generated.go index 301b3847..72ce68e8 100644 --- a/example/generated.go +++ b/example/generated.go @@ -91,9 +91,8 @@ query getUser ($Login: String!) { } var err error - resp := &graphql.Response{ - Data: &getUserResponse{}, - } + var data getUserResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -101,8 +100,7 @@ query getUser ($Login: String!) { resp, ) - retval := resp.Data.(*getUserResponse) - return retval, err + return &data, err } func getViewer( @@ -122,9 +120,8 @@ query getViewer { } var err error - resp := &graphql.Response{ - Data: &getViewerResponse{}, - } + var data getViewerResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -132,6 +129,5 @@ query getViewer { resp, ) - retval := resp.Data.(*getViewerResponse) - return retval, err + return &data, err } diff --git a/generate/operation.go.tmpl b/generate/operation.go.tmpl index 9126e68b..b379e9fb 100644 --- a/generate/operation.go.tmpl +++ b/generate/operation.go.tmpl @@ -17,10 +17,6 @@ func {{.Name}}( OpName: "{{.Name}}", Query: `{{.Body}}`, {{if .Input -}} - {{/* We need to avoid conflicting with any of the function's argument names - which are derived from the GraphQL argument names; notably `input` is - a common one. So we use a name that's not legal in GraphQL, namely - one starting with a double-underscore. */ -}} Variables: &{{.Input.GoName}}{ {{range .Input.Fields -}} {{.GoName}}: {{.GraphQLName}}, @@ -37,16 +33,14 @@ func {{.Name}}( return nil, {{if .Config.Extensions -}}nil,{{end -}} err } {{end}} - resp := &graphql.Response{ - Data: &{{.ResponseName}}{}, - } + var data {{.ResponseName}} + resp := &graphql.Response{Data: &data} err = client.MakeRequest( {{if ne .Config.ContextType "-"}}ctx{{else}}nil{{end}}, req, resp, ) - - retval := resp.Data.(*{{.ResponseName}}) - return retval, {{if .Config.Extensions -}}resp.Extensions,{{end -}} err + + return &data, {{if .Config.Extensions -}}resp.Extensions,{{end -}} err } diff --git a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go index 22440799..d514e912 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexInlineFragments.graphql-ComplexInlineFragments.graphql.go @@ -1440,9 +1440,8 @@ query ComplexInlineFragments { } var err error - resp := &graphql.Response{ - Data: &ComplexInlineFragmentsResponse{}, - } + var data ComplexInlineFragmentsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -1450,7 +1449,6 @@ query ComplexInlineFragments { resp, ) - retval := resp.Data.(*ComplexInlineFragmentsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go index 93b39ca8..15603b28 100644 --- a/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ComplexNamedFragments.graphql-ComplexNamedFragments.graphql.go @@ -1806,9 +1806,8 @@ fragment MoreVideoFields on Video { } var err error - resp := &graphql.Response{ - Data: &ComplexNamedFragmentsResponse{}, - } + var data ComplexNamedFragmentsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -1816,7 +1815,6 @@ fragment MoreVideoFields on Video { resp, ) - retval := resp.Data.(*ComplexNamedFragmentsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go index a777fcb1..004d9db1 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshal.graphql-CustomMarshal.graphql.go @@ -194,9 +194,8 @@ query CustomMarshal ($date: Date!) { } var err error - resp := &graphql.Response{ - Data: &CustomMarshalResponse{}, - } + var data CustomMarshalResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -204,7 +203,6 @@ query CustomMarshal ($date: Date!) { resp, ) - retval := resp.Data.(*CustomMarshalResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go index 529f0402..26e2b700 100644 --- a/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-CustomMarshalSlice.graphql-CustomMarshalSlice.graphql.go @@ -223,9 +223,8 @@ query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { } var err error - resp := &graphql.Response{ - Data: &CustomMarshalSliceResponse{}, - } + var data CustomMarshalSliceResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -233,7 +232,6 @@ query CustomMarshalSlice ($datesss: [[[Date!]!]!]!, $datesssp: [[[Date!]!]!]!) { resp, ) - retval := resp.Data.(*CustomMarshalSliceResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go index cd243589..94e069d1 100644 --- a/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-DateTime.graphql-DateTime.graphql.go @@ -47,9 +47,8 @@ query convertTimezone ($dt: DateTime!, $tz: String) { } var err error - resp := &graphql.Response{ - Data: &convertTimezoneResponse{}, - } + var data convertTimezoneResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -57,7 +56,6 @@ query convertTimezone ($dt: DateTime!, $tz: String) { resp, ) - retval := resp.Data.(*convertTimezoneResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go index 89a575cd..0b302932 100644 --- a/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-EmptyInterface.graphql-EmptyInterface.graphql.go @@ -34,9 +34,8 @@ query EmptyInterface { } var err error - resp := &graphql.Response{ - Data: &EmptyInterfaceResponse{}, - } + var data EmptyInterfaceResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -44,7 +43,6 @@ query EmptyInterface { resp, ) - retval := resp.Data.(*EmptyInterfaceResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go index 1db1d545..b22e2709 100644 --- a/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go @@ -310,9 +310,8 @@ fragment ChildVideoFields on Video { } var err error - resp := &graphql.Response{ - Data: &InnerQueryFragment{}, - } + var data InnerQueryFragment + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -320,7 +319,6 @@ fragment ChildVideoFields on Video { resp, ) - retval := resp.Data.(*InnerQueryFragment) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go index 3bccd3c1..b1f28d81 100644 --- a/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputEnum.graphql-InputEnum.graphql.go @@ -73,9 +73,8 @@ query InputEnumQuery ($role: Role!) { } var err error - resp := &graphql.Response{ - Data: &InputEnumQueryResponse{}, - } + var data InputEnumQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -83,7 +82,6 @@ query InputEnumQuery ($role: Role!) { resp, ) - retval := resp.Data.(*InputEnumQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go index 920de9d9..09be3f3f 100644 --- a/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.graphql.go @@ -196,9 +196,8 @@ query InputObjectQuery ($query: UserQueryInput) { } var err error - resp := &graphql.Response{ - Data: &InputObjectQueryResponse{}, - } + var data InputObjectQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -206,7 +205,6 @@ query InputObjectQuery ($query: UserQueryInput) { resp, ) - retval := resp.Data.(*InputObjectQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go index a85d291f..596f1322 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListField.graphql-InterfaceListField.graphql.go @@ -550,9 +550,8 @@ query InterfaceListField { } var err error - resp := &graphql.Response{ - Data: &InterfaceListFieldResponse{}, - } + var data InterfaceListFieldResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -560,7 +559,6 @@ query InterfaceListField { resp, ) - retval := resp.Data.(*InterfaceListFieldResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go index bc48e9cf..b46922f6 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceListOfListsOfListsField.graphql-InterfaceListOfListsOfListsField.graphql.go @@ -528,9 +528,8 @@ query InterfaceListOfListOfListsField { } var err error - resp := &graphql.Response{ - Data: &InterfaceListOfListOfListsFieldResponse{}, - } + var data InterfaceListOfListOfListsFieldResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -538,7 +537,6 @@ query InterfaceListOfListOfListsField { resp, ) - retval := resp.Data.(*InterfaceListOfListOfListsFieldResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go index 1f19dad9..565302ea 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNesting.graphql-InterfaceNesting.graphql.go @@ -530,9 +530,8 @@ query InterfaceNesting { } var err error - resp := &graphql.Response{ - Data: &InterfaceNestingResponse{}, - } + var data InterfaceNestingResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -540,7 +539,6 @@ query InterfaceNesting { resp, ) - retval := resp.Data.(*InterfaceNestingResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go index 65d2e164..4fce0d23 100644 --- a/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-InterfaceNoFragments.graphql-InterfaceNoFragments.graphql.go @@ -657,9 +657,8 @@ query InterfaceNoFragmentsQuery { } var err error - resp := &graphql.Response{ - Data: &InterfaceNoFragmentsQueryResponse{}, - } + var data InterfaceNoFragmentsQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -667,7 +666,6 @@ query InterfaceNoFragmentsQuery { resp, ) - retval := resp.Data.(*InterfaceNoFragmentsQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go index 387de625..818104a7 100644 --- a/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListInput.graphql-ListInput.graphql.go @@ -60,9 +60,8 @@ query ListInputQuery ($names: [String]) { } var err error - resp := &graphql.Response{ - Data: &ListInputQueryResponse{}, - } + var data ListInputQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -70,7 +69,6 @@ query ListInputQuery ($names: [String]) { resp, ) - retval := resp.Data.(*ListInputQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go index a1e30863..b77ff404 100644 --- a/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-ListOfListsOfLists.graphql-ListOfListsOfLists.graphql.go @@ -29,9 +29,8 @@ query ListOfListsOfLists { } var err error - resp := &graphql.Response{ - Data: &ListOfListsOfListsResponse{}, - } + var data ListOfListsOfListsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -39,7 +38,6 @@ query ListOfListsOfLists { resp, ) - retval := resp.Data.(*ListOfListsOfListsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go index c4ad14de..78cb7b76 100644 --- a/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.graphql.go @@ -349,9 +349,8 @@ query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { } var err error - resp := &graphql.Response{ - Data: &MyMultipleDirectivesResponse{}, - } + var data MyMultipleDirectivesResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -359,7 +358,6 @@ query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { resp, ) - retval := resp.Data.(*MyMultipleDirectivesResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go index b04eaf3d..ba0a9efd 100644 --- a/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.graphql.go @@ -251,9 +251,8 @@ query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: D } var err error - resp := &graphql.Response{ - Data: &OmitEmptyQueryResponse{}, - } + var data OmitEmptyQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -261,7 +260,6 @@ query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: D resp, ) - retval := resp.Data.(*OmitEmptyQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go index 8285c95d..12e0e9e3 100644 --- a/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pointers.graphql-Pointers.graphql.go @@ -261,9 +261,8 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { } var err error - resp := &graphql.Response{ - Data: &PointersQueryResponse{}, - } + var data PointersQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -271,7 +270,6 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { resp, ) - retval := resp.Data.(*PointersQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go index b2921e7d..996202cf 100644 --- a/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-PointersInline.graphql-PointersInline.graphql.go @@ -258,9 +258,8 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { } var err error - resp := &graphql.Response{ - Data: &PointersQueryResponse{}, - } + var data PointersQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -268,7 +267,6 @@ query PointersQuery ($query: UserQueryInput, $dt: DateTime, $tz: String) { resp, ) - retval := resp.Data.(*PointersQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go index d34529fc..749e8796 100644 --- a/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Pokemon.graphql-Pokemon.graphql.go @@ -100,9 +100,8 @@ query GetPokemonSiblings ($input: PokemonInput!) { } var err error - resp := &graphql.Response{ - Data: &GetPokemonSiblingsResponse{}, - } + var data GetPokemonSiblingsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -110,7 +109,6 @@ query GetPokemonSiblings ($input: PokemonInput!) { resp, ) - retval := resp.Data.(*GetPokemonSiblingsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go index a26c6732..784bbb32 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithAlias.graphql-QueryWithAlias.graphql.go @@ -56,9 +56,8 @@ query QueryWithAlias { } var err error - resp := &graphql.Response{ - Data: &QueryWithAliasResponse{}, - } + var data QueryWithAliasResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -66,7 +65,6 @@ query QueryWithAlias { resp, ) - retval := resp.Data.(*QueryWithAliasResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go index 795941e1..6e2213ac 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithDoubleAlias.graphql-QueryWithDoubleAlias.graphql.go @@ -56,9 +56,8 @@ query QueryWithDoubleAlias { } var err error - resp := &graphql.Response{ - Data: &QueryWithDoubleAliasResponse{}, - } + var data QueryWithDoubleAliasResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -66,7 +65,6 @@ query QueryWithDoubleAlias { resp, ) - retval := resp.Data.(*QueryWithDoubleAliasResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go index 791cda21..52f51996 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithEnums.graphql-QueryWithEnums.graphql.go @@ -80,9 +80,8 @@ query QueryWithEnums { } var err error - resp := &graphql.Response{ - Data: &QueryWithEnumsResponse{}, - } + var data QueryWithEnumsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -90,7 +89,6 @@ query QueryWithEnums { resp, ) - retval := resp.Data.(*QueryWithEnumsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go index 16b11665..e7347faf 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithSlices.graphql-QueryWithSlices.graphql.go @@ -59,9 +59,8 @@ query QueryWithSlices { } var err error - resp := &graphql.Response{ - Data: &QueryWithSlicesResponse{}, - } + var data QueryWithSlicesResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -69,7 +68,6 @@ query QueryWithSlices { resp, ) - retval := resp.Data.(*QueryWithSlicesResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go index 4fb2b47e..63ac7fbf 100644 --- a/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-QueryWithStructs.graphql-QueryWithStructs.graphql.go @@ -61,9 +61,8 @@ query QueryWithStructs { } var err error - resp := &graphql.Response{ - Data: &QueryWithStructsResponse{}, - } + var data QueryWithStructsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -71,7 +70,6 @@ query QueryWithStructs { resp, ) - retval := resp.Data.(*QueryWithStructsResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go index 61eafc1f..b8cab24c 100644 --- a/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-Recursion.graphql-Recursion.graphql.go @@ -93,9 +93,8 @@ query Recursion ($input: RecursiveInput!) { } var err error - resp := &graphql.Response{ - Data: &RecursionResponse{}, - } + var data RecursionResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -103,7 +102,6 @@ query Recursion ($input: RecursiveInput!) { resp, ) - retval := resp.Data.(*RecursionResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go index a21e7f41..b63971fc 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.graphql.go @@ -262,9 +262,8 @@ query SimpleInlineFragment { } var err error - resp := &graphql.Response{ - Data: &SimpleInlineFragmentResponse{}, - } + var data SimpleInlineFragmentResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -272,7 +271,6 @@ query SimpleInlineFragment { resp, ) - retval := resp.Data.(*SimpleInlineFragmentResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go index 20d13207..7fe46d49 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleInput.graphql-SimpleInput.graphql.go @@ -60,9 +60,8 @@ query SimpleInputQuery ($name: String!) { } var err error - resp := &graphql.Response{ - Data: &SimpleInputQueryResponse{}, - } + var data SimpleInputQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -70,7 +69,6 @@ query SimpleInputQuery ($name: String!) { resp, ) - retval := resp.Data.(*SimpleInputQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go index 283a8a53..15a13fb8 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleMutation.graphql-SimpleMutation.graphql.go @@ -65,9 +65,8 @@ mutation SimpleMutation ($name: String!) { } var err error - resp := &graphql.Response{ - Data: &SimpleMutationResponse{}, - } + var data SimpleMutationResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -75,7 +74,6 @@ mutation SimpleMutation ($name: String!) { resp, ) - retval := resp.Data.(*SimpleMutationResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go index 175c50a9..dbfc0626 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go @@ -577,9 +577,8 @@ fragment VideoFields on Video { } var err error - resp := &graphql.Response{ - Data: &SimpleNamedFragmentResponse{}, - } + var data SimpleNamedFragmentResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -587,7 +586,6 @@ fragment VideoFields on Video { resp, ) - retval := resp.Data.(*SimpleNamedFragmentResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go index 589a50a3..645e1115 100644 --- a/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-SimpleQuery.graphql-SimpleQuery.graphql.go @@ -48,9 +48,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -58,7 +57,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go index de07f933..fdec034d 100644 --- a/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go @@ -461,9 +461,8 @@ fragment VideoFields on Video { } var err error - resp := &graphql.Response{ - Data: &StructOptionResponse{}, - } + var data StructOptionResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -471,7 +470,6 @@ fragment VideoFields on Video { resp, ) - retval := resp.Data.(*StructOptionResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go index ba8d8e64..899cc2da 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeName.graphql-TypeName.graphql.go @@ -53,9 +53,8 @@ query TypeNameQuery { } var err error - resp := &graphql.Response{ - Data: &TypeNameQueryResponse{}, - } + var data TypeNameQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -63,7 +62,6 @@ query TypeNameQuery { resp, ) - retval := resp.Data.(*TypeNameQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go index fc35a5d8..9ee556a3 100644 --- a/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-TypeNames.graphql-TypeNames.graphql.go @@ -289,9 +289,8 @@ query TypeNames { } var err error - resp := &graphql.Response{ - Data: &Resp{}, - } + var data Resp + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -299,7 +298,6 @@ query TypeNames { resp, ) - retval := resp.Data.(*Resp) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go index 44d17710..195a6010 100644 --- a/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UnionNoFragments.graphql-UnionNoFragments.graphql.go @@ -189,9 +189,8 @@ query UnionNoFragmentsQuery { } var err error - resp := &graphql.Response{ - Data: &UnionNoFragmentsQueryResponse{}, - } + var data UnionNoFragmentsQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -199,7 +198,6 @@ query UnionNoFragmentsQuery { resp, ) - retval := resp.Data.(*UnionNoFragmentsQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go index 8cbc3bdd..06b39fe6 100644 --- a/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-UsesEnumTwice.graphql-UsesEnumTwice.graphql.go @@ -80,9 +80,8 @@ query UsesEnumTwiceQuery { } var err error - resp := &graphql.Response{ - Data: &UsesEnumTwiceQueryResponse{}, - } + var data UsesEnumTwiceQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -90,7 +89,6 @@ query UsesEnumTwiceQuery { resp, ) - retval := resp.Data.(*UsesEnumTwiceQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go index d26881bd..8aabfa6b 100644 --- a/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go +++ b/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go @@ -196,9 +196,8 @@ query unexported ($query: UserQueryInput) { } var err error - resp := &graphql.Response{ - Data: &unexportedResponse{}, - } + var data unexportedResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -206,7 +205,6 @@ query unexported ($query: UserQueryInput) { resp, ) - retval := resp.Data.(*unexportedResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go index 8cea8275..d5ac56db 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetter-testdata-queries-generated.go @@ -56,9 +56,8 @@ query SimpleQuery { return nil, err } - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -66,7 +65,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go index 485e0b74..61b5518f 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterCustomContext-testdata-queries-generated.go @@ -59,9 +59,8 @@ query SimpleQuery { return nil, err } - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -69,7 +68,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go index 602ac866..e35911a6 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ClientGetterNoContext-testdata-queries-generated.go @@ -52,9 +52,8 @@ query SimpleQuery { return nil, err } - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -62,7 +61,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go index 7a345af2..790ecb8d 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-CustomContext-testdata-queries-generated.go @@ -54,9 +54,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -64,7 +63,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go index 035ca9e8..bb9d5d5d 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-DefaultConfig-testdata-queries-generated.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go index 035ca9e8..bb9d5d5d 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-ExportOperations-testdata-queries-generated.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go index 3246165d..691c2ba4 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Extensions-testdata-queries-generated.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go index b689d31b..5318ac79 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-NoContext-testdata-queries-generated.go @@ -47,9 +47,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( nil, @@ -57,7 +56,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go index e88ab2c2..d6dea59b 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-PackageName-testdata-queries-myfile.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } 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 85356e26..31993fd2 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-StructReferences-testdata-queries-generated-structrefs.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } 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 e88ab2c2..d6dea59b 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-Subpackage-testdata-queries-mypkg-myfile.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } 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 e88ab2c2..d6dea59b 100644 --- a/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go +++ b/generate/testdata/snapshots/TestGenerateWithConfig-SubpackageConfig-testdata-queries-mypkg-myfile.go @@ -50,9 +50,8 @@ query SimpleQuery { } var err error - resp := &graphql.Response{ - Data: &SimpleQueryResponse{}, - } + var data SimpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -60,7 +59,6 @@ query SimpleQuery { resp, ) - retval := resp.Data.(*SimpleQueryResponse) - return retval, err + return &data, err } diff --git a/internal/integration/generated.go b/internal/integration/generated.go index 08593b2b..8ebe975d 100644 --- a/internal/integration/generated.go +++ b/internal/integration/generated.go @@ -3060,9 +3060,8 @@ query failingQuery { } var err error - resp := &graphql.Response{ - Data: &failingQueryResponse{}, - } + var data failingQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3070,8 +3069,7 @@ query failingQuery { resp, ) - retval := resp.Data.(*failingQueryResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithCustomMarshal( @@ -3096,9 +3094,8 @@ query queryWithCustomMarshal ($date: Date!) { } var err error - resp := &graphql.Response{ - Data: &queryWithCustomMarshalResponse{}, - } + var data queryWithCustomMarshalResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3106,8 +3103,7 @@ query queryWithCustomMarshal ($date: Date!) { resp, ) - retval := resp.Data.(*queryWithCustomMarshalResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithCustomMarshalOptional( @@ -3134,9 +3130,8 @@ query queryWithCustomMarshalOptional ($date: Date, $id: ID) { } var err error - resp := &graphql.Response{ - Data: &queryWithCustomMarshalOptionalResponse{}, - } + var data queryWithCustomMarshalOptionalResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3144,8 +3139,7 @@ query queryWithCustomMarshalOptional ($date: Date, $id: ID) { resp, ) - retval := resp.Data.(*queryWithCustomMarshalOptionalResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithCustomMarshalSlice( @@ -3170,9 +3164,8 @@ query queryWithCustomMarshalSlice ($dates: [Date!]!) { } var err error - resp := &graphql.Response{ - Data: &queryWithCustomMarshalSliceResponse{}, - } + var data queryWithCustomMarshalSliceResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3180,8 +3173,7 @@ query queryWithCustomMarshalSlice ($dates: [Date!]!) { resp, ) - retval := resp.Data.(*queryWithCustomMarshalSliceResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithFlatten( @@ -3240,9 +3232,8 @@ fragment FriendsFields on User { } var err error - resp := &graphql.Response{ - Data: &QueryFragment{}, - } + var data QueryFragment + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3250,8 +3241,7 @@ fragment FriendsFields on User { resp, ) - retval := resp.Data.(*QueryFragment) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithFragments( @@ -3304,9 +3294,8 @@ query queryWithFragments ($ids: [ID!]!) { } var err error - resp := &graphql.Response{ - Data: &queryWithFragmentsResponse{}, - } + var data queryWithFragmentsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3314,8 +3303,7 @@ query queryWithFragments ($ids: [ID!]!) { resp, ) - retval := resp.Data.(*queryWithFragmentsResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithInterfaceListField( @@ -3340,9 +3328,8 @@ query queryWithInterfaceListField ($ids: [ID!]!) { } var err error - resp := &graphql.Response{ - Data: &queryWithInterfaceListFieldResponse{}, - } + var data queryWithInterfaceListFieldResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3350,8 +3337,7 @@ query queryWithInterfaceListField ($ids: [ID!]!) { resp, ) - retval := resp.Data.(*queryWithInterfaceListFieldResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithInterfaceListPointerField( @@ -3376,9 +3362,8 @@ query queryWithInterfaceListPointerField ($ids: [ID!]!) { } var err error - resp := &graphql.Response{ - Data: &queryWithInterfaceListPointerFieldResponse{}, - } + var data queryWithInterfaceListPointerFieldResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3386,8 +3371,7 @@ query queryWithInterfaceListPointerField ($ids: [ID!]!) { resp, ) - retval := resp.Data.(*queryWithInterfaceListPointerFieldResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithInterfaceNoFragments( @@ -3416,9 +3400,8 @@ query queryWithInterfaceNoFragments ($id: ID!) { } var err error - resp := &graphql.Response{ - Data: &queryWithInterfaceNoFragmentsResponse{}, - } + var data queryWithInterfaceNoFragmentsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3426,8 +3409,7 @@ query queryWithInterfaceNoFragments ($id: ID!) { resp, ) - retval := resp.Data.(*queryWithInterfaceNoFragmentsResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithNamedFragments( @@ -3480,9 +3462,8 @@ fragment MoreUserFields on User { } var err error - resp := &graphql.Response{ - Data: &queryWithNamedFragmentsResponse{}, - } + var data queryWithNamedFragmentsResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3490,8 +3471,7 @@ fragment MoreUserFields on User { resp, ) - retval := resp.Data.(*queryWithNamedFragmentsResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithOmitempty( @@ -3516,9 +3496,8 @@ query queryWithOmitempty ($id: ID) { } var err error - resp := &graphql.Response{ - Data: &queryWithOmitemptyResponse{}, - } + var data queryWithOmitemptyResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3526,8 +3505,7 @@ query queryWithOmitempty ($id: ID) { resp, ) - retval := resp.Data.(*queryWithOmitemptyResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func queryWithVariables( @@ -3552,9 +3530,8 @@ query queryWithVariables ($id: ID!) { } var err error - resp := &graphql.Response{ - Data: &queryWithVariablesResponse{}, - } + var data queryWithVariablesResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3562,8 +3539,7 @@ query queryWithVariables ($id: ID!) { resp, ) - retval := resp.Data.(*queryWithVariablesResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func simpleQuery( @@ -3584,9 +3560,8 @@ query simpleQuery { } var err error - resp := &graphql.Response{ - Data: &simpleQueryResponse{}, - } + var data simpleQueryResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3594,8 +3569,7 @@ query simpleQuery { resp, ) - retval := resp.Data.(*simpleQueryResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } func simpleQueryExt( @@ -3616,9 +3590,8 @@ query simpleQueryExt { } var err error - resp := &graphql.Response{ - Data: &simpleQueryExtResponse{}, - } + var data simpleQueryExtResponse + resp := &graphql.Response{Data: &data} err = client.MakeRequest( ctx, @@ -3626,6 +3599,5 @@ query simpleQueryExt { resp, ) - retval := resp.Data.(*simpleQueryExtResponse) - return retval, resp.Extensions, err + return &data, resp.Extensions, err } From 5d884cb1d8a3754a1410b2bf954d176b5ff7a26f Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Wed, 30 Mar 2022 16:54:30 +0200 Subject: [PATCH 5/9] Update interface documentation --- graphql/client.go | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/graphql/client.go b/graphql/client.go index 1d9486ee..d9368ad4 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -23,21 +23,18 @@ type Client interface { // is disabled in the genqlient settings, this will be set to // context.Background(). // - // query is the literal string representing the GraphQL query, e.g. - // `query myQuery { myField }`. variables contains a JSON-marshalable - // value containing the variables to be sent along with the query, - // or may be nil if there are none. Typically, GraphQL APIs will - // accept a JSON payload of the form - // {"query": "query myQuery { ... }", "variables": {...}}` - // but MakeRequest may use some other transport, handle extensions, or set - // other parameters, if it wishes. + // req is the Request object that should be sent to the GraphQL server. + // MakeRequest is marshalling this into a byte sequence readable by + // the API server. // - // retval is a pointer to the struct representing the query result, e.g. - // new(myQueryResponse). Typically, GraphQL APIs will return a JSON - // payload of the form - // {"data": {...}, "errors": {...}} - // and retval is designed so that `data` will json-unmarshal into `retval`. - // (Errors are returned.) But again, MakeRequest may customize this. + // resp is the Response object that will be used to store the returned + // data to. MakeRequest will try to unmarshal the data returend by the GraphQL + // server. Thus it is expected, that you set the Data field to your expected + // Datatype. example: + // var data complexDataStruct + // resp := &graphql.Response{Data: &data} + // In case errors are returned in the response, Makerequest will return these. + // Extensions are added as well, if sent by the server, during regular unmarshalling MakeRequest( ctx context.Context, req *Request, @@ -76,16 +73,28 @@ type Doer interface { // Request contains all the values required to build queries executed by // the graphql.Client. +// +// Query is the literal string representing the GraphQL query, e.g. +// `query myQuery { myField }`. +// Variables contains a JSON-marshalable value containing the variables +// to be sent along with the query, or may be nil if there are none. +// Typically, GraphQL APIs will accept a JSON payload of the form +// {"query": "query myQuery { ... }", "variables": {...}}` +// OpName is only required if there are multiple queries in the document, +// but we set it unconditionally, because that's easier. type Request struct { Query string `json:"query"` Variables interface{} `json:"variables,omitempty"` - // OpName is only required if there are multiple queries in the document, - // but we set it unconditionally, because that's easier. - OpName string `json:"operationName"` + OpName string `json:"operationName"` } -// Response that contains data returned by the GraphQL API. Extensions and -// Errors might not be set, depending on the values returned by the Request. +// Response that contains data returned by the GraphQL API. +// +// Typically, GraphQL APIs will return a JSON payload of the form +// {"data": {...}, "errors": {...}}, additionally it can contain a key +// named "extensions", that might hold GraphQL protocol extensions. +// Extensions and Errors are optional, depending on the values +// returned by the Request. type Response struct { Data interface{} `json:"data"` Extensions map[string]interface{} `json:"extensions,omitempty"` From a47445a4773c336d68982ddb5b109796fcf8b52c Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Boll Date: Wed, 30 Mar 2022 17:07:47 +0200 Subject: [PATCH 6/9] Add changelog entries --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0da5596b..26102637 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -23,10 +23,12 @@ When releasing a new version: ### Breaking changes: - genqlient now requires Go 1.16 or higher. +- Return types of generated functions might change from `data, error` to `data, map[string]interface{}, error` if you enable `use_extensions`. ### New features: - genqlient can now run as a portable binary (i.e. without a local checkout of the repository or `go run`). +- You can now enable `use_extensions` in the configuration file, to receive extensions returned by the GraphQL API server. Generated functions will return Extensions as `map[string]interface{}`, if enabled. ### Bug fixes: From 3394901bed01ab24a4543b1a4d0c7e941bb47bb4 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Wed, 30 Mar 2022 13:34:58 -0700 Subject: [PATCH 7/9] Updates to changelog --- docs/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 26102637..a86884e2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -23,12 +23,12 @@ When releasing a new version: ### Breaking changes: - genqlient now requires Go 1.16 or higher. -- Return types of generated functions might change from `data, error` to `data, map[string]interface{}, error` if you enable `use_extensions`. +- The [`graphql.Client`](https://pkg.go.dev/github.com/Khan/genqlient/graphql#Client) interface now accepts two structs for the request and response, to allow future expansion, rather than several individual arguments. Clients implementing the interface themselves will need to change the signature; clients who simply call `graphql.NewClient` are unaffected. ### New features: - genqlient can now run as a portable binary (i.e. without a local checkout of the repository or `go run`). -- You can now enable `use_extensions` in the configuration file, to receive extensions returned by the GraphQL API server. Generated functions will return Extensions as `map[string]interface{}`, if enabled. +- You can now enable `use_extensions` in the configuration file, to receive extensions returned by the GraphQL API server. Generated functions will return extensions as `map[string]interface{}`, if enabled. ### Bug fixes: From fd75133ed022710782da8e25efc9528ca358bfb6 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Wed, 30 Mar 2022 13:42:58 -0700 Subject: [PATCH 8/9] Tweak client documentation --- graphql/client.go | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/graphql/client.go b/graphql/client.go index d9368ad4..104288bc 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -13,9 +13,6 @@ import ( // Client is the interface that the generated code calls into to actually make // requests. -// -// Unstable: This interface is likely to change before v1.0, see #19. Creating -// a client with NewClient will remain the same. type Client interface { // MakeRequest must make a request to the client's GraphQL API. // @@ -23,18 +20,16 @@ type Client interface { // is disabled in the genqlient settings, this will be set to // context.Background(). // - // req is the Request object that should be sent to the GraphQL server. - // MakeRequest is marshalling this into a byte sequence readable by - // the API server. + // req contains the data to be sent to the GraphQL server. Typically GraphQL + // APIs will expect it to simply be marshalled as JSON, but MakeRequest may + // customize this. // - // resp is the Response object that will be used to store the returned - // data to. MakeRequest will try to unmarshal the data returend by the GraphQL - // server. Thus it is expected, that you set the Data field to your expected - // Datatype. example: - // var data complexDataStruct - // resp := &graphql.Response{Data: &data} - // In case errors are returned in the response, Makerequest will return these. - // Extensions are added as well, if sent by the server, during regular unmarshalling + // resp is the Response object into which the server's response will be + // unmarshalled. Typically GraphQL APIs will return JSON which can be + // unmarshalled directly into resp, but MakeRequest can customize it. + // If the response contains an error, this must also be returned by + // MakeRequest. The field resp.Data will be prepopulated with a pointer + // to an empty struct of the correct generated type (e.g. MyQueryResponse). MakeRequest( ctx context.Context, req *Request, @@ -74,27 +69,30 @@ type Doer interface { // Request contains all the values required to build queries executed by // the graphql.Client. // -// Query is the literal string representing the GraphQL query, e.g. -// `query myQuery { myField }`. -// Variables contains a JSON-marshalable value containing the variables -// to be sent along with the query, or may be nil if there are none. -// Typically, GraphQL APIs will accept a JSON payload of the form +// Typically, GraphQL APIs will accept a JSON payload of the form // {"query": "query myQuery { ... }", "variables": {...}}` -// OpName is only required if there are multiple queries in the document, -// but we set it unconditionally, because that's easier. +// and Request marshals to this format. However, MakeRequest may +// marshal the data in some other way desired by the backend. type Request struct { + // The literal string representing the GraphQL query, e.g. + // `query myQuery { myField }`. Query string `json:"query"` + // A JSON-marshalable value containing the variables to be sent + // along with the query, or nil if there are none. Variables interface{} `json:"variables,omitempty"` + // The GraphQL operation name. The server typically doesn't + // require this unless there are multiple queries in the + // document, but genqlient sets it unconditionally anyway. OpName string `json:"operationName"` } // Response that contains data returned by the GraphQL API. // // Typically, GraphQL APIs will return a JSON payload of the form -// {"data": {...}, "errors": {...}}, additionally it can contain a key -// named "extensions", that might hold GraphQL protocol extensions. -// Extensions and Errors are optional, depending on the values -// returned by the Request. +// {"data": {...}, "errors": {...}} +// It may additionally contain a key named "extensions", that +// might hold GraphQL protocol extensions. Extensions and Errors +// are optional, depending on the values returned by the server. type Response struct { Data interface{} `json:"data"` Extensions map[string]interface{} `json:"extensions,omitempty"` From 3ed2b5a45344329dc824a37d6db86f74ccf4a9f3 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Wed, 30 Mar 2022 13:46:24 -0700 Subject: [PATCH 9/9] Lint --- graphql/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql/client.go b/graphql/client.go index 104288bc..47154702 100644 --- a/graphql/client.go +++ b/graphql/client.go @@ -76,14 +76,14 @@ type Doer interface { type Request struct { // The literal string representing the GraphQL query, e.g. // `query myQuery { myField }`. - Query string `json:"query"` + Query string `json:"query"` // A JSON-marshalable value containing the variables to be sent // along with the query, or nil if there are none. Variables interface{} `json:"variables,omitempty"` // The GraphQL operation name. The server typically doesn't // require this unless there are multiple queries in the // document, but genqlient sets it unconditionally anyway. - OpName string `json:"operationName"` + OpName string `json:"operationName"` } // Response that contains data returned by the GraphQL API.