diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c5268b3724..235a0e5c853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The version headers in this history reflect the versions of Apollo Server itself ## vNEXT - `apollo-server-koa`: The peer dependency on `koa` (added in v3.0.0) should be a `^` range dependency rather than depending on exactly one version, and it should not be automatically increased when new versions of `koa` are released. [PR #5759](https://github.com/apollographql/apollo-server/pull/5759) +- `apollo-server-fastify`: Export `ApolloServerFastifyConfig` and `FastifyContext` TypeScript types. [PR #5743](https://github.com/apollographql/apollo-server/pull/5743) ## v3.3.0 diff --git a/packages/apollo-server-fastify/src/ApolloServer.ts b/packages/apollo-server-fastify/src/ApolloServer.ts index 66176086402..10fc48f07cf 100644 --- a/packages/apollo-server-fastify/src/ApolloServer.ts +++ b/packages/apollo-server-fastify/src/ApolloServer.ts @@ -1,5 +1,6 @@ import { ApolloServerBase, + Config, convertNodeHttpToRequest, GraphQLOptions, isHttpQueryError, @@ -17,6 +18,13 @@ export interface ServerRegistration { disableHealthCheck?: boolean; } +export interface FastifyContext { + request: FastifyRequest; + reply: FastifyReply; +} + +export type ApolloServerFastifyConfig = Config; + const stringifyHealthCheck = fastJson({ type: 'object', properties: { @@ -26,12 +34,15 @@ const stringifyHealthCheck = fastJson({ }, }); -export class ApolloServer extends ApolloServerBase { +export class ApolloServer< + ContextFunctionParams = FastifyContext, +> extends ApolloServerBase { async createGraphQLServerOptions( - request?: FastifyRequest, - reply?: FastifyReply, + request: FastifyRequest, + reply: FastifyReply, ): Promise { - return this.graphQLServerOptions({ request, reply }); + const contextParams: FastifyContext = { request, reply }; + return this.graphQLServerOptions(contextParams); } public createHandler({ @@ -103,7 +114,7 @@ export class ApolloServer extends ApolloServerBase { method: ['GET', 'POST'], url: '/', preHandler, - handler: async (request: FastifyRequest, reply: FastifyReply) => { + handler: async (request, reply) => { try { const { graphqlResponse, responseInit } = await runHttpQuery( [], diff --git a/packages/apollo-server-fastify/src/index.ts b/packages/apollo-server-fastify/src/index.ts index 12f384f069d..d093ead1a5d 100644 --- a/packages/apollo-server-fastify/src/index.ts +++ b/packages/apollo-server-fastify/src/index.ts @@ -13,4 +13,9 @@ export { } from 'apollo-server-core'; // ApolloServer integration. -export { ApolloServer, ServerRegistration } from './ApolloServer'; +export { + ApolloServer, + ApolloServerFastifyConfig, + FastifyContext, + ServerRegistration, +} from './ApolloServer';