Skip to content

Commit 9ef2b07

Browse files
committed
Allow loading graphql query from URL
1 parent bb83187 commit 9ef2b07

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

netbox/templates/graphql/graphiql.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@
8888
#
8989
`;
9090

91+
let sharedQuery;
92+
const hashArgs = new URLSearchParams(window.location.hash.substring(1));
93+
if (hashArgs.has('query')) {
94+
sharedQuery = hashArgs.get('query');
95+
// reset url to not motivate copying of stale URL
96+
hashArgs.delete('query');
97+
console.log("args size", hashArgs.size)
98+
let remainingHash = "";
99+
if (hashArgs.size !== 0) {
100+
remainingHash = `#${hashArgs.toString()}`;
101+
}
102+
history.pushState("", document.title,
103+
window.location.pathname + window.location.search + remainingHash
104+
);
105+
}
106+
91107
const fetchURL = window.location.href;
92108

93109
function httpUrlToWebSockeUrl(url) {
@@ -123,6 +139,8 @@
123139
defaultEditorToolsVisibility: true,
124140
plugins: [explorerPlugin],
125141
inputValueDeprecation: true,
142+
defaultQuery: EXAMPLE_QUERY,
143+
query: sharedQuery,
126144
}),
127145
);
128146
</script>

0 commit comments

Comments
 (0)