Skip to content

Commit 5c30d06

Browse files
author
Jannis Pohlmann
committed
subscriptions: Convert GraphQL errors to nil if they are empty
This reduces the likelyhood of servers that use graphqlws to send an empty array of errors along with subscription updates to clients. This also makes subscriptions work better in GraphiQL, where previously, the empty array of errors would make GraphiQL-Subscriptions-Fetcher would treat all updates as errors: https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher/blob/master/src/fetcher.ts#L36 (An empty array is considered truthy).
1 parent decdb69 commit 5c30d06

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

subscriptions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import (
1212

1313
// ErrorsFromGraphQLErrors convert from GraphQL errors to regular errors.
1414
func ErrorsFromGraphQLErrors(errors []gqlerrors.FormattedError) []error {
15+
if len(errors) == 0 {
16+
return nil
17+
}
18+
1519
out := make([]error, len(errors))
1620
for i := range errors {
1721
out[i] = errors[i]

0 commit comments

Comments
 (0)