|
Hello everyone, does anybody succeeded in using subscriptions this way ? The doc's example works fine but I need to encapsulate Ariadne with Starlette or FastAPI. I tried several ways but every time, CORS does not work for subscriptions, I get a HTTP 403. Here are my attempts: Attempt 1: graphqlapp = CORSMiddleware(
GraphQL(schema, debug=True, introspection=True),
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"])
app = Starlette(debug=True)
app.mount("/graphql", graphqlapp)Attempt 2: graphqlapp = GraphQL(schema, debug=True, introspection=True)
app = Starlette(debug=True, middleware=[Middleware(CORSMiddleware,
allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])])
app.mount("/graphql", graphqlapp)Both attempts were tested with the subscription counter example using uvicorn and websockets without success. However, CORS works perfectly fine for queries and mutations. |
Answered by
rafalp
May 2, 2021
Replies: 1 comment 1 reply
|
Hey! This isn't documented anywhere on Starlette's site but you are supposed to mount WebSocket app separately: app.mount("/graphql/", graphql)
app.add_websocket_route("/graphql/", graphql.websocket_server)Your error 403 in fact is not caused by CORS (because those don't apply to the Websocket connections!) - its refusal of protocol by the server that gives 403 here. |
1 reply
Answer selected by
AlexMili
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
This isn't documented anywhere on Starlette's site but you are supposed to mount WebSocket app separately:
Your error 403 in fact is not caused by CORS (because those don't apply to the Websocket connections!) - its refusal of protocol by the server that gives 403 here.