diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 664a97e..596cc43 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.16' + go-version: '1.21' - name: Lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4109b5..2946921 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - go: [1.16] + go: [1.21] runs-on: ${{ matrix.os }} steps: diff --git a/README.md b/README.md index 40e8de9..a49c524 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Package `graphql` provides a GraphQL client implementation, and is forked from ` Installation ------------ -`graphql` requires Go version 1.16 or later. - ```bash go get -u github.com/cli/shurcooL-graphql ``` @@ -130,7 +128,7 @@ var q struct { Then, define a `variables` map with their values: ```Go -variables := map[string]interface{}{ +variables := map[string]any{ "id": graphql.ID(id), "unit": starwars.LengthUnit("METER"), } @@ -250,7 +248,7 @@ var m struct { Commentary graphql.String } `graphql:"createReview(episode: $ep, review: $review)"` } -variables := map[string]interface{}{ +variables := map[string]any{ "ep": starwars.Episode("JEDI"), "review": starwars.ReviewInput{ Stars: graphql.Int(5), diff --git a/go.mod b/go.mod index 0f583b1..09db548 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/cli/shurcooL-graphql -go 1.16 - -require golang.org/x/net v0.15.0 +go 1.21 diff --git a/go.sum b/go.sum index 10bb1cb..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,40 +0,0 @@ -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/graphql.go b/graphql.go index 3129390..d45cbbb 100644 --- a/graphql.go +++ b/graphql.go @@ -5,18 +5,17 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" "github.com/cli/shurcooL-graphql/internal/jsonutil" - "golang.org/x/net/context/ctxhttp" ) // Client is a GraphQL client. type Client struct { - url string // GraphQL server URL. - httpClient *http.Client + url string // GraphQL server URL. + httpClient *http.Client // Non-nil. } // NewClient creates a GraphQL client targeting the specified GraphQL server URL. @@ -34,29 +33,29 @@ func NewClient(url string, httpClient *http.Client) *Client { // Query executes a single GraphQL query request, // with a query derived from q, populating the response into it. // Argument q should be a pointer to struct that corresponds to the GraphQL schema. -func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error { +func (c *Client) Query(ctx context.Context, q any, variables map[string]any) error { return c.do(ctx, queryOperation, q, variables, "") } // QueryNamed is the same as Query but allows a name to be specified for the query. -func (c *Client) QueryNamed(ctx context.Context, queryName string, q interface{}, variables map[string]interface{}) error { +func (c *Client) QueryNamed(ctx context.Context, queryName string, q any, variables map[string]any) error { return c.do(ctx, queryOperation, q, variables, queryName) } // Mutate executes a single GraphQL mutation request, // with a mutation derived from m, populating the response into it. // Argument m should be a pointer to struct that corresponds to the GraphQL schema. -func (c *Client) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}) error { +func (c *Client) Mutate(ctx context.Context, m any, variables map[string]any) error { return c.do(ctx, mutationOperation, m, variables, "") } // MutateNamed is the same as Mutate but allows a name to be specified for the mutation. -func (c *Client) MutateNamed(ctx context.Context, queryName string, m interface{}, variables map[string]interface{}) error { +func (c *Client) MutateNamed(ctx context.Context, queryName string, m any, variables map[string]any) error { return c.do(ctx, mutationOperation, m, variables, queryName) } // do executes a single GraphQL operation. -func (c *Client) do(ctx context.Context, op operationType, v interface{}, variables map[string]interface{}, queryName string) error { +func (c *Client) do(ctx context.Context, op operationType, v any, variables map[string]any, queryName string) error { var query string switch op { case queryOperation: @@ -65,8 +64,8 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab query = constructMutation(v, variables, queryName) } in := struct { - Query string `json:"query"` - Variables map[string]interface{} `json:"variables,omitempty"` + Query string `json:"query"` + Variables map[string]any `json:"variables,omitempty"` }{ Query: query, Variables: variables, @@ -76,19 +75,24 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab if err != nil { return err } - resp, err := ctxhttp.Post(ctx, c.httpClient, c.url, "application/json", &buf) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url, &buf) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + resp, err := c.httpClient.Do(req) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) return fmt.Errorf("non-200 OK status code: %v body: %q", resp.Status, body) } var out struct { Data *json.RawMessage Errors Errors - //Extensions interface{} // Unused. + //Extensions any // Unused. } err = json.NewDecoder(resp.Body).Decode(&out) if err != nil { @@ -111,15 +115,15 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab // Errors represents the "errors" array in a response from a GraphQL server. // If returned via error interface, the slice is expected to contain at least 1 element. // -// Specification: http://spec.graphql.org/June2018/#sec-Errors +// Specification: https://spec.graphql.org/October2021/#sec-Errors. type Errors []struct { Message string Locations []struct { Line int Column int } - Path []interface{} - Extensions map[string]interface{} + Path []any + Extensions map[string]any Type string } diff --git a/graphql_test.go b/graphql_test.go index 2fb7722..361c17d 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -3,7 +3,6 @@ package graphql_test import ( "context" "io" - "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -144,7 +143,7 @@ func TestClient_Query_emptyVariables(t *testing.T) { Name string } } - err := client.Query(context.Background(), &q, map[string]interface{}{}) + err := client.Query(context.Background(), &q, map[string]any{}) if err != nil { t.Fatal(err) } @@ -166,7 +165,7 @@ func (l localRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) } func mustRead(r io.Reader) string { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { panic(err) } diff --git a/ident/ident.go b/ident/ident.go index 29e498e..9fa9258 100644 --- a/ident/ident.go +++ b/ident/ident.go @@ -118,7 +118,7 @@ func ParseScreamingSnakeCase(name string) Name { // Name is an identifier name, broken up into individual words. type Name []string -// ToMixedCaps expresses identifer name in MixedCaps naming convention. +// ToMixedCaps expresses identifier name in MixedCaps naming convention. // // E.g., "ClientMutationID". func (n Name) ToMixedCaps() string { @@ -141,7 +141,7 @@ func (n Name) ToMixedCaps() string { return strings.Join(n, "") } -// ToLowerCamelCase expresses identifer name in lowerCamelCase naming convention. +// ToLowerCamelCase expresses identifier name in lowerCamelCase naming convention. // // E.g., "clientMutationId". func (n Name) ToLowerCamelCase() string { @@ -180,8 +180,6 @@ func isTwoInitialisms(word string) (string, string, bool) { // Only add entries that are highly unlikely to be non-initialisms. // For instance, "ID" is fine (Freudian code is rare), but "AND" is not. var initialisms = map[string]struct{}{ - // These are the common initialisms from golint. Keep them in sync - // with https://gotools.org/github.com/golang/lint#commonInitialisms. "ACL": {}, "API": {}, "ASCII": {}, @@ -201,6 +199,7 @@ var initialisms = map[string]struct{}{ "RAM": {}, "RHS": {}, "RPC": {}, + "RSS": {}, "SLA": {}, "SMTP": {}, "SQL": {}, @@ -211,18 +210,15 @@ var initialisms = map[string]struct{}{ "UDP": {}, "UI": {}, "UID": {}, - "UUID": {}, "URI": {}, "URL": {}, "UTF8": {}, + "UUID": {}, "VM": {}, "XML": {}, "XMPP": {}, "XSRF": {}, "XSS": {}, - - // Additional common initialisms. - "RSS": {}, } // isBrand reports whether word is a brand. @@ -237,4 +233,9 @@ func isBrand(word string) (string, bool) { // Only add entries that are highly unlikely to be non-brands. var brands = map[string]string{ "github": "GitHub", + "gitlab": "GitLab", + "devops": "DevOps", // For https://en.wikipedia.org/wiki/DevOps. + // For https://docs.github.com/en/graphql/reference/enums#fundingplatform. + "issuehunt": "IssueHunt", + "lfx": "LFX", } diff --git a/ident/ident_test.go b/ident/ident_test.go index b6487a8..586a530 100644 --- a/ident/ident_test.go +++ b/ident/ident_test.go @@ -89,6 +89,7 @@ func TestName_ToMixedCaps(t *testing.T) { {in: ident.Name{"client", "Mutation", "Id"}, want: "ClientMutationID"}, {in: ident.Name{"CLIENT", "MUTATION", "ID"}, want: "ClientMutationID"}, {in: ident.Name{"github", "logo"}, want: "GitHubLogo"}, + {in: ident.Name{"AZURE", "DEVOPS"}, want: "AzureDevOps"}, } for _, tc := range tests { got := tc.in.ToMixedCaps() diff --git a/internal/jsonutil/graphql.go b/internal/jsonutil/graphql.go index 1f165fd..5a44ea5 100644 --- a/internal/jsonutil/graphql.go +++ b/internal/jsonutil/graphql.go @@ -17,7 +17,7 @@ import ( // // The implementation is created on top of the JSON tokenizer available // in "encoding/json".Decoder. -func UnmarshalGraphQL(data []byte, v interface{}) error { +func UnmarshalGraphQL(data []byte, v any) error { dec := json.NewDecoder(bytes.NewReader(data)) dec.UseNumber() err := (&decoder{tokenizer: dec}).Decode(v) @@ -57,7 +57,7 @@ type decoder struct { } // Decode decodes a single JSON value from d.tokenizer into v. -func (d *decoder) Decode(v interface{}) error { +func (d *decoder) Decode(v any) error { rv := reflect.ValueOf(v) if rv.Kind() != reflect.Ptr { return fmt.Errorf("cannot decode into non-pointer %T", v) @@ -280,10 +280,9 @@ func hasGraphQLName(f reflect.StructField, name string) bool { // GraphQL fragment. It doesn't have a name. return false } - if i := strings.Index(value, "("); i != -1 { - value = value[:i] - } - if i := strings.Index(value, ":"); i != -1 { + // Cut off anything that follows the field name, + // such as field arguments, aliases, directives. + if i := strings.IndexAny(value, "(:@"); i != -1 { value = value[:i] } return strings.TrimSpace(value) == name diff --git a/internal/jsonutil/graphql_test.go b/internal/jsonutil/graphql_test.go index 1c92965..94ddaa0 100644 --- a/internal/jsonutil/graphql_test.go +++ b/internal/jsonutil/graphql_test.go @@ -267,6 +267,39 @@ func TestUnmarshalGraphQL_multipleValues(t *testing.T) { } } +func TestUnmarshalGraphQL_directives(t *testing.T) { + /* + query { + me { + name @include(if: true) + height @skip(if: false) + } + } + */ + type query struct { + Me struct { + Name graphql.String `graphql:"name @include(if: true)"` + Height graphql.Float `graphql:"height @skip(if: false)"` + } + } + var got query + err := jsonutil.UnmarshalGraphQL([]byte(`{ + "me": { + "name": "Luke Skywalker", + "height": 1.72 + } + }`), &got) + if err != nil { + t.Fatal(err) + } + var want query + want.Me.Name = "Luke Skywalker" + want.Me.Height = 1.72 + if !reflect.DeepEqual(got, want) { + t.Error("not equal") + } +} + func TestUnmarshalGraphQL_union(t *testing.T) { /* { diff --git a/query.go b/query.go index 0d04b04..16eaecd 100644 --- a/query.go +++ b/query.go @@ -10,7 +10,7 @@ import ( "github.com/cli/shurcooL-graphql/ident" ) -func constructQuery(v interface{}, variables map[string]interface{}, queryName string) string { +func constructQuery(v any, variables map[string]any, queryName string) string { query := query(v) if len(variables) > 0 { return "query" + queryNameFormat(queryName) + "(" + queryArguments(variables) + ")" + query @@ -20,7 +20,7 @@ func constructQuery(v interface{}, variables map[string]interface{}, queryName s return query } -func constructMutation(v interface{}, variables map[string]interface{}, queryName string) string { +func constructMutation(v any, variables map[string]any, queryName string) string { query := query(v) if len(variables) > 0 { return "mutation" + queryNameFormat(queryName) + "(" + queryArguments(variables) + ")" + query @@ -37,8 +37,8 @@ func queryNameFormat(n string) string { // queryArguments constructs a minified arguments string for variables. // -// E.g., map[string]interface{}{"a": Int(123), "b": NewBoolean(true)} -> "$a:Int!$b:Boolean". -func queryArguments(variables map[string]interface{}) string { +// E.g., map[string]any{"a": Int(123), "b": NewBoolean(true)} -> "$a:Int!$b:Boolean". +func queryArguments(variables map[string]any) string { // Sort keys in order to produce deterministic output for testing purposes. // TODO: If tests can be made to work with non-deterministic output, then no need to sort. keys := make([]string, 0, len(variables)) @@ -55,7 +55,7 @@ func queryArguments(variables map[string]interface{}) string { writeArgumentType(&buf, reflect.TypeOf(variables[k]), true) // Don't insert a comma here. // Commas in GraphQL are insignificant, and we want minified output. - // See https://facebook.github.io/graphql/October2016/#sec-Insignificant-Commas. + // See https://spec.graphql.org/October2021/#sec-Insignificant-Commas. } return buf.String() } @@ -95,7 +95,7 @@ func writeArgumentType(w io.Writer, t reflect.Type, value bool) { // a minified query string from the provided struct v. // // E.g., struct{Foo Int, BarBaz *Boolean} -> "{foo,barBaz}". -func query(v interface{}) string { +func query(v any) string { var buf bytes.Buffer writeQuery(&buf, reflect.TypeOf(v), false) return buf.String() diff --git a/query_test.go b/query_test.go index c290d91..9db3d1c 100644 --- a/query_test.go +++ b/query_test.go @@ -8,8 +8,8 @@ import ( func TestConstructQuery(t *testing.T) { tests := []struct { - inV interface{} - inVariables map[string]interface{} + inV any + inVariables map[string]any want string }{ { @@ -56,7 +56,7 @@ func TestConstructQuery(t *testing.T) { want: `{repository(owner:"shurcooL-test"name:"test-repo"){databaseId,url,issue(number:1){comments(first:1after:"Y3Vyc29yOjE5NTE4NDI1Ng=="){edges{node{body,author{login},editor{login}},cursor}}}}}`, }, { - inV: func() interface{} { + inV: func() any { type actor struct { Login String AvatarURL URI @@ -90,7 +90,7 @@ func TestConstructQuery(t *testing.T) { want: `{repository(owner:"shurcooL-test"name:"test-repo"){databaseId,url,issue(number:1){comments(first:1){edges{node{databaseId,author{login,avatarUrl,url},publishedAt,lastEditedAt,editor{login,avatarUrl,url},body,viewerCanUpdate},cursor}}}}}`, }, { - inV: func() interface{} { + inV: func() any { type actor struct { Login String AvatarURL URI `graphql:"avatarUrl(size:72)"` @@ -160,7 +160,7 @@ func TestConstructQuery(t *testing.T) { } `graphql:"issue(number: $issueNumber)"` } `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"` }{}, - inVariables: map[string]interface{}{ + inVariables: map[string]any{ "repositoryOwner": String("shurcooL-test"), "repositoryName": String("test-repo"), "issueNumber": Int(1), @@ -181,7 +181,7 @@ func TestConstructQuery(t *testing.T) { } `graphql:"issue(number: $issueNumber)"` } `graphql:"repository(owner: $repositoryOwner, name: $repositoryName)"` }{}, - inVariables: map[string]interface{}{ + inVariables: map[string]any{ "repositoryOwner": String("shurcooL-test"), "repositoryName": String("test-repo"), "issueNumber": Int(1), @@ -190,7 +190,7 @@ func TestConstructQuery(t *testing.T) { }, // Embedded structs without graphql tag should be inlined in query. { - inV: func() interface{} { + inV: func() any { type actor struct { Login String AvatarURL URI @@ -221,7 +221,7 @@ func TestConstructQuery(t *testing.T) { Viewer struct { Login string CreatedAt time.Time - ID interface{} + ID any DatabaseID int } }{}, @@ -238,8 +238,8 @@ func TestConstructQuery(t *testing.T) { func TestConstructMutation(t *testing.T) { tests := []struct { - inV interface{} - inVariables map[string]interface{} + inV any + inVariables map[string]any want string }{ { @@ -254,7 +254,7 @@ func TestConstructMutation(t *testing.T) { } } `graphql:"addReaction(input:$input)"` }{}, - inVariables: map[string]interface{}{ + inVariables: map[string]any{ "input": AddReactionInput{ SubjectID: "MDU6SXNzdWUyMzE1MjcyNzk=", Content: ReactionContentThumbsUp, @@ -273,44 +273,44 @@ func TestConstructMutation(t *testing.T) { func TestQueryArguments(t *testing.T) { tests := []struct { - in map[string]interface{} + in map[string]any want string }{ { - in: map[string]interface{}{"a": Int(123), "b": NewBoolean(true)}, + in: map[string]any{"a": Int(123), "b": NewBoolean(true)}, want: "$a:Int!$b:Boolean", }, { - in: map[string]interface{}{ + in: map[string]any{ "required": []IssueState{IssueStateOpen, IssueStateClosed}, "optional": &[]IssueState{IssueStateOpen, IssueStateClosed}, }, want: "$optional:[IssueState!]$required:[IssueState!]!", }, { - in: map[string]interface{}{ + in: map[string]any{ "required": []IssueState(nil), "optional": (*[]IssueState)(nil), }, want: "$optional:[IssueState!]$required:[IssueState!]!", }, { - in: map[string]interface{}{ + in: map[string]any{ "required": [...]IssueState{IssueStateOpen, IssueStateClosed}, "optional": &[...]IssueState{IssueStateOpen, IssueStateClosed}, }, want: "$optional:[IssueState!]$required:[IssueState!]!", }, { - in: map[string]interface{}{"id": ID("someID")}, + in: map[string]any{"id": ID("someID")}, want: "$id:ID!", }, { - in: map[string]interface{}{"ids": []ID{"someID", "anotherID"}}, + in: map[string]any{"ids": []ID{"someID", "anotherID"}}, want: `$ids:[ID!]!`, }, { - in: map[string]interface{}{"ids": &[]ID{"someID", "anotherID"}}, + in: map[string]any{"ids": &[]ID{"someID", "anotherID"}}, want: `$ids:[ID!]`, }, } diff --git a/scalar.go b/scalar.go index 0f7ceea..8679d34 100644 --- a/scalar.go +++ b/scalar.go @@ -23,7 +23,7 @@ type ( // intended to be human-readable. When expected as an input type, // any string (such as "VXNlci0xMA==") or integer (such as 4) input // value will be accepted as an ID. - ID interface{} + ID any // Int represents non-fractional signed whole numeric values. // Int can represent values between -(2^31) and 2^31 - 1.