forked from shokai/websocket-client-simple
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hello,
Thanks for your nice gem,
I wondering if it's possible to send a graphQL query with the gem :
For the moment , i just receive the welcome and ping message of an external websocket. ref:
Here is my code :
(I also added a header and subprotocol, but not sure if it's the right way to mention it too)
In my controller :
require 'websocket-client-simple'
require 'json'
url = "wss://ws.sorare.com/cable"
subprotocol = 'actioncable-v1-json'
header = {
"Authorization" => "Bearer #{ENV['S_TKN']}"
}
query = <<-GRAPHQL
subscription {
aCardWasUpdated { slug }
}
GRAPHQL
data = { 'query' => query, 'variables' => {} }
message = { 'command' => 'subscribe', 'identifier' => { 'channel' => 'MyChannel' }, 'data' => data }.to_json
client = WebSocket::Client::Simple.connect(url, protocol: subprotocol, header: header)
client.on :open do
p "opening"
client.send message
end
client.on :message do |message|
puts "Message : #{message.data}"
end
client.on :error do |error|
puts "Erreur : #{error}"
end
Thank you
Metadata
Metadata
Assignees
Labels
No labels