in src/components/operations/operation-details/ko/runtime/graphql-console.ts [676:737]
private initWebSocket(): void {
this.ws = new WebsocketClient();
this.ws.onOpen = () => {
this.wsProcessing(false);
this.wsConnected(true);
this.ws.send(JSON.stringify({
type: GqlWsMessageType.connection_init,
payload: {}
}));
this.ws.send(JSON.stringify({
type: GqlWsMessageType.subscribe,
id: "1",
payload: {
query: this.document(),
variables: this.variables() && this.variables().length > 0 ? JSON.parse(this.variables()) : null
}
}, null, 2));
};
this.ws.onLogItem = (data: LogItem) => {
if (!data) {
return;
}
if (data.logType === LogItemType.GetData) {
try {
const json = JSON.parse(data.logData);
if (json["type"] == GqlWsMessageType.next && "payload" in json) {
data.logData = JSON.stringify(json["payload"], null, 2);
this.wsLogItems.unshift(data);
}
} catch (error) {
this.logger.trackError(error, { message: `Error for ${data.logType}` });
}
}
else if (data.logType === LogItemType.SendData) {
try {
const json = JSON.parse(data.logData);
if (json["type"] == GqlWsMessageType.subscribe && "payload" in json) {
data.logData = JSON.stringify(json["payload"], null, 2);
this.wsLogItems.unshift(data);
}
} catch (error) {
this.logger.trackError(error, { message: `Error for ${data.logType}` });
}
}
else if (data.logType === LogItemType.Connection) {
if (data.logData.includes("Disconnected")) {
return;
}
if (data.logData.includes("Disconnecting from")) {
data.logData = data.logData.replace("Disconnecting", "Disconnected");
}
this.wsLogItems.unshift(data);
}
else {
this.wsLogItems.unshift(data);
}
};
this.ws.onError = (error: string) => {
this.wsProcessing(false);
this.wsConnected(false);
};
}