contra/graphql-helix

where can I find information about graphql-helix's usage of stream.write?

Opened this issue · 3 comments

I hope it is not rude to ask this question. Where can one find details about the PassThrough "write" syntax used here https://github.com/contrawork/graphql-helix/blob/master/examples/koa/server.ts/koa/server.ts#L64

const stream = new PassThrough();

stream.write(`data: ${JSON.stringify(result)}\n\n`);
stream.write("---");
stream.write(data.join("\r\n"));
stream.write("\r\n-----\r\n");

I cannot find documentation for calls like these. If I make changes to these calls, for example, if I remove one of the trailing "\n" characters or if I remove the "data: " part at the beginning, the data aren't sent to the client. Where can I find information about this?

Would you recommend a way to stream error(s) to the client? For example, if a permission or data error occurred mid-stream?

Thank you for your any response.

I seem to have found the answer to the first question -- the syntax is an SSE-specific syntax

I'm interested to know your opinion about sending errors so will leave this ticket open.

adding event: error sends the error to the client

streamPassThrough.write( `event: error\ndata: ${JSON.stringify( result )}\n\n` );

it's using a non-documented protocol, this has been addressed in a new library https://github.com/enisdenjo/graphql-sse which has a proper protocol, (shameless plug, already available in graphql-ez https://www.graphql-ez.com/plugins/sse )