Skip to content

Commit

Permalink
apollo-server-fastify: drop dependency on fast-json-stringify
Browse files Browse the repository at this point in the history
This package was being used only to stringify two small constant
objects. It has a major version update available and rather than
evaluate the CHANGELOG, we might as well just not use it.

(Honestly I think it would be fine to just use JSON.stringify here; I
don't see any justification in #1971 for why this particular use case
requires a faster stringification than all the other JSON
stringification we do in Apollo Server. But just in case this matters to
anybody, I went with the fastest possible way of converting a constant
object to string.)

This should replace #5985.
  • Loading branch information
glasser committed Jan 5, 2022
1 parent fd9597d commit a735efa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ The version headers in this history reflect the versions of Apollo Server itself
- [`@apollo/gateway`](https://github.com/apollographql/federation/blob/HEAD/gateway-js/CHANGELOG.md)
- [`@apollo/federation`](https://github.com/apollographql/federation/blob/HEAD/federation-js/CHANGELOG.md)

## vNEXT

- `apollo-server-fastify`: Drop dependency on `fast-json-stringify`. [PR #FIXME](https://github.com/apollographql/apollo-server/pull/FIXME)

## v3.6.1

- Correctly remove dependency on `apollo-graphql` as intended in v3.6.0. [Issue #5981](https://github.com/apollographql/apollo-server/issues/5981) [PR #5981](https://github.com/apollographql/apollo-server/pull/5981)
Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/apollo-server-fastify/package.json
Expand Up @@ -28,7 +28,6 @@
"dependencies": {
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-types": "file:../apollo-server-types",
"fast-json-stringify": "^2.7.6",
"fastify-accepts": "^2.0.1",
"fastify-cors": "^6.0.0"
},
Expand Down
16 changes: 3 additions & 13 deletions packages/apollo-server-fastify/src/ApolloServer.ts
Expand Up @@ -9,7 +9,6 @@ import {
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
import accepts from 'fastify-accepts';
import fastifyCors from 'fastify-cors';
import fastJson from 'fast-json-stringify';

export interface ServerRegistration {
path?: string;
Expand All @@ -25,15 +24,6 @@ export interface FastifyContext {

export type ApolloServerFastifyConfig = Config<FastifyContext>;

const stringifyHealthCheck = fastJson({
type: 'object',
properties: {
status: {
type: 'string',
},
},
});

export class ApolloServer<
ContextFunctionParams = FastifyContext,
> extends ApolloServerBase<ContextFunctionParams> {
Expand Down Expand Up @@ -66,12 +56,12 @@ export class ApolloServer<
if (onHealthCheck) {
try {
await onHealthCheck(request);
reply.send(stringifyHealthCheck({ status: 'pass' }));
reply.send('{"status":"pass"}');
} catch (e) {
reply.status(503).send(stringifyHealthCheck({ status: 'fail' }));
reply.status(503).send('{"status":"fail"}');
}
} else {
reply.send(stringifyHealthCheck({ status: 'pass' }));
reply.send('{"status":"pass"}');
}
});
}
Expand Down

0 comments on commit a735efa

Please sign in to comment.