Skip to content

Commit 77c332c

Browse files
committed
support graphql-sse
1 parent 47cae71 commit 77c332c

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

packages/graphiql-toolkit/src/create-fetcher/create-sse-fetcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import type {
55
} from 'graphql-sse';
66
import { Fetcher, FetcherParams } from './types';
77

8+
/**
9+
* Based on https://gist.github.com/enisdenjo/d7bc1a013433502349d2763c3d2f2b79
10+
*/
811
export async function createSseFetcher(opts: ClientOptions): Promise<Fetcher> {
912
const { createClient } =
1013
process.env.USE_IMPORT === 'false'

packages/graphiql/cypress/e2e/graphql-ws.cy.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
describe('IncrementalDelivery support via fetcher', () => {
2+
function assertResponse() {
3+
for (const message of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
4+
cy.assertQueryResult({ data: { message } });
5+
}
6+
}
7+
8+
it('should work with ws', () => {
9+
const testSubscription = /* GraphQL */ `
10+
subscription TestSubscription {
11+
message
12+
}
13+
`;
14+
15+
cy.visit(`/?query=${testSubscription}`);
16+
cy.clickExecuteQuery();
17+
assertResponse();
18+
});
19+
20+
it('should work with sse', () => {
21+
const testSubscription = /* GraphQL */ `
22+
subscription Test {
23+
message
24+
}
25+
`;
26+
27+
cy.visit(
28+
`/?sseUrl=http://localhost:8080/graphql/stream&query=${testSubscription}`,
29+
);
30+
cy.clickExecuteQuery();
31+
assertResponse();
32+
});
33+
});

packages/graphiql/test/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ const TestSubscriptionType = new GraphQLObjectType({
374374
},
375375
async *subscribe(root, args) {
376376
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
377-
if (args?.delay) {
377+
if (args.delay) {
378378
await sleep(args.delay);
379379
}
380380
yield { message: hi };

0 commit comments

Comments
 (0)