From ead0eb8f9c3d91dad6b4664930e562081e4c7971 Mon Sep 17 00:00:00 2001 From: jhen Date: Thu, 27 Jul 2023 04:55:30 +0800 Subject: [PATCH] Middleware: Handle `ac-devtools:` prefix messages --- app/middlewares/debuggerAPI.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/app/middlewares/debuggerAPI.js b/app/middlewares/debuggerAPI.js index 567680f9..63c8c960 100644 --- a/app/middlewares/debuggerAPI.js +++ b/app/middlewares/debuggerAPI.js @@ -29,24 +29,13 @@ let host let port let socket -const APOLLO_BACKEND = 'apollo-devtools-backend' -const APOLLO_PROXY = 'apollo-devtools-proxy' +const APOLLO_MESSAGE_PREFIX = 'ac-devtools:' const workerOnMessage = (message) => { const { data } = message - if (data && data.source === APOLLO_BACKEND) { - if (!window.__APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__) { - window.__APOLLO_DEVTOOLS_SHOULD_DISPLAY_PANEL__ = true - } - - postMessage( - { - source: APOLLO_BACKEND, - payload: data, - }, - '*', - ) + if (data && data.message?.startsWith(APOLLO_MESSAGE_PREFIX)) { + postMessage(data, '*') return false } @@ -63,12 +52,10 @@ const workerOnMessage = (message) => { const onWindowMessage = (e) => { const { data } = e - if (data && data.source === APOLLO_PROXY) { - const message = typeof data.payload === 'string' ? { event: data.payload } : data.payload + if (data && data.message?.startsWith(APOLLO_MESSAGE_PREFIX)) { worker.postMessage({ method: 'emitApolloMessage', - source: APOLLO_PROXY, - ...message, + ...data, }) } }