private void handleExecutionResult(WebSocketWriter out, String id,
                                       @Nullable ExecutionResult executionResult, @Nullable Throwable t) {
        if (t != null) {
            logger.debug("Error handling subscription", t);
            writeError(out, id, t);
            return;
        }

        if (executionResult == null) {
            logger.debug("ExecutionResult was null but no error was thrown");
            writeError(out, id, new IllegalArgumentException("ExecutionResult was null"));
            return;
        }

        if (!executionResult.getErrors().isEmpty()) {
            try {
                writeError(out, id, executionResult.getErrors());
            } catch (JsonProcessingException e) {
                logger.warn("Error serializing error event", e);
                out.close(e);
            }
            return;
        }

        if (!(executionResult.getData() instanceof Publisher)) {
            writeError(out, id, new Exception("Result of operation was not a subscription"));
            return;
        }

        final Publisher<ExecutionResult> publisher = executionResult.getData();
        final StreamMessage<ExecutionResult> streamMessage = StreamMessage.of(publisher);

        final ExecutionResultSubscriber executionResultSubscriber =
                new ExecutionResultSubscriber(id, new GraphqlSubProtocol() {
                    boolean completed;

                    @Override
                    public void sendResult(String operationId, ExecutionResult executionResult)
                            throws JsonProcessingException {
                        writeNext(out, operationId, executionResult);
                    }

                    @Override
                    public void sendGraphqlErrors(List<GraphQLError> errors) throws JsonProcessingException {
                        writeError(out, id, errors);
                    }

                    @Override
                    public void completeWithError(Throwable cause) {
                        if (completed) {
                            return;
                        }
                        completed = true;
                        writeError(out, id, cause);
                        graphqlSubscriptions.remove(id);
                    }

                    @Override
                    public void complete() {
                        if (completed) {
                            return;
                        }
                        completed = true;
                        writeComplete(out, id);
                        graphqlSubscriptions.remove(id);
                    }
                });

        graphqlSubscriptions.put(id, executionResultSubscriber);
        streamMessage.subscribe(executionResultSubscriber, ctx.eventLoop());
    }
Receives an event and returns a response if one should be sent.
graphql/src/main/java/com/linecorp/armeria/server/graphql/GraphqlWSSubProtocol.java