From 76173ebdd2932a03e9a22e13149ea5a0219b253e Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 15 Aug 2025 10:51:36 +0200 Subject: [PATCH 1/2] fix SSE by sending an empty message in the beginning so the first real message is the second one and the browser receives it --- .../hypergraph/src/cli/services/Typesync.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/hypergraph/src/cli/services/Typesync.ts b/packages/hypergraph/src/cli/services/Typesync.ts index 0798e9e6..4f06d2ab 100644 --- a/packages/hypergraph/src/cli/services/Typesync.ts +++ b/packages/hypergraph/src/cli/services/Typesync.ts @@ -185,13 +185,18 @@ export class TypesyncSchemaStreamBuilder extends Effect.Service { - const jsonData = JSON.stringify(stream); - const sseData = `data: ${jsonData}\n\n`; - return encoder.encode(sseData); - }), + return Stream.concat( + // This is a workaround because the browser doesn't send a message until the second message is sent. + // We are sending an empty message, because then the actual first message will be the real second message and the browsers receives it. + Stream.succeed(encoder.encode('data: {"types":[]}\n\n')), + currentSchemaStream(schemaFilePath, mappingFilePath).pipe( + Stream.concat(watchSchemaStream(schemaFilePath, mappingFilePath)), + Stream.map((stream) => { + const jsonData = JSON.stringify(stream); + const sseData = `data: ${jsonData}\n\n`; + return encoder.encode(sseData); + }), + ), ); }); From 934aaf20dcdeda752b050550be7d0855bf649413 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Fri, 15 Aug 2025 10:52:20 +0200 Subject: [PATCH 2/2] fix loading the initial schema in typesync --- .changeset/hungry-monkeys-shine.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/hungry-monkeys-shine.md diff --git a/.changeset/hungry-monkeys-shine.md b/.changeset/hungry-monkeys-shine.md new file mode 100644 index 00000000..dbefd182 --- /dev/null +++ b/.changeset/hungry-monkeys-shine.md @@ -0,0 +1,6 @@ +--- +"@graphprotocol/hypergraph": patch +--- + +fixes loading the initial schema in typesync + \ No newline at end of file