Skip to content

Commit cd680d5

Browse files
author
Federico Bevione
committed
fix lint
1 parent cca0e08 commit cd680d5

2 files changed

Lines changed: 17 additions & 35 deletions

File tree

client/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,14 @@ func parseResponse(body []byte, httpCode int, result interface{}) error {
151151
return nil
152152
}
153153

154+
// response is a GraphQL layer response from a handler.
155+
type response struct {
156+
Data json.RawMessage `json:"data"`
157+
Errors json.RawMessage `json:"errors"`
158+
}
159+
154160
func unmarshal(data []byte, res interface{}) error {
155-
resp := graphqljson.Response{}
161+
resp := response{}
156162
if err := graphqljson.UnmarshalData(data, &resp); err != nil {
157163
return xerrors.Errorf("failed to decode data %s: %w", string(data), err)
158164
}

graphqljson/graphql.go

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ import (
3838

3939
// Reference: https://blog.gopheracademy.com/advent-2017/custom-json-unmarshaler-for-graphql-client/
4040

41-
// Response is a GraphQL layer response from a handler.
42-
type Response struct {
43-
Data json.RawMessage
44-
Errors Errors
45-
Extensions map[string]interface{}
46-
}
47-
4841
// UnmarshalData parses the JSON-encoded GraphQL response data and stores
4942
// the result in the GraphQL query data structure pointed to by v.
5043
//
@@ -70,9 +63,9 @@ func UnmarshalData(data json.RawMessage, v interface{}) error {
7063
return xerrors.Errorf("invalid token '%v' after top-level value", tok)
7164
}
7265

73-
// decoder is a JSON decoder that performs custom unmarshaling behavior
66+
// Decoder is a JSON Decoder that performs custom unmarshaling behavior
7467
// for GraphQL query data structures. It's implemented on top of a JSON tokenizer.
75-
type decoder struct {
68+
type Decoder struct {
7669
jsonDecoder *json.Decoder
7770

7871
// Stack of what part of input JSON we're in the middle of - objects, arrays.
@@ -87,17 +80,17 @@ type decoder struct {
8780
vs [][]reflect.Value
8881
}
8982

90-
func newDecoder(r io.Reader) *decoder {
83+
func newDecoder(r io.Reader) *Decoder {
9184
jsonDecoder := json.NewDecoder(r)
9285
jsonDecoder.UseNumber()
9386

94-
return &decoder{
87+
return &Decoder{
9588
jsonDecoder: jsonDecoder,
9689
}
9790
}
9891

9992
// Decode decodes a single JSON value from d.tokenizer into v.
100-
func (d *decoder) Decode(v interface{}) error {
93+
func (d *Decoder) Decode(v interface{}) error {
10194
rv := reflect.ValueOf(v)
10295
if rv.Kind() != reflect.Ptr {
10396
return xerrors.Errorf("cannot decode into non-pointer %T", v)
@@ -112,7 +105,7 @@ func (d *decoder) Decode(v interface{}) error {
112105
}
113106

114107
// decode decodes a single JSON value from d.tokenizer into d.vs.
115-
func (d *decoder) decode() error {
108+
func (d *Decoder) decode() error {
116109
// The loop invariant is that the top of each d.vs stack
117110
// is where we try to unmarshal the next JSON value we see.
118111
for len(d.vs) > 0 {
@@ -268,18 +261,18 @@ func (d *decoder) decode() error {
268261
}
269262

270263
// pushState pushes a new parse state s onto the stack.
271-
func (d *decoder) pushState(s json.Delim) {
264+
func (d *Decoder) pushState(s json.Delim) {
272265
d.parseState = append(d.parseState, s)
273266
}
274267

275268
// popState pops a parse state (already obtained) off the stack.
276269
// The stack must be non-empty.
277-
func (d *decoder) popState() {
270+
func (d *Decoder) popState() {
278271
d.parseState = d.parseState[:len(d.parseState)-1]
279272
}
280273

281274
// state reports the parse state on top of stack, or 0 if empty.
282-
func (d *decoder) state() json.Delim {
275+
func (d *Decoder) state() json.Delim {
283276
if len(d.parseState) == 0 {
284277
return 0
285278
}
@@ -288,7 +281,7 @@ func (d *decoder) state() json.Delim {
288281
}
289282

290283
// popAllVs pops from all d.vs stacks, keeping only non-empty ones.
291-
func (d *decoder) popAllVs() {
284+
func (d *Decoder) popAllVs() {
292285
var nonEmpty [][]reflect.Value
293286
for i := range d.vs {
294287
d.vs[i] = d.vs[i][:len(d.vs[i])-1]
@@ -360,20 +353,3 @@ func unmarshalValue(value json.Token, v reflect.Value) error {
360353

361354
return json.Unmarshal(b, v.Addr().Interface())
362355
}
363-
364-
// Errors represents the "Errors" array in a response from a GraphQL server.
365-
// If returned via error interface, the slice is expected to contain at least 1 element.
366-
//
367-
// Specification: https://facebook.github.io/graphql/#sec-Errors.
368-
type Errors []struct {
369-
Message string
370-
Locations []struct {
371-
Line int
372-
Column int
373-
}
374-
}
375-
376-
// Error implements error interface.
377-
func (e Errors) Error() string {
378-
return e[0].Message
379-
}

0 commit comments

Comments
 (0)