Closed lastmeta closed 2 years ago
Could you show some of the phoenix backend code? Right now you connect to /graphql
. Is that where your socket is mounted? The phoenix socket supports two transports, so note that the websocket transport is by default under /socket/websocket/
.
A second issue is that the Absinthe.Phoenix backend is built on top of Phoenix channels. There's a Python client for Phoenix channels. However, if you want to use this in conjunction with Absinthe.Phoenix you'll have to implement graphql subscription bookkeeping as well. That is, the same role absinthe-socket
fulfills.
Imo it makes more sense to use https://hex.pm/packages/absinthe_graphql_ws
. A graphql_ws backend written in Elixir that works in Phoenix. It doesn't use Phoenix channels as it doesn't need them. There's a Python client as well for graphql_ws.
Could you show some of the phoenix backend code?
I'm not sure what would be most useful, here's the router for graphiql
scope "/" do
pipe_through(:api)
forward("/api", Absinthe.Plug, schema: SatoriWeb.GraphQL.Schema)
forward("/graphiql", Absinthe.Plug.GraphiQL,
schema: SatoriWeb.GraphQL.Schema,
socket: SatoriWeb.UserSocket
)
end
the graphiQL website says the ws url is ws://localhost:4000/user_socket
but when I attempt that from my python client I actually get a 404
here's the entire servercode https://github.com/lastmeta/Satori/tree/main/server/satori
Looking at the server code and the python example, I think in your case the URL you should provide is ws://localhost:4000/user_socket/websocket
.
ws://localhost:4000/user_socket/websocket
of course, that takes care of it! thanks!
I want to use graphql ws subscriptions in a project I'm working on. My python client can't connect to my phx graphql absinthe websocket api. I'm actually just followed the pragmatic studios tutorial to create a graphql server, and in that tutorial they then use apollo in react to make a JS client that connects to it. I want to use a python client instead, so I made a simple one:
This client works fine when I have it connect to a little mock server I made:
But when I connect to the phx server it recognizes the connection, gives no error, but on the client side it says the server returned a 400.
There must be something really simple I'm missing, like a header or something, because what good is a graphql api if clients can't use it? Although, maybe it's a complex thing I'm missing, otherwise why would you have to use a special package to connect to Absinthe (Apollo)? Anyway, can you help me see what I'm missing?
PS in searching for a solution I found someone else who seemed to have a similar issue: https://github.com/oliyh/re-graph/issues/59 maybe that will give some insight into what I'm experiencing.