graphiql.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {% load static %}
  2. {% comment %}
  3. This template derives from the strawberry-graphql project:
  4. https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/static/graphiql.html
  5. {% endcomment %}
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>GraphiQL | NetBox</title>
  10. <link
  11. rel="icon"
  12. href="data:image/svg+xml,
  13. <svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22>
  14. <!-- Strawberry Emoji as a HTML Entity (hex) -->
  15. <text y=%22.9em%22 font-size=%2280%22>&#x1f353;</text>
  16. </svg>"
  17. />
  18. <style>
  19. body {
  20. height: 100%;
  21. margin: 0;
  22. width: 100%;
  23. overflow: hidden;
  24. }
  25. #graphiql {
  26. height: 100vh;
  27. display: flex;
  28. }
  29. .docExplorerHide {
  30. display: none;
  31. }
  32. .doc-explorer-contents {
  33. overflow-y: hidden !important;
  34. }
  35. .docExplorerWrap {
  36. width: unset !important;
  37. min-width: unset !important;
  38. }
  39. .graphiql-explorer-actions select {
  40. margin-left: 4px;
  41. }
  42. </style>
  43. <script src="{% static 'graphiql/react.production.min.js' %}"></script>
  44. <script src="{% static 'graphiql/react-dom.production.min.js' %}"></script>
  45. <script src="{% static 'graphiql/js.cookie.min.js' %}"></script>
  46. <link rel="stylesheet" href="{% static 'graphiql/graphiql.min.css' %}"/>
  47. <link rel="stylesheet" href="{% static 'graphiql/plugin-explorer-style.css' %}"/>
  48. </head>
  49. <body>
  50. <div id="graphiql" class="graphiql-container">Loading...</div>
  51. <script src="{% static 'graphiql/graphiql.min.js' %}"></script>
  52. <script src="{% static 'graphiql/index.umd.js' %}"></script>
  53. <script>
  54. const EXAMPLE_QUERY = `# Welcome to GraphiQL 🍓
  55. #
  56. # GraphiQL is an in-browser tool for writing, validating, and
  57. # testing GraphQL queries.
  58. #
  59. # Type queries into this side of the screen, and you will see intelligent
  60. # typeaheads aware of the current GraphQL type schema and live syntax and
  61. # validation errors highlighted within the text.
  62. #
  63. # GraphQL queries typically start with a "{" character. Lines that starts
  64. # with a # are ignored.
  65. #
  66. # An example GraphQL query might look like:
  67. #
  68. # {
  69. # field(arg: "value") {
  70. # subField
  71. # }
  72. # }
  73. #
  74. # Keyboard shortcuts:
  75. #
  76. # Run Query: Ctrl-Enter (or press the play button above)
  77. #
  78. # Auto Complete: Ctrl-Space (or just start typing)
  79. #
  80. `;
  81. const fetchURL = window.location.href;
  82. function httpUrlToWebSockeUrl(url) {
  83. const parsedURL = new URL(url);
  84. const protocol = parsedURL.protocol === "http:" ? "ws:" : "wss:";
  85. parsedURL.protocol = protocol;
  86. parsedURL.hash = "";
  87. return parsedURL.toString();
  88. }
  89. const headers = {};
  90. const csrfToken = Cookies.get("csrftoken");
  91. if (csrfToken) {
  92. headers["x-csrftoken"] = csrfToken;
  93. }
  94. const subscriptionUrl = httpUrlToWebSockeUrl(fetchURL);
  95. const fetcher = GraphiQL.createFetcher({
  96. url: fetchURL,
  97. headers: headers,
  98. subscriptionUrl,
  99. });
  100. const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
  101. const root = ReactDOM.createRoot(document.getElementById("graphiql"));
  102. root.render(
  103. React.createElement(GraphiQL, {
  104. fetcher: fetcher,
  105. defaultEditorToolsVisibility: true,
  106. plugins: [explorerPlugin],
  107. inputValueDeprecation: true,
  108. }),
  109. );
  110. </script>
  111. </body>
  112. </html>