Skip to content

Commit

Permalink
Middleware: Handle ac-devtools: prefix messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Jul 26, 2023
1 parent 64cb93b commit ead0eb8
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions app/middlewares/debuggerAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
})
}
}
Expand Down

0 comments on commit ead0eb8

Please sign in to comment.