Skip to content

Commit 8ab0100

Browse files
authored
fix initial typesync sse (#484)
1 parent eeffc5f commit 8ab0100

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

.changeset/hungry-monkeys-shine.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@graphprotocol/hypergraph": patch
3+
---
4+
5+
fixes loading the initial schema in typesync
6+

packages/hypergraph/src/cli/services/Typesync.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,18 @@ export class TypesyncSchemaStreamBuilder extends Effect.Service<TypesyncSchemaSt
185185
yield* kv.set(MAPPING_FILE_PATH_STORAGE_KEY, mappingFilePath.value);
186186
}
187187

188-
return currentSchemaStream(schemaFilePath, mappingFilePath).pipe(
189-
Stream.concat(watchSchemaStream(schemaFilePath, mappingFilePath)),
190-
Stream.map((stream) => {
191-
const jsonData = JSON.stringify(stream);
192-
const sseData = `data: ${jsonData}\n\n`;
193-
return encoder.encode(sseData);
194-
}),
188+
return Stream.concat(
189+
// This is a workaround because the browser doesn't send a message until the second message is sent.
190+
// We are sending an empty message, because then the actual first message will be the real second message and the browsers receives it.
191+
Stream.succeed(encoder.encode('data: {"types":[]}\n\n')),
192+
currentSchemaStream(schemaFilePath, mappingFilePath).pipe(
193+
Stream.concat(watchSchemaStream(schemaFilePath, mappingFilePath)),
194+
Stream.map((stream) => {
195+
const jsonData = JSON.stringify(stream);
196+
const sseData = `data: ${jsonData}\n\n`;
197+
return encoder.encode(sseData);
198+
}),
199+
),
195200
);
196201
});
197202

0 commit comments

Comments
 (0)