test move to v2.8.2; try to bubble up template source to settings

This commit is contained in:
Joe Rhodes 2020-03-11 16:34:23 -04:00
parent da705ee1ee
commit 14a1083e8c
5 changed files with 29 additions and 46 deletions

View File

@ -1,7 +1,7 @@
import binascii
from django import forms
from django.core.exceptions import ValidationError
from django import forms
from django.forms import CharField, Field, MultipleChoiceField
from django.utils.translation import gettext_lazy as _
@ -28,19 +28,6 @@ class GlobalIDFormField(Field):
return value
class GlobalIDMultipleChoiceField(MultipleChoiceField):
default_error_messages = {
"invalid_choice": _("One of the specified IDs was invalid (%(value)s)."),
"invalid_list": _("Enter a list of values."),
}
def valid_value(self, value):
# Clean will raise a validation error if there is a problem
GlobalIDFormField().clean(value)
return True
class HeaderForm(forms.Form):
# make a ChoiceField for 'JWT' and other methods -- use a widget?
headers = forms.CharField(help_text="Enter auth method to be stored in the <head> as HTTP_AUTHORIZATION", initial="JWT ")
@ -52,3 +39,4 @@ class HeaderForm(forms.Form):
# Remember to always return the cleaned data.
return data

View File

@ -36,13 +36,14 @@ DEFAULTS = {
# Max items returned in ConnectionFields / FilterConnectionFields
"RELAY_CONNECTION_MAX_LIMIT": 100,
"CAMELCASE_ERRORS": False,
"SOURCE": None
}
if settings.DEBUG:
DEFAULTS["MIDDLEWARE"] += ("graphene_django.debug.DjangoDebugMiddleware",)
# List of settings that may be in string import notation.
IMPORT_STRINGS = ("MIDDLEWARE", "SCHEMA")
IMPORT_STRINGS = ("MIDDLEWARE", "SCHEMA", "SOURCE")
def perform_import(val, setting_name):

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body {
html, body, #editor {
height: 100%;
margin: 0;
overflow: hidden;
@ -14,29 +14,11 @@
}
</style>
{% if 'cdn' == TEMPLATE_SOURCE %}
<link href="https://cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.css"
rel="stylesheet"
crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/whatwg-fetch@2.0.3/fetch.min.js"
integrity="sha384-dcF7KoWRaRpjcNbVPUFgatYgAijf8DqW6NWuqLdfB5Sb4Cdbb8iHX7bHsl9YhpKa"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react@{{react_version}}/umd/react.production.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@{{react_version}}/umd/react-dom.production.min.js"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/graphiql@{{graphiql_version}}/graphiql.min.js"
crossorigin="anonymous"></script>
{% endif %}
{% if 'static' == TEMPLATE_SOURCE %}
<link rel="stylesheet" href={% static "graphiql/css/graphiql.css" %}>
<script src={%static "graphiql/js/fetch.min.js" %}></script>
<script src={%static "graphiql/js/react.production.min.js" %}></script>
<script src={%static "graphiql/js/react-dom.production.min.js" %}></script>
<script src={%static "graphiql/js/graphiql.min.js" %}></script>
{% endif %}
<link rel="stylesheet" href={% static "graphiql/css/graphiql.css" %}>
<script src={%static "graphiql/js/fetch.min.js" %}></script>
<script src={%static "graphiql/js/react.production.min.js" %}></script>
<script src={%static "graphiql/js/react-dom.production.min.js" %}></script>
<script src={%static "graphiql/js/graphiql.min.js" %}></script>
<title>{% block title %}{% endblock %}</title>
<meta name="Authorization" content="{% block additional_headers %}{% endblock %}">

View File

@ -6,6 +6,7 @@
{% block additional_headers %}{{ auth_header }}{% endblock %}
{% block content %}
<div id="editor"></div>
{% csrf_token %}
<script src="{% static 'graphene_django/graphiql.js' %}"></script>
{% endblock %}

View File

@ -18,7 +18,7 @@ from graphql.execution import ExecutionResult
from graphql.type.schema import GraphQLSchema
from graphene_django.settings import graphene_settings
from graphene_django.forms.forms import HeaderForm
class HttpError(Exception):
def __init__(self, response, message=None, *args, **kwargs):
@ -97,7 +97,7 @@ class GraphQLView(APIView):
assert isinstance(
self.schema, GraphQLSchema
), "A Schema is required to be provided to GraphQLView."
assert not all((graphiql, batch)), "Use either graphiql or batch processing"
assert not all((graphiql_headers, graphiql, batch)), "Use either graphiql, graphiql_headers, or batch processing"
# noinspection PyUnusedLocal
def get_root_value(self, request):
@ -114,9 +114,18 @@ class GraphQLView(APIView):
@method_decorator(ensure_csrf_cookie)
def dispatch(self, request, *args, **kwargs):
GET_FROM_CDN = kwargs.get('GET_FROM_CDN', None)
if GET_FROM_CDN is None:
GET_FROM_CDN = 'static' # this is diconnected
# if specified in settings.py:
# GRAPHENE = {
# why does this not make it????
# 'SOURCE': 'cdn'
# }
try:
GET_FROM_CDN = graphene_settings.SOURCE # get IF it exists
if GET_FROM_CDN is None:
# should not need
GET_FROM_CDN = 'static'
except:
GET_FROM_CDN = 'static' # this is diconnected by default
graphiql_arguments = {}
if GET_FROM_CDN == 'cdn':
@ -128,7 +137,7 @@ class GraphQLView(APIView):
graphiql_arguments.update({'graphiql_template': 'graphene/graphiql.html'})
graphiql_arguments.update({'TEMPLATE_SOURCE': 'static'})
else:
print('Unsuppored option in setting. Choose <cdn> or <static>')
print('The option %s is unsuppored option in setting. Choose <cdn> or <static>' % GET_FROM_CDN)
try:
if request.method.lower() not in ("get", "post"):
@ -386,6 +395,8 @@ class GraphQLView(APIView):
return content_type.split(";", 1)[0].lower()
def _get_auth_header(iQLView, request, graphiql_arguments):
from libs.graphene_django_auth.forms import HeaderForm
# If this is a POST request then process the Form data
if request.method == 'POST':
@ -396,7 +407,7 @@ def _get_auth_header(iQLView, request, graphiql_arguments):
if form.is_valid():
# process the data in form.cleaned_data as required (here we just write it to the model due_back field)
auth_header = form.cleaned_data['headers']
# return extra stuff to put in META tag for graphiql:
request.session['HTTP_AUTHORIZATION'] = auth_header
request.session['use_graphiql'] = True