Skip to content

Commit 2a75862

Browse files
committed
use postMessage to send query params in URL as Explorer query
1 parent ffe0783 commit 2a75862

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

javascripts/explorer.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
const explorerUrl = process.env.NODE_ENV === 'production'
2+
? 'https://graphql.github.com/explorer'
3+
: 'http://localhost:3000'
14

5+
// Pass non-search query params to Explorer app via the iFrame
26
export default function () {
3-
// TODO support "Run in Explorer" links in GraphQL guides
4-
// will need to handle query params separately from search queries
7+
const graphiqlExplorer = document.getElementById('graphiql')
8+
const queryString = window.location.search
9+
10+
if (!(queryString && graphiqlExplorer)) return
11+
12+
window.onload = () => {
13+
graphiqlExplorer.contentWindow.postMessage(queryString, explorerUrl)
14+
}
515
}

0 commit comments

Comments
 (0)