Skip to content

Commit

Permalink
fix(fastify): return reply object from async handlers (#6798)
Browse files Browse the repository at this point in the history
This is the recommended pattern, and will be required in Fastify 4.

Co-authored-by: David Glasser <glasser@davidglasser.net>
  • Loading branch information
SimenB and glasser authored Aug 25, 2022
1 parent 149d686 commit 70ad2f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ The version headers in this history reflect the versions of Apollo Server itself

## vNEXT

## 3.7.0 (RESTDataSource only)
## v3.10.2

- [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)
- `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)
- `apollo-datasource-rest@3.7.0`: 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)

## v3.10.1

Expand Down
14 changes: 8 additions & 6 deletions packages/apollo-server-fastify/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class ApolloServer<
if (onHealthCheck) {
try {
await onHealthCheck(request);
reply.send('{"status":"pass"}');
return reply.send('{"status":"pass"}');
} catch (e) {
reply.status(503).send('{"status":"fail"}');
return reply.status(503).send('{"status":"fail"}');
}
} else {
reply.send('{"status":"pass"}');
return reply.send('{"status":"pass"}');
}
});
}
Expand Down Expand Up @@ -94,9 +94,11 @@ export class ApolloServer<

if (prefersHtml) {
reply.type('text/html');
reply.send(landingPage.html);
return reply.send(landingPage.html);
}
}

return undefined;
}
: undefined;

Expand Down Expand Up @@ -129,7 +131,7 @@ export class ApolloServer<
}
reply.status(responseInit.status || 200);
reply.serializer((payload: string) => payload);
reply.send(graphqlResponse);
return reply.send(graphqlResponse);
} catch (error) {
if (!isHttpQueryError(error)) {
throw error;
Expand All @@ -143,7 +145,7 @@ export class ApolloServer<

reply.code(error.statusCode);
reply.serializer((payload: string) => payload);
reply.send(error.message);
return reply.send(error.message);
}
},
});
Expand Down

0 comments on commit 70ad2f1

Please sign in to comment.