Comments (16)
just discovered graphene and though of evaluating state of graphql integration with django.
this might a bit late though:
For short:
- To resolve
Subscriptions are not allowed. You will need to either use the subscribe function or pass allow_subscriptions=True
after navigating the call stack I found we can pass a custom backend to GraphQLView that can custom exc_context parameters.
from graphql.backend import GraphQLCoreBackend
class GraphQLCustomCoreBackend(GraphQLCoreBackend):
def __init__(self, executor=None):
# type: (Optional[Any]) -> None
super().__init__(executor)
self.execute_params['allow_subscriptions'] = True
- Same way, used
MIDDLEWARE: []
inGRAPHENE
settings. as OP. - To resolve 'AnonymousObservable' object has no attribute 'errors'. a custom view can to be defined that would unbox
execution_result
from the Observable. (this is hacky) Using ExtraGraphQLView, AuthenticatedGraphQLView outlined in eamigo86/graphene-django-subscriptions#2 didn't work for me as they just as GraphQLView don't handle observables returned fromexecute_graphql_request
which is from graphql/execution/executor.py#L265
class GraphQLObservableUnboxingView(GraphQLView):
def execute_graphql_request(
self, request, data, query, variables, operation_name, show_graphiql=False
):
target_result = None
def override_target_result(value):
nonlocal target_result
target_result = value
execution_result = super().execute_graphql_request(request, data, query, variables, operation_name, show_graphiql)
if execution_result:
if isinstance(execution_result, ObservableBase):
target = execution_result.subscribe(on_next=lambda value: override_target_result(value))
target.dispose()
else:
return execution_result
return target_result
So in urls.py it can be:
url(r'^graphql', GraphQLObservableUnboxingView.as_view(graphiql=True, backend=GraphQLCustomCoreBackend()))
I have not used django channels and just tried reproducing the most possible minimal example so that subscription can be resolved:
subscription{
subscribeToFoo(id: 1)
}
from rx import Observable
class Subscription(graphene.ObjectType):
subscribe_to_foo = graphene.Boolean(id=graphene.Int())
def resolve_subscribe_to_foo(self, args, **kwargs):
return Observable.of(True)
schema = graphene.Schema(query=Query, subscription=Subscription)
also please make sure you are using rxpy 1.6.*
from graphql-ws.
Hello there,
I am trying to call a subscription from PostMan, but whenever run got is error
{ "errors": [ { "message": "Subscription must return Async Iterable or Observable. Received: <Promise at 0x2940d9c7cd0 rejected with AttributeError(\"'NoneType' object has no attribute 'register_subscription'\")>" } ], "data": null }
even when I did the same step as @ambientlight did. I can't find any solution for that any help please!
from graphql-ws.
@arturataide I ended up using this: https://github.com/datadvance/DjangoChannelsGraphqlWs
from graphql-ws.
I have experienced exactly the same today, but after seeing your issue I have stopped trying already after the second step.
from graphql-ws.
I'm whiling to help, but I don't understand too much about the Observables :(
from graphql-ws.
I've checked that DjangoDebugMiddleware
returns promise, so it cannot be set together with subscriptions and observables. But AnonymousObservable' object has no attribute 'errors
still occures even when I added field errors
to observable. I think that it's graphene bug (?). But I still really need to add subscriptions to my django app (graphene-django, python). Do you have any thoughts how can I do this? I know graphene-django-subscriptions
lib, but does it really necessery to use serializer class only in case of subscriptions? Please, a little help will be desirable.
from graphql-ws.
@jonatasbaldin which version of channels are you using?
from graphql-ws.
Changing the urls.py it's solved
eamigo86/graphene-django-subscriptions#2
from graphql-ws.
I'm stuck on the AnonymousObserable issue as well. https://github.com/xDHILEx/graphqlwsdjangochannels. @colanconnon I'm using channels 1.1.8
from graphql-ws.
@xDHILEx I will have to look at this closer when I have some time
from graphql-ws.
Has anyone managed to solve this? I'm getting the same issue.
from graphql-ws.
what is it ObservableBase?
from graphql-ws.
@ambientlight your solution seems to work when MIDDLEWARE: [ ], but since I'm using 'graphql_jwt.middleware.JSONWebTokenMiddleware', the rest of queries and mutations throws a Not logged in Error...
from graphql-ws.
@phjocoronel2806: ObservableBase
is from rxpy
: https://github.com/ReactiveX/RxPY/blob/release/v1.6.x/rx/core/observablebase.py
@carlosalvarez91: haven't used any middleware with the above test so cannot yet give you any feedback on this.
from graphql-ws.
@carlosalvarez91 same issue as you.. Did you come up with any solution?
from graphql-ws.
Django v2+ version now merged to master
from graphql-ws.
Related Issues (20)
- Unbreakable flask_gevent subscription resolving HOT 4
- graphql-core v3? HOT 2
- Flask SocketIO Implementation
- test graphql-ws subscription HOT 1
- GeventSubscriptionServer ignore schema validation errors
- detect disconnect
- Django Channels Instructions/Support is Outdated HOT 5
- Is graphql-ws dead? HOT 2
- Release current master branch to pypi HOT 2
- Update to graphene v3 ? HOT 8
- Error running Django with graphql-ws HOT 3
- Using Django's GenericForeignKey with Async Graphene Subscription
- channels 3 compatibility HOT 1
- Deep nested objects in django won't work due to async HOT 6
- [Question] How to get payload on connect in aiohttp
- Impossible to use HTTP Headers with GraphIQL when using graphql-ws
- graphql-ws-next HOT 4
- No module named 'graphql.execution.executors' using graphql-ws HOT 2
- 403 error (failing WebSocket opening handshake ('Access denied'))
- using this with signals
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-ws.