Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iambumblehead opened this issue Jul 7, 2021 · 3 comments
Labels
question Further information is requested

Comments

@iambumblehead
Copy link

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.

@iambumblehead
Copy link
Author

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.

@iambumblehead
Copy link
Author

adding event: error sends the error to the client

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

@PabloSzx
Copy link
Contributor

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 )

@dotansimha dotansimha added the question Further information is requested label Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

3 participants