diff --git a/examples/cookbook/cookbook/urls.py b/examples/cookbook/cookbook/urls.py index 0bc7578..9410ca5 100644 --- a/examples/cookbook/cookbook/urls.py +++ b/examples/cookbook/cookbook/urls.py @@ -1,7 +1,6 @@ -from django.conf.urls import include, url +from django.conf.urls import url from django.contrib import admin -from cookbook.schema import schema from graphene_django.views import GraphQLView urlpatterns = [ diff --git a/examples/starwars/schema.py b/examples/starwars/schema.py index affb3f4..0ff95c5 100644 --- a/examples/starwars/schema.py +++ b/examples/starwars/schema.py @@ -1,6 +1,6 @@ import graphene from graphene import Schema, relay, resolve_only_args -from graphene_django import DjangoObjectType, DjangoConnectionField +from graphene_django import DjangoConnectionField, DjangoObjectType from .data import (create_ship, get_empire, get_faction, get_rebels, get_ship, get_ships) diff --git a/graphene_django/management/commands/graphql_schema.py b/graphene_django/management/commands/graphql_schema.py index 405c9ed..209dbca 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -32,7 +32,6 @@ else: class CommandArguments(BaseCommand): def add_arguments(self, parser): - from django.conf import settings parser.add_argument( '--schema', type=str, @@ -57,7 +56,6 @@ class Command(CommandArguments): json.dump(schema_dict, outfile) def handle(self, *args, **options): - from django.conf import settings options_schema = options.get('schema') if options_schema: schema = importlib.import_module(options_schema) diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 6452907..5cbecca 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -43,7 +43,6 @@ IMPORT_STRINGS = ( ) - def perform_import(val, setting_name): """ If the given setting is a string import notation, @@ -82,6 +81,7 @@ class GrapheneSettings(object): Any setting with string import paths will be automatically resolved and return the class, rather than the string literal. """ + def __init__(self, user_settings=None, defaults=None, import_strings=None): if user_settings: self._user_settings = user_settings diff --git a/graphene_django/tests/schema_view.py b/graphene_django/tests/schema_view.py index cf81153..429a9f8 100644 --- a/graphene_django/tests/schema_view.py +++ b/graphene_django/tests/schema_view.py @@ -1,8 +1,5 @@ import graphene -from graphene import Schema, ObjectType, relay - -from ..types import DjangoObjectType -from .models import Article, Reporter +from graphene import ObjectType, Schema class QueryRoot(ObjectType): @@ -10,10 +7,10 @@ class QueryRoot(ObjectType): thrower = graphene.String(required=True) request = graphene.String(required=True) test = graphene.String(who=graphene.String()) - + def resolve_thrower(self, args, context, info): raise Exception("Throws!") - + def resolve_request(self, args, context, info): request = context return request.GET.get('q') diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 0c50477..81402fc 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -19,7 +19,6 @@ from .models import Article, Film, FilmDetails, Reporter # from graphene.core.types.custom_scalars import DateTime, JSONString - def assert_conversion(django_field, graphene_field, *args, **kwargs): field = django_field(help_text='Custom Help Text', *args, **kwargs) graphene_type = convert_django_field(field) diff --git a/graphene_django/tests/test_views.py b/graphene_django/tests/test_views.py index ebb518f..1f9b5de 100644 --- a/graphene_django/tests/test_views.py +++ b/graphene_django/tests/test_views.py @@ -1,6 +1,7 @@ -import pytest import json +import pytest + try: from urllib import urlencode except ImportError: diff --git a/graphene_django/tests/urls.py b/graphene_django/tests/urls.py index 8613311..ff4459e 100644 --- a/graphene_django/tests/urls.py +++ b/graphene_django/tests/urls.py @@ -1,4 +1,5 @@ from django.conf.urls import url + from ..views import GraphQLView urlpatterns = [ diff --git a/graphene_django/tests/urls_pretty.py b/graphene_django/tests/urls_pretty.py index 2d83ff5..670acce 100644 --- a/graphene_django/tests/urls_pretty.py +++ b/graphene_django/tests/urls_pretty.py @@ -1,4 +1,5 @@ from django.conf.urls import url + from graphql_django_view import GraphQLView from .schema_view import schema diff --git a/graphene_django/views.py b/graphene_django/views.py index 1c127fd..e2d6ffe 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -1,23 +1,25 @@ -import re import json -import six +import re +import six from django.http import HttpResponse, HttpResponseNotAllowed from django.http.response import HttpResponseBadRequest -from django.views.generic import View from django.shortcuts import render +from django.views.generic import View -from graphql import Source, parse, execute, validate -from graphql.error import GraphQLError, format_error as format_graphql_error +from graphql import Source, execute, parse, validate +from graphql.error import format_error as format_graphql_error +from graphql.error import GraphQLError from graphql.execution import ExecutionResult -from graphql.type.schema import GraphQLSchema from graphql.execution.middleware import MiddlewareManager +from graphql.type.schema import GraphQLSchema from graphql.utils.get_operation_ast import get_operation_ast from .settings import graphene_settings class HttpError(Exception): + def __init__(self, response, message=None, *args, **kwargs): self.response = response self.message = message = message or response.content.decode() @@ -192,7 +194,7 @@ class GraphQLView(View): if operation_ast and operation_ast.operation != 'query': if show_graphiql: return None - + raise HttpError(HttpResponseNotAllowed( ['POST'], 'Can only perform a {} operation from a POST request.'.format(operation_ast.operation) ))