我正在尝试使用普通javascript进行aws-appsync连接。建立连接并接收消息-数据:“ {” type“:” ka“}”。但是,当我尝试发送数据以开始订阅时,出现错误-
data: "{\"type\":\"error\",\"payload\":{\"errors\":[{\"errorType\":\"UnsupportedOperation\",\"message\":\"unknown not supported through the realtime channel\"}]}}"
这是一个用于测试订阅的简单脚本。标头和有效负载是base64编码的。遵循this AWS文档进行订阅。
<html>
Hello World
<button onClick="subscribeToEvt()">Click here to Subscribe</button>
<script type="text/javascript">
var Socket = new WebSocket("wss://XXXXXXXXXX.appsync-realtime-api.us-west-2.amazonaws.com/graphql?header=eyAiXXXXXXXXXXXXXXXXXXXXXXXIiB9&payload=e30=", "graphql-ws");
Socket.onopen = function(evt) {
console.log(evt);
// Web Socket is connected, send data using send()
Socket.send("{ \"type\": \"connection_init\" }");
alert("Message is sent...");
};
Socket.onmessage = function (evt) {
var received_msg = evt.data;
console.log(evt);
alert("Message is received...");
};
function subscribeToEvt(){
Socket.send("{\"id\":\"1\",\"type\":\"start\",\"payload\":{\"variables\":{\"sessionID\":\"659d86ae-ec0c-4170-9866-b436a981ce29\"},\"extensions\":{\"authorization\":{\"host\":\"XXXXXXXXXX.appsync-api.us-west-2.amazonaws.com\",\"x-api-key\":\"XXXXXXXXXX\"}},\"operationName\":\"routeOrder\",\"query\":\"subscription routeOrder {\\n routeOrder {\\n id\\n site_id\\n route_id\\n driver_id\\n truck_id\\n \\n }\\n}\\n\",\"data\":\"{\\\"variables\\\":{\\\"sessionID\\\":\\\"659d86ae-ec0c-4170-9866-b436a981ce29\\\"},\\\"extensions\\\":{},\\\"operationName\\\":\\\"routeOrder\\\",\\\"query\\\":\\\"subscription routeOrder { \\n routeOrder {\\n id\\n site_id\\n route_id\\n driver_id\\n truck_id\\n }\\n }\\\", }n}n\\\"}");
alert('sent');
}
</script>
</html>
答案 0 :(得分:0)
见https://forums.aws.amazon.com/message.jspa?messageID=935705 - 结论是
<块引用>要让 AppSync 订阅与 subscription-transport-ws 一起使用,您需要按照此 GitHub 问题中的说明进行操作:https://github.com/apollographql/apollo-feature-requests/issues/224