From a576aff03f0fe4923ec5e3df4149f63e17290f4b Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Fri, 5 Jan 2018 14:19:14 +0100 Subject: [PATCH] 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). --- subscriptions.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/subscriptions.go b/subscriptions.go index 33827ed..27378c8 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -12,6 +12,10 @@ import ( // ErrorsFromGraphQLErrors convert from GraphQL errors to regular errors. func ErrorsFromGraphQLErrors(errors []gqlerrors.FormattedError) []error { + if len(errors) == 0 { + return nil + } + out := make([]error, len(errors)) for i := range errors { out[i] = errors[i]