graphene-subscriptions
graphene-subscriptions copied to clipboard
NoneType object has no attribute 'filter' when implementing custom view
Hi, I am creating a simple project that implements both GraphQL playground as well as a Custom view (which is queried from frontend with javascript fetch API).
GraphQL Playground works with all types (query, mutation and subscription) but the Custom view doesn't work with subscription (haven't tried mutation yet) i get the following error:
Traceback (most recent call last):
File "mypath/django-graphql/venv/lib/python3.8/site-packages/graphql/execution/executor.py", line 452, in resolve_or_error
return executor.execute(resolve_fn, source, info, **args)
File "mypath/django-graphql/venv/lib/python3.8/site-packages/graphql/execution/executors/sync.py", line 16, in execute
return fn(*args, **kwargs)
File "mypath/django-graphql/django_graphql/stock/graphql/subscription.py", line 49, in resolve_vehicle_updated
return root.filter(
AttributeError: 'NoneType' object has no attribute 'filter'
I saw this suggestion so i added another path to my Custom View in routing.py
:
application = ProtocolTypeRouter({
"websocket": URLRouter([
path('graphql', GraphqlSubscriptionConsumer),
path('query', GraphqlSubscriptionConsumer)
]),
})
urls.py:
urlpatterns = [
path('', views.index, name='index'),
path('graphql', GraphQLView.as_view(graphiql=True)),
path('query', views.query_graphql, name='query') # Custom view
]
views.py
def index(request):
return render(request, "index.html")
def get_graphql_result_from(request):
result = {}
if request.method == 'POST':
body_data = json.loads(request.body.decode("utf-8"))
query = body_data['query']
result = schema.execute(query, context_value=request, allow_subscriptions=True)
result = result.data
return result
# Custom View
def query_graphql(request):
result = get_graphql_result_from(request)
return JsonResponse(result, safe=False)
I have also created a repo of the whole project : please check graphql_ui branch not master
Hi, I am creating a simple project that implements both GraphQL playground as well as a Custom view (which is queried from frontend with javascript fetch API).
GraphQL Playground works with all types (query, mutation and subscription) but the Custom view doesn't work with subscription (haven't tried mutation yet) i get the following error:
Traceback (most recent call last): File "mypath/django-graphql/venv/lib/python3.8/site-packages/graphql/execution/executor.py", line 452, in resolve_or_error return executor.execute(resolve_fn, source, info, **args) File "mypath/django-graphql/venv/lib/python3.8/site-packages/graphql/execution/executors/sync.py", line 16, in execute return fn(*args, **kwargs) File "mypath/django-graphql/django_graphql/stock/graphql/subscription.py", line 49, in resolve_vehicle_updated return root.filter( AttributeError: 'NoneType' object has no attribute 'filter'
I saw this suggestion so i added another path to my Custom View in
routing.py
:application = ProtocolTypeRouter({ "websocket": URLRouter([ path('graphql', GraphqlSubscriptionConsumer), path('query', GraphqlSubscriptionConsumer) ]), })
urls.py:
urlpatterns = [ path('', views.index, name='index'), path('graphql', GraphQLView.as_view(graphiql=True)), path('query', views.query_graphql, name='query') # Custom view ]
views.py
def index(request): return render(request, "index.html") def get_graphql_result_from(request): result = {} if request.method == 'POST': body_data = json.loads(request.body.decode("utf-8")) query = body_data['query'] result = schema.execute(query, context_value=request, allow_subscriptions=True) result = result.data return result # Custom View def query_graphql(request): result = get_graphql_result_from(request) return JsonResponse(result, safe=False)
I have also created a repo of the whole project : please check graphql_ui branch not master
Can you share your repo , did you solved it?