Skip to content

Commit ad010c5

Browse files
committed
Merge branch 'trunk'
2 parents ed46e5a + af8dbfa commit ad010c5

17 files changed

Lines changed: 172 additions & 177 deletions

File tree

.github/workflows/lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
7+
steps:
8+
- name: Checkout code
9+
uses: actions/checkout@v4
10+
11+
- name: Set up Go
12+
uses: actions/setup-go@v4
13+
with:
14+
go-version: '1.16'
15+
16+
- name: Lint
17+
uses: golangci/golangci-lint-action@v3
18+
with:
19+
version: latest

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
os: [ubuntu-latest, windows-latest, macos-latest]
9+
go: [1.16]
10+
runs-on: ${{ matrix.os }}
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: ${{ matrix.go }}
20+
21+
- name: Run tests
22+
run: go test -v ./...

.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
linters:
2+
enable:
3+
- gofmt
4+
- godot
5+
6+
linters-settings:
7+
godot:
8+
# comments to be checked: `declarations`, `toplevel`, or `all`
9+
scope: declarations
10+
# check that each sentence starts with a capital letter
11+
capital: true

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
graphql
22
=======
33

4-
[![Go Reference](https://pkg.go.dev/badge/github.com/shurcooL/graphql.svg)](https://pkg.go.dev/github.com/shurcooL/graphql)
5-
6-
Package `graphql` provides a GraphQL client implementation.
7-
8-
For more information, see package [`github.com/shurcooL/githubv4`](https://github.com/shurcooL/githubv4), which is a specialized version targeting GitHub GraphQL API v4. That package is driving the feature development.
4+
Package `graphql` provides a GraphQL client implementation, and is forked from `https://github.com/shurcooL/graphql`.
95

106
Installation
117
------------
128

13-
```sh
14-
go get github.com/shurcooL/graphql
9+
```bash
10+
go get -u github.com/cli/shurcooL-graphql
1511
```
1612

1713
Usage
@@ -274,14 +270,6 @@ fmt.Printf("Created a %v star review: %v\n", m.CreateReview.Stars, m.CreateRevie
274270
// Created a 5 star review: This is a great movie!
275271
```
276272
277-
Directories
278-
-----------
279-
280-
| Path | Synopsis |
281-
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
282-
| [ident](https://pkg.go.dev/github.com/shurcooL/graphql/ident) | Package ident provides functions for parsing and converting identifier names between various naming convention. |
283-
| [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. |
284-
285273
License
286274
-------
287275

doc.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/graphqldev/main.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/shurcooL/graphql
1+
module github.com/cli/shurcooL-graphql
22

33
go 1.19

go.sum

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
4+
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
5+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
6+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
7+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
9+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
10+
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
11+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
12+
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
13+
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
14+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
15+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
16+
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
17+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
18+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
21+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
25+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
26+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
27+
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
28+
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
29+
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
30+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
31+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
32+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
33+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
34+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
35+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
36+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
37+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
38+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
39+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
40+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

graphql.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"strings"
1011

11-
"github.com/shurcooL/graphql/internal/jsonutil"
12+
"github.com/cli/shurcooL-graphql/internal/jsonutil"
1213
)
1314

1415
// Client is a GraphQL client.
@@ -31,26 +32,36 @@ func NewClient(url string, httpClient *http.Client) *Client {
3132

3233
// Query executes a single GraphQL query request,
3334
// with a query derived from q, populating the response into it.
34-
// q should be a pointer to struct that corresponds to the GraphQL schema.
35+
// Argument q should be a pointer to struct that corresponds to the GraphQL schema.
3536
func (c *Client) Query(ctx context.Context, q any, variables map[string]any) error {
36-
return c.do(ctx, queryOperation, q, variables)
37+
return c.do(ctx, queryOperation, q, variables, "")
38+
}
39+
40+
// QueryNamed is the same as Query but allows a name to be specified for the query.
41+
func (c *Client) QueryNamed(ctx context.Context, queryName string, q any, variables map[string]any) error {
42+
return c.do(ctx, queryOperation, q, variables, queryName)
3743
}
3844

3945
// Mutate executes a single GraphQL mutation request,
4046
// with a mutation derived from m, populating the response into it.
41-
// m should be a pointer to struct that corresponds to the GraphQL schema.
47+
// Argument m should be a pointer to struct that corresponds to the GraphQL schema.
4248
func (c *Client) Mutate(ctx context.Context, m any, variables map[string]any) error {
43-
return c.do(ctx, mutationOperation, m, variables)
49+
return c.do(ctx, mutationOperation, m, variables, "")
50+
}
51+
52+
// MutateNamed is the same as Mutate but allows a name to be specified for the mutation.
53+
func (c *Client) MutateNamed(ctx context.Context, queryName string, m any, variables map[string]any) error {
54+
return c.do(ctx, mutationOperation, m, variables, queryName)
4455
}
4556

4657
// do executes a single GraphQL operation.
47-
func (c *Client) do(ctx context.Context, op operationType, v any, variables map[string]any) error {
58+
func (c *Client) do(ctx context.Context, op operationType, v any, variables map[string]any, queryName string) error {
4859
var query string
4960
switch op {
5061
case queryOperation:
51-
query = constructQuery(v, variables)
62+
query = constructQuery(v, variables, queryName)
5263
case mutationOperation:
53-
query = constructMutation(v, variables)
64+
query = constructMutation(v, variables, queryName)
5465
}
5566
in := struct {
5667
Query string `json:"query"`
@@ -80,7 +91,7 @@ func (c *Client) do(ctx context.Context, op operationType, v any, variables map[
8091
}
8192
var out struct {
8293
Data *json.RawMessage
83-
Errors errors
94+
Errors Errors
8495
//Extensions any // Unused.
8596
}
8697
err = json.NewDecoder(resp.Body).Decode(&out)
@@ -101,27 +112,37 @@ func (c *Client) do(ctx context.Context, op operationType, v any, variables map[
101112
return nil
102113
}
103114

104-
// errors represents the "errors" array in a response from a GraphQL server.
115+
// Errors represents the "errors" array in a response from a GraphQL server.
105116
// If returned via error interface, the slice is expected to contain at least 1 element.
106117
//
107118
// Specification: https://spec.graphql.org/October2021/#sec-Errors.
108-
type errors []struct {
119+
type Errors []struct {
109120
Message string
110121
Locations []struct {
111122
Line int
112123
Column int
113124
}
125+
Path []any
126+
Extensions map[string]any
127+
Type string
114128
}
115129

116130
// Error implements error interface.
117-
func (e errors) Error() string {
118-
return e[0].Message
131+
func (e Errors) Error() string {
132+
b := strings.Builder{}
133+
l := len(e)
134+
for i, err := range e {
135+
b.WriteString(fmt.Sprintf("Message: %s, Locations: %+v", err.Message, err.Locations))
136+
if i != l-1 {
137+
b.WriteString("\n")
138+
}
139+
}
140+
return b.String()
119141
}
120142

121143
type operationType uint8
122144

123145
const (
124146
queryOperation operationType = iota
125147
mutationOperation
126-
//subscriptionOperation // Unused.
127148
)

graphql_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/http/httptest"
88
"testing"
99

10-
"github.com/shurcooL/graphql"
10+
graphql "github.com/cli/shurcooL-graphql"
1111
)
1212

1313
func TestClient_Query_partialDataWithErrorResponse(t *testing.T) {
@@ -52,7 +52,7 @@ func TestClient_Query_partialDataWithErrorResponse(t *testing.T) {
5252
if err == nil {
5353
t.Fatal("got error: nil, want: non-nil")
5454
}
55-
if got, want := err.Error(), "Could not resolve to a node with the global id of 'NotExist'"; got != want {
55+
if got, want := err.Error(), "Message: Could not resolve to a node with the global id of 'NotExist', Locations: [{Line:10 Column:4}]"; got != want {
5656
t.Errorf("got error: %v, want: %v", got, want)
5757
}
5858
if q.Node1 == nil || q.Node1.ID != "MDEyOklzc3VlQ29tbWVudDE2OTQwNzk0Ng==" {
@@ -92,7 +92,7 @@ func TestClient_Query_noDataWithErrorResponse(t *testing.T) {
9292
if err == nil {
9393
t.Fatal("got error: nil, want: non-nil")
9494
}
95-
if got, want := err.Error(), "Field 'user' is missing required arguments: login"; got != want {
95+
if got, want := err.Error(), "Message: Field 'user' is missing required arguments: login, Locations: [{Line:7 Column:3}]"; got != want {
9696
t.Errorf("got error: %v, want: %v", got, want)
9797
}
9898
if q.User.Name != "" {

0 commit comments

Comments
 (0)