Skip to content

Commit a6f87b0

Browse files
authored
Merge pull request #246 from apollo-server-integrations/trevor/defer-support
Implement `@defer` support
2 parents 89046a0 + 2320e3a commit a6f87b0

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ jobs:
4343
- run: npm run test:ci
4444
- store_test_results:
4545
path: junit.xml
46+
Incremental Delivery:
47+
docker:
48+
- image: cimg/base:stable
49+
environment:
50+
INCREMENTAL_DELIVERY_TESTS_ENABLED: t
51+
steps:
52+
- setup-node:
53+
node-version: "18"
54+
# Install a prerelease of graphql-js 17 with incremental delivery support.
55+
# --legacy-peer-deps because nothing expects v17 yet.
56+
- run: npm i --legacy-peer-deps graphql@17.0.0-alpha.1.canary.pr.3361.04ab27334641e170ce0e05bc927b972991953882
57+
- run: npm run test:ci
4658
Lint:
4759
docker:
4860
- image: cimg/base:stable
@@ -69,3 +81,4 @@ workflows:
6981
- "16"
7082
- "18"
7183
- "20"
84+
- Incremental Delivery

src/handler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Readable } from "node:stream";
2+
13
import { ApolloServer, BaseContext } from "@apollo/server";
24
import type { WithRequired } from "@apollo/utils.withrequired";
35
import type {
@@ -114,8 +116,10 @@ export function fastifyApolloHandler<
114116

115117
if (body.kind === "complete") {
116118
return body.string;
117-
} else {
118-
throw new Error("Incremental delivery not implemented yet.");
119119
}
120+
121+
const readable = Readable.from(body.asyncIterator);
122+
// @ts-ignore something wrong with the `ReplyType` but not sure what
123+
return reply.send(readable);
120124
};
121125
}

tests/handler.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,4 @@ defineIntegrationTestSuite(
3434
url,
3535
};
3636
},
37-
{
38-
noIncrementalDelivery: true,
39-
},
4037
);

tests/plugin.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,4 @@ defineIntegrationTestSuite(
3434
url,
3535
};
3636
},
37-
{
38-
noIncrementalDelivery: true,
39-
},
4037
);

0 commit comments

Comments
 (0)