braverhealth / phoenix-socket-dart

Cross-platform and stream-based implementation of Phoenix Sockets
https://pub.dev/packages/phoenix_socket
BSD 3-Clause "New" or "Revised" License
74 stars 37 forks source link

Can I use this package with graphql package to connect to phoenix backend? #7

Closed freewebwithme closed 3 years ago

freewebwithme commented 3 years ago

Hi I am using graphql and graphql-flutter packages in my flutter project. And phoenix framework using absinthe for backend server.

I am trying to use subscription in graphql but having trouble with it. I think graphql-flutter package doesn't initialize websocket for specifically phoenix. I got this error In my server log

[info] CONNECTED TO JaangWeb.UserSocket in 116µs
  Transport: :websocket
  Serializer: Phoenix.Socket.V1.JSONSerializer
  Parameters: %{}
[error] Ranch listener JaangWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.935.0> exit with reason: {%Phoenix.Socket.InvalidMessageError{message: "missing key \"topic\""}, [{Phoenix.Socket.Message, :from_map!, 1, [file: 'lib/phoenix/socket/message.ex', line: 35]}, {Phoenix.Socket, :__in__, 2, [file: 'lib/phoenix/socket.ex', line: 466]}, {Phoenix.Endpoint.Cowboy2Handler, :websocket_handle, 2, [file: 'lib/phoenix/endpoint/cowboy2_handler.ex', line: 175]}, {:cowboy_websocket, :handler_call, 6, [file: '/home/taedori/elixir-project/jaang/deps/cowboy/src/cowboy_websocket.erl', line: 528]}, {:cowboy_http, :loop, 1, [file: '/home/taedori/elixir-project/jaang/deps/cowboy/src/cowboy_http.erl', line: 254]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}

Is this package helps with this problem?

matehat commented 3 years ago

It could, but some pieces are missing for it to work.

Subscriptions through absinthe uses Phoenix Sockets for the transport, and this repo here implements that transport protocol, but it doesn't offer anything with regards to GraphQL subscriptions specifically.

I don't think there's a lot missing though, if you're willing to dig a bit.