a year ago
queries and mutations work fine, but whenever I try to create a subscription I get the error referenced above. which is odd, because when I try creating a subscription in graphi I get no issues. below is the relevant code:
// Create a plain WebSocket connection to the external GraphQL server
const externalWs = new ws("wss://backboard.railway.com/graphql/v2");
// When the connection opens, send the connection_init message.
externalWs.on("open", () => {
console.log("Opened connection to external GraphQL server");
const connectionInitMsg = {
type: "connection_init",
payload: {},
};
externalWs.send(JSON.stringify(connectionInitMsg));
});
// Listen for messages from the external GraphQL server.
externalWs.on("message", (message: ws.RawData) => {
let parsedMsg;
try {
parsedMsg = JSON.parse(message.toString());
} catch (err) {
console.error("Failed to parse message from external server", err);
return;
}
// When we receive a connection_ack, send the subscription request.
if (parsedMsg.type === "connection_ack") {
const subscriptionId = Math.random().toString(36).substring(2, 15);
const query = `
subscription MyQuery($deploymentId: String!) {
deploymentLogs(deploymentId: $deploymentId) {
severity
message
}
}
`;
const subscribeMsg = {
id: subscriptionId, // Use generated ID
type: "subscribe",
payload: {
query: query,
operationName: "MyQuery",
variables: { deploymentId: data.deploymentId },
},
};
externalWs.send(JSON.stringify(subscribeMsg));5 Replies
a year ago
i must ask, what is the usecase, im intrigued
a year ago
do tell more
ok ok I will spoil the fun - I was looking through the careers page and you all mention the async project, where candidates build an app to spin containers up and down. I thought it sounded neat and wanted to build this myself. I want to add a few bells and whistles, so I thought I'd take a stab at graphQL subscriptions.
also, I understand you probably have more pressing things to focus on so don't worry about the above if you don't have time. I just thought it was odd and could possibly be a bug so I wanted to reach out