From bdb1221e171e552b0c7228c0837e6a2a2038b0f1 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 19 May 2022 23:09:53 -0400 Subject: [PATCH 1/9] ident: add GitLab, DevOps, IssueHunt, LFX brands These help generate nicer identifiers in the githubv4 package. Also remove mention of golint since it's deprecated, and sort the initialisms map. --- ident/ident.go | 13 +++++++------ ident/ident_test.go | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ident/ident.go b/ident/ident.go index 29e498e..408c96d 100644 --- a/ident/ident.go +++ b/ident/ident.go @@ -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 9ee1b47..9cecb78 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() From 3cf50f8a0a295163db1d360b4de28fb3cb874913 Mon Sep 17 00:00:00 2001 From: David Bain <97858950+david-bain@users.noreply.github.com> Date: Mon, 6 Jun 2022 14:39:23 +1000 Subject: [PATCH 2/9] internal/jsonutil: support directives directly after name Also consider "@" when looking for the end of the field name, since GraphQL directives can follow a field name immediately without any arguments or aliases being involved. For example: query { me { firstName lastName @include(if: $expandedInfo) } } The strings.Index check for "@" is the third separator we look for. There's no reason to look separately, since we just want the first field name separator. Add test covering a GraphQL directive that immediately follows the field name. Co-authored-by: Dmitri Shuralyov GitHub-Pull-Request: https://github.com/shurcooL/graphql/pull/94 --- internal/jsonutil/graphql.go | 7 +++---- internal/jsonutil/graphql_test.go | 33 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/internal/jsonutil/graphql.go b/internal/jsonutil/graphql.go index 15bae24..b99a9e7 100644 --- a/internal/jsonutil/graphql.go +++ b/internal/jsonutil/graphql.go @@ -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 6329ed8..0963baf 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) { /* { From 63a4f2adcc7502bcf912bccf00c1c2813d181778 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sat, 20 Nov 2021 15:36:42 -0500 Subject: [PATCH 3/9] regenerate README.md, add go.mod, remove .travis.yml Ignore example/graphqldev for now to avoid needing its dependencies for 'go test all' and the module as a whole. --- .travis.yml | 16 ---------------- README.md | 17 +++++++---------- doc.go | 2 +- example/graphqldev/main.go | 2 ++ go.mod | 5 +++++ go.sum | 2 ++ 6 files changed, 17 insertions(+), 27 deletions(-) delete mode 100644 .travis.yml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6452acb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false -language: go -go: - - 1.x - - master -matrix: - allow_failures: - - go: master - fast_finish: true -install: - - # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step). -script: - - go get -t -v ./... - - diff -n <(echo -n) <(gofmt -d -s .) - - go vet ./... - - go test -v -race ./... diff --git a/README.md b/README.md index 3353795..bf35325 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ graphql ======= -[![Build Status](https://travis-ci.org/shurcooL/graphql.svg?branch=master)](https://travis-ci.org/shurcooL/graphql) [![GoDoc](https://godoc.org/github.com/shurcooL/graphql?status.svg)](https://godoc.org/github.com/shurcooL/graphql) +[![Go Reference](https://pkg.go.dev/badge/github.com/shurcooL/graphql.svg)](https://pkg.go.dev/github.com/shurcooL/graphql) Package `graphql` provides a GraphQL client implementation. @@ -10,10 +10,8 @@ For more information, see package [`github.com/shurcooL/githubv4`](https://githu Installation ------------ -`graphql` requires Go version 1.8 or later. - -```bash -go get -u github.com/shurcooL/graphql +```sh +go get github.com/shurcooL/graphql ``` Usage @@ -279,11 +277,10 @@ fmt.Printf("Created a %v star review: %v\n", m.CreateReview.Stars, m.CreateRevie Directories ----------- -| Path | Synopsis | -|----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| -| [example/graphqldev](https://godoc.org/github.com/shurcooL/graphql/example/graphqldev) | graphqldev is a test program currently being used for developing graphql package. | -| [ident](https://godoc.org/github.com/shurcooL/graphql/ident) | Package ident provides functions for parsing and converting identifier names between various naming convention. | -| [internal/jsonutil](https://godoc.org/github.com/shurcooL/graphql/internal/jsonutil) | Package jsonutil provides a function for decoding JSON into a GraphQL query data structure. | +| Path | Synopsis | +|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------| +| [ident](https://pkg.go.dev/github.com/shurcooL/graphql/ident) | Package ident provides functions for parsing and converting identifier names between various naming convention. | +| [internal/jsonutil](https://pkg.go.dev/github.com/shurcooL/graphql/internal/jsonutil) | Package jsonutil provides a function for decoding JSON into a GraphQL query data structure. | License ------- diff --git a/doc.go b/doc.go index 870e3d4..cba7295 100644 --- a/doc.go +++ b/doc.go @@ -5,4 +5,4 @@ // That package is driving the feature development. // // For now, see README for more details. -package graphql // import "github.com/shurcooL/graphql" +package graphql diff --git a/example/graphqldev/main.go b/example/graphqldev/main.go index ffc8302..bffb493 100644 --- a/example/graphqldev/main.go +++ b/example/graphqldev/main.go @@ -1,3 +1,5 @@ +//go:build ignore + // graphqldev is a test program currently being used for developing graphql package. // It performs queries against a local test GraphQL server instance. // diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0e81aec --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/shurcooL/graphql + +go 1.19 + +require golang.org/x/net v0.11.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a29105c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= From 24ceaa0402e46e42a1fe756e8f8430d4fe32a8a1 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 23 Apr 2023 23:24:31 -0400 Subject: [PATCH 4/9] use package io instead of io/ioutil Package ioutil is longer and deprecated. --- graphql.go | 4 ++-- graphql_test.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/graphql.go b/graphql.go index 8520956..b80437f 100644 --- a/graphql.go +++ b/graphql.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/shurcooL/graphql/internal/jsonutil" @@ -71,7 +71,7 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab } 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 { diff --git a/graphql_test.go b/graphql_test.go index e09dcc9..5b6de3b 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" @@ -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) } From 85bf0c3c277eb06bae22d3c03cbb89113085fb0b Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Wed, 12 Jul 2023 16:28:42 +0300 Subject: [PATCH 5/9] ident: fix a typo in 'identifier' GitHub-Pull-Request: https://github.com/shurcooL/graphql/pull/108 --- ident/ident.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ident/ident.go b/ident/ident.go index 408c96d..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 { From 7016eab9f755e15d0565bfdc18c1e20f331b4dbd Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 14 Jul 2023 21:00:36 +0300 Subject: [PATCH 6/9] drop golang.org/x/net dependency Package graphql has only one ctxhttp.Post call that requires the golang.org/x/net module. It's easy enough to use net/http directly and drop x/net so there are fewer dependencies that need to be maintained. Co-authored-by: Dmitri Shuralyov GitHub-Pull-Request: https://github.com/shurcooL/graphql/pull/110 --- go.mod | 2 -- go.sum | 2 -- graphql.go | 12 ++++++++---- 3 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 go.sum diff --git a/go.mod b/go.mod index 0e81aec..a3c021e 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/shurcooL/graphql go 1.19 - -require golang.org/x/net v0.11.0 diff --git a/go.sum b/go.sum deleted file mode 100644 index a29105c..0000000 --- a/go.sum +++ /dev/null @@ -1,2 +0,0 @@ -golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= -golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= diff --git a/graphql.go b/graphql.go index b80437f..e516f75 100644 --- a/graphql.go +++ b/graphql.go @@ -9,13 +9,12 @@ import ( "net/http" "github.com/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. @@ -65,7 +64,12 @@ 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 } From 3e04114ae69a21dc27a554acb6ae568b046691d0 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 14 Jul 2023 21:28:44 +0300 Subject: [PATCH 7/9] replace interface{} with any The predeclared identifier 'any', an alias for the empty interface, is available as of Go 1.18. Use it in place of 'interface{}' since it's slightly shorter. GitHub-Pull-Request: https://github.com/shurcooL/graphql/pull/109 --- README.md | 4 ++-- example/graphqldev/main.go | 4 ++-- graphql.go | 12 ++++++------ graphql_test.go | 2 +- internal/jsonutil/graphql.go | 4 ++-- query.go | 10 +++++----- query_test.go | 38 ++++++++++++++++++------------------ scalar.go | 2 +- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index bf35325..d842768 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,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"), } @@ -252,7 +252,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/example/graphqldev/main.go b/example/graphqldev/main.go index bffb493..343c4d5 100644 --- a/example/graphqldev/main.go +++ b/example/graphqldev/main.go @@ -72,7 +72,7 @@ func run() error { AppearsIn []graphql.String } `graphql:"character(id: $characterID)"` } - variables := map[string]interface{}{ + variables := map[string]any{ "characterID": graphql.ID("1003"), } err = client.Query(context.Background(), &q, variables) @@ -85,7 +85,7 @@ func run() error { } // print pretty prints v to stdout. It panics on any error. -func print(v interface{}) { +func print(v any) { w := json.NewEncoder(os.Stdout) w.SetIndent("", "\t") err := w.Encode(v) diff --git a/graphql.go b/graphql.go index e516f75..38e92b7 100644 --- a/graphql.go +++ b/graphql.go @@ -32,19 +32,19 @@ 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. // 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) } // Mutate executes a single GraphQL mutation request, // with a mutation derived from m, populating the response into it. // 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) } // do executes a single GraphQL operation. -func (c *Client) do(ctx context.Context, op operationType, v interface{}, variables map[string]interface{}) error { +func (c *Client) do(ctx context.Context, op operationType, v any, variables map[string]any) error { var query string switch op { case queryOperation: @@ -53,8 +53,8 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab query = constructMutation(v, variables) } 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, @@ -81,7 +81,7 @@ func (c *Client) do(ctx context.Context, op operationType, v interface{}, variab var out struct { Data *json.RawMessage Errors errors - //Extensions interface{} // Unused. + //Extensions any // Unused. } err = json.NewDecoder(resp.Body).Decode(&out) if err != nil { diff --git a/graphql_test.go b/graphql_test.go index 5b6de3b..95c5c2a 100644 --- a/graphql_test.go +++ b/graphql_test.go @@ -143,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) } diff --git a/internal/jsonutil/graphql.go b/internal/jsonutil/graphql.go index b99a9e7..3b81d5c 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) diff --git a/query.go b/query.go index e10b771..6b1dd80 100644 --- a/query.go +++ b/query.go @@ -10,7 +10,7 @@ import ( "github.com/shurcooL/graphql/ident" ) -func constructQuery(v interface{}, variables map[string]interface{}) string { +func constructQuery(v any, variables map[string]any) string { query := query(v) if len(variables) > 0 { return "query(" + queryArguments(variables) + ")" + query @@ -18,7 +18,7 @@ func constructQuery(v interface{}, variables map[string]interface{}) string { return query } -func constructMutation(v interface{}, variables map[string]interface{}) string { +func constructMutation(v any, variables map[string]any) string { query := query(v) if len(variables) > 0 { return "mutation(" + queryArguments(variables) + ")" + query @@ -28,8 +28,8 @@ func constructMutation(v interface{}, variables map[string]interface{}) 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)) @@ -86,7 +86,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 4de8cb5..b4f5af4 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. From ed46e5a4646634fc16cb07c3b8db389542cc8847 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sat, 22 Jul 2023 07:37:21 +0300 Subject: [PATCH 8/9] update links to GraphQL specification User newer and more consistent links. GitHub-Pull-Request: https://github.com/shurcooL/graphql/pull/113 --- graphql.go | 2 +- query.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/graphql.go b/graphql.go index 38e92b7..b11bfae 100644 --- a/graphql.go +++ b/graphql.go @@ -104,7 +104,7 @@ func (c *Client) do(ctx context.Context, op operationType, v any, variables map[ // 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: https://facebook.github.io/graphql/#sec-Errors. +// Specification: https://spec.graphql.org/October2021/#sec-Errors. type errors []struct { Message string Locations []struct { diff --git a/query.go b/query.go index 6b1dd80..cc5954a 100644 --- a/query.go +++ b/query.go @@ -46,7 +46,7 @@ func queryArguments(variables map[string]any) 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() } From e6968884b737529e4dc6d8aef81d88693a18f259 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Thu, 5 Oct 2023 17:47:09 +0200 Subject: [PATCH 9/9] Update to Go 1.21 --- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- go.mod | 2 +- go.sum | 40 -------------------------------------- 4 files changed, 3 insertions(+), 43 deletions(-) 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/go.mod b/go.mod index 9bdde33..09db548 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/cli/shurcooL-graphql -go 1.19 +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=