Skip to content

Commit 1025f08

Browse files
committed
Allow loading graphql query from URL
1 parent bb83187 commit 1025f08

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

netbox/templates/graphql/graphiql.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@
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+
let remainingHash = "";
98+
if (hashArgs.size !== 0) {
99+
remainingHash = `#${hashArgs.toString()}`;
100+
}
101+
history.pushState("", document.title,
102+
window.location.pathname + window.location.search + remainingHash
103+
);
104+
}
105+
91106
const fetchURL = window.location.href;
92107

93108
function httpUrlToWebSockeUrl(url) {
@@ -123,6 +138,8 @@
123138
defaultEditorToolsVisibility: true,
124139
plugins: [explorerPlugin],
125140
inputValueDeprecation: true,
141+
defaultQuery: EXAMPLE_QUERY,
142+
query: sharedQuery,
126143
}),
127144
);
128145
</script>

0 commit comments

Comments
 (0)