public function createResponse(array $result): Response
    {
        if (empty($this->deferred)) {
            return response($result);
        }

        return response()->stream(
            function () use ($result): void {
                $nested = 1;
                $this->result = $result;
                $this->isStreaming = true;
                $this->stream->stream($result, [], empty($this->deferred));

                if ($executionTime = config('lighthouse.defer.max_execution_ms', 0)) {
                    $this->maxExecutionTime = microtime(true) + ($executionTime * 1000);
                }

                // TODO: Allow nested_levels to be set in config
                // to break out of loop early.
                while (
                    count($this->deferred)
                    && ! $this->executionTimeExpired()
                    && ! $this->maxNestedFieldsResolved($nested)
                ) {
                    $nested++;
                    $this->executeDeferred();
                }

                // We've hit the max execution time or max nested levels of deferred fields.
                // We process remaining deferred fields, but are no longer allowing additional
                // fields to be deferred.
                if (count($this->deferred)) {
                    $this->acceptFurtherDeferring = false;
                    $this->executeDeferred();
                }
            },
            200,
            [
                // TODO: Allow headers to be set in config
                'X-Accel-Buffering' => 'no',
                'Content-Type' => 'multipart/mixed; boundary="-"',
            ]
        );
    }