Просмотр исходного кода

#6834: Add title, favicon to GraphiQL view

jeremystretch 4 лет назад
Родитель
Сommit
81e1b7490e

+ 2 - 0
netbox/netbox/graphql/views.py

@@ -12,6 +12,8 @@ class GraphQLView(GraphQLView_):
     """
     Extends graphene_django's GraphQLView to support DRF's token-based authentication.
     """
+    graphiql_template = 'graphiql.html'
+
     def dispatch(self, request, *args, **kwargs):
 
         # Enforce GRAPHQL_ENABLED

BIN
netbox/project-static/img/graphql.ico


+ 59 - 0
netbox/templates/graphiql.html

@@ -0,0 +1,59 @@
+{% comment %}
+  This template derives from the graphene-django project:
+  https://github.com/graphql-python/graphene-django/blob/main/graphene_django/templates/graphene/graphiql.html
+{% endcomment %}
+<!--
+The request to this GraphQL server provided the header "Accept: text/html"
+and as a result has been presented GraphiQL - an in-browser IDE for
+exploring GraphQL.
+If you wish to receive JSON, provide the header "Accept: application/json" or
+add "&raw" to the end of the URL within a browser.
+-->
+{% load static %}
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <style>
+      html, body, #editor {
+        height: 100%;
+        margin: 0;
+        overflow: hidden;
+        width: 100%;
+      }
+    </style>
+    <link href="https://cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.min.css"
+          integrity="{{graphiql_css_sri}}"
+          rel="stylesheet"
+          crossorigin="anonymous" />
+    <script src="https://cdn.jsdelivr.net/npm/whatwg-fetch@{{whatwg_fetch_version}}/dist/fetch.umd.js"
+            integrity="{{whatwg_fetch_sri}}"
+            crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/react@{{react_version}}/umd/react.production.min.js"
+            integrity="{{react_sri}}"
+            crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/react-dom@{{react_version}}/umd/react-dom.production.min.js"
+            integrity="{{react_dom_sri}}"
+            crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.min.js"
+            integrity="{{graphiql_sri}}"
+            crossorigin="anonymous"></script>
+    <script src="https://cdn.jsdelivr.net/npm/subscriptions-transport-ws@{{subscriptions_transport_ws_version}}/browser/client.js"
+            integrity="{{subscriptions_transport_ws_sri}}"
+            crossorigin="anonymous"></script>
+    <link rel="icon" type="image/png" href="{% static 'graphql.ico' %}" />
+    <title>GraphiQL | NetBox</title>
+  </head>
+  <body>
+    <div id="editor"></div>
+    {% csrf_token %}
+    <script type="application/javascript">
+      window.GRAPHENE_SETTINGS = {
+      {% if subscription_path %}
+        subscriptionPath: "{{subscription_path}}",
+      {% endif %}
+        graphiqlHeaderEditorEnabled: {{ graphiql_header_editor_enabled|yesno:"true,false" }},
+      };
+    </script>
+    <script src="{% static 'graphene_django/graphiql.js' %}"></script>
+  </body>
+</html>