Skip to content

Commit

Permalink
resolver: do not return extensions or errors if there are non
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarkk committed Oct 14, 2021
1 parent 704a652 commit 96dec74
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions implement_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestHandleRequestRequestInURL(t *testing.T) {
for _, err := range errs {
panic(err)
}
a.Equal(t, `{"data":{"a":{"bar":"baz"}},"errors":[],"extensions":{}}`, string(res))
a.Equal(t, `{"data":{"a":{"bar":"baz"}}}`, string(res))
}

func TestHandleRequestRequestJsonBody(t *testing.T) {
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestHandleRequestRequestJsonBody(t *testing.T) {
for _, err := range errs {
panic(err)
}
a.Equal(t, `{"data":{"a":{"bar":"baz"}},"errors":[],"extensions":{}}`, string(res))
a.Equal(t, `{"data":{"a":{"bar":"baz"}}}`, string(res))
}

func TestHandleRequestRequestForm(t *testing.T) {
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestHandleRequestRequestForm(t *testing.T) {
for _, err := range errs {
panic(err)
}
a.Equal(t, `{"data":{"a":{"bar":"baz"}},"errors":[],"extensions":{}}`, string(res))
a.Equal(t, `{"data":{"a":{"bar":"baz"}}}`, string(res))
}

func TestHandleRequestRequestBatch(t *testing.T) {
Expand Down Expand Up @@ -162,5 +162,5 @@ func TestHandleRequestRequestBatch(t *testing.T) {
for _, err := range errs {
panic(err)
}
a.Equal(t, `[{"data":{"a":{"bar":"baz"}},"errors":[],"extensions":{}},{"data":{"a":{"foo":null}},"errors":[],"extensions":{}}]`, string(res))
a.Equal(t, `[{"data":{"a":{"bar":"baz"}}},{"data":{"a":{"foo":null}}}]`, string(res))
}
2 changes: 1 addition & 1 deletion readme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func TestReadmeExample(t *testing.T) {
log.Fatal(err)
}

a.Equal(t, `{"data":{"posts":[{"id":"1","name":"post 1"},{"id":"2","name":"post 2"},{"id":"3","name":"post 3"}]},"errors":[],"extensions":{}}`, string(s.Result))
a.Equal(t, `{"data":{"posts":[{"id":"1","name":"post 1"},{"id":"2","name":"post 2"},{"id":"3","name":"post 3"}]}}`, string(s.Result))
}
6 changes: 2 additions & 4 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,9 @@ func (s *Schema) Resolve(query []byte, opts ResolveOptions) []error {
// Add errors to output
errsLen := len(ctx.query.Errors)
if errsLen == 0 && !ctx.tracingEnabled {
ctx.write([]byte(`,"errors":[],"extensions":{}}`))
ctx.write([]byte(`}`))
} else {
if errsLen == 0 {
ctx.write([]byte(`,"errors":[]`))
} else {
if errsLen != 0 {
ctx.write([]byte(`,"errors":[`))
for i, err := range ctx.query.Errors {
if i > 0 {
Expand Down
2 changes: 1 addition & 1 deletion resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestBytecodeResolveCorrectMeta(t *testing.T) {
if !json.Valid([]byte(res)) {
panic("invalid json: " + res)
}
a.Equal(t, `{"data":{"a":{"foo":null,"bar":""},"b":{"baz":""}},"errors":[],"extensions":{}}`, res)
a.Equal(t, `{"data":{"a":{"foo":null,"bar":""},"b":{"baz":""}}}`, res)
}

func TestBytecodeResolveCorrectMetaWithError(t *testing.T) {
Expand Down

0 comments on commit 96dec74

Please sign in to comment.