Skip to content

Commit 70ad2f1

Browse files
SimenBglasser
andauthored
fix(fastify): return reply object from async handlers (#6798)
This is the recommended pattern, and will be required in Fastify 4. Co-authored-by: David Glasser <[email protected]>
1 parent 149d686 commit 70ad2f1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ The version headers in this history reflect the versions of Apollo Server itself
1010

1111
## vNEXT
1212

13-
## 3.7.0 (RESTDataSource only)
13+
## v3.10.2
1414

15-
- [apollo-datasource-rest] Add option `memoizeGetRequests` to disable GET cache [PR #6650](https://github.com/apollographql/apollo-server/pull/6650) and [PR #6834](https://github.com/apollographql/apollo-server/pull/6834)
15+
- `apollo-server-fastify`: Use `return reply.send` in handlers to match the pattern encouraged by Fastify 4 (although [`apollo-server-fastify@3` only works with Fastify 3](https://github.com/apollographql/apollo-server/issues/6576#issuecomment-1159249244)). [PR #6798](https://github.com/apollographql/apollo-server/pull/6798)
16+
- `[email protected]`: Add option `memoizeGetRequests` to disable GET cache [PR #6650](https://github.com/apollographql/apollo-server/pull/6650) and [PR #6834](https://github.com/apollographql/apollo-server/pull/6834)
1617

1718
## v3.10.1
1819

packages/apollo-server-fastify/src/ApolloServer.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export class ApolloServer<
5656
if (onHealthCheck) {
5757
try {
5858
await onHealthCheck(request);
59-
reply.send('{"status":"pass"}');
59+
return reply.send('{"status":"pass"}');
6060
} catch (e) {
61-
reply.status(503).send('{"status":"fail"}');
61+
return reply.status(503).send('{"status":"fail"}');
6262
}
6363
} else {
64-
reply.send('{"status":"pass"}');
64+
return reply.send('{"status":"pass"}');
6565
}
6666
});
6767
}
@@ -94,9 +94,11 @@ export class ApolloServer<
9494

9595
if (prefersHtml) {
9696
reply.type('text/html');
97-
reply.send(landingPage.html);
97+
return reply.send(landingPage.html);
9898
}
9999
}
100+
101+
return undefined;
100102
}
101103
: undefined;
102104

@@ -129,7 +131,7 @@ export class ApolloServer<
129131
}
130132
reply.status(responseInit.status || 200);
131133
reply.serializer((payload: string) => payload);
132-
reply.send(graphqlResponse);
134+
return reply.send(graphqlResponse);
133135
} catch (error) {
134136
if (!isHttpQueryError(error)) {
135137
throw error;
@@ -143,7 +145,7 @@ export class ApolloServer<
143145

144146
reply.code(error.statusCode);
145147
reply.serializer((payload: string) => payload);
146-
reply.send(error.message);
148+
return reply.send(error.message);
147149
}
148150
},
149151
});

0 commit comments

Comments
 (0)