···11+---
22+'@urql/core': patch
33+---
44+55+Add case for `subscriptionExchange` to handle `GraphQLError[]` received in the `error` observer callback.
66+**Note:** This doesn't strictly check for the `GraphQLError` shape and only checks for arrays and receiving errors in the `ExecutionResult` on the `next` observer callback is preferred and recommended for transports.
+24-13
packages/core/src/exchanges/subscription.ts
···144144 operation
145145 );
146146147147- return make<OperationResult>(({ next, complete }) => {
147147+ return make<OperationResult>(observer => {
148148 let isComplete = false;
149149 let sub: Subscription | void;
150150 let result: OperationResult | void;
151151+152152+ function nextResult(value: ExecutionResult) {
153153+ observer.next(
154154+ (result = result
155155+ ? mergeResultPatch(result, value)
156156+ : makeResult(operation, value))
157157+ );
158158+ }
151159152160 Promise.resolve().then(() => {
153161 if (isComplete) return;
154162155163 sub = observableish.subscribe({
156156- next(nextResult) {
157157- next(
158158- (result = result
159159- ? mergeResultPatch(result, nextResult)
160160- : makeResult(operation, nextResult))
161161- );
162162- },
164164+ next: nextResult,
163165 error(error) {
164164- next(makeErrorResult(operation, error));
166166+ if (Array.isArray(error)) {
167167+ // NOTE: This is an exception for transports that deliver `GraphQLError[]`, as part
168168+ // of the observer’s error callback (may happen as part of `graphql-ws`).
169169+ // We only check for arrays here, as this is an extremely “unexpected” case as the
170170+ // shape of `ExecutionResult` is instead strictly defined.
171171+ nextResult({ errors: error });
172172+ } else {
173173+ observer.next(makeErrorResult(operation, error));
174174+ }
175175+ observer.complete();
165176 },
166177 complete() {
167178 if (!isComplete) {
···171182 makeOperation('teardown', operation, operation.context)
172183 );
173184 }
174174-175175- if (result && result.hasNext)
176176- next(mergeResultPatch(result, { hasNext: false }));
177177- complete();
185185+ if (result && result.hasNext) {
186186+ nextResult({ hasNext: false });
187187+ }
188188+ observer.complete();
178189 }
179190 },
180191 });