Fixed middleware

This commit is contained in:
Syrus Akbary 2016-09-19 22:33:46 -07:00
parent 70dbd4b512
commit 8caa2cd00f
2 changed files with 14 additions and 2 deletions

View File

@ -1,11 +1,13 @@
import cookbook.ingredients.schema
import graphene
from graphene_django.debug import DjangoDebug
# print cookbook.ingredients.schema.Query._meta.graphql_type.get_fields()['allIngredients'].args
class Query(cookbook.ingredients.schema.Query, graphene.ObjectType):
pass
debug = graphene.Field(DjangoDebug, name='__debug')
schema = graphene.Schema(query=Query)

View File

@ -1,3 +1,4 @@
import inspect
import json
import re
@ -42,6 +43,14 @@ def get_accepted_content_types(request):
key=lambda x: x[1], reverse=True))
def instantiate_middleware(middlewares):
for middleware in middlewares:
if inspect.isclass(middleware):
yield middleware()
continue
yield middleware
class GraphQLView(View):
graphiql_version = '0.7.8'
graphiql_template = 'graphene/graphiql.html'
@ -60,7 +69,8 @@ class GraphQLView(View):
middleware = graphene_settings.MIDDLEWARE
self.schema = schema
self.middleware = MiddlewareManager(middleware)
if middleware is not None:
self.middleware = MiddlewareManager(*list(instantiate_middleware(middleware)))
self.executor = executor
self.root_value = root_value
self.pretty = pretty