Skip to content

Commit

Permalink
Fix formatResponse typings (#5089)
Browse files Browse the repository at this point in the history
This typing was added in #3431; it looks like we put the `| null` in the wrong
place. Fortunately, a function that's OK with accepting a null argument and will
never return null can still typecheck with the new type.

Fixes #5009.
  • Loading branch information
glasser authored Apr 6, 2021
1 parent df06a7c commit ad4c3ac
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The version headers in this history reflect the versions of Apollo Server itself
- `apollo-server-core`: Add optional argument to `ApolloServer.executeOperation` allowing the caller to manually specify an argument to the `config` function analogous to that provided by integration packages. [PR #4166](https://github.com/apollographql/apollo-server/pull/4166) [Issue #2886](https://github.com/apollographql/apollo-server/issues/2886)
- `apollo-server-cache-redis`: New `BaseRedisCache` class which takes an `ioredis`-compatible Redis client as an argument. The existing classes `RedisCache` and `RedisClusterCache` (which pass their arguments to `ioredis` constructors) are now implemented in terms of this class. This allows you to use any of the `ioredis` constructor forms rather than just the ones recognized by our classes. This also fixes a long-standing bug where the Redis cache implementations returned a number from `delete()`; it now returns a number, matching what the `KeyValueCache` interface and the TypeScript types expect. [PR #5034](https://github.com/apollographql/apollo-server/pull/5034) [PR #5088](https://github.com/apollographql/apollo-server/pull/5088) [Issue #4870](https://github.com/apollographql/apollo-server/issues/4870) [Issue #5006](https://github.com/apollographql/apollo-server/issues/5006)
- `apollo-server-core`: Fix type for `formatResponse` function. It never is called with a `null` argument, and is allowed to return `null`. [Issue #5009](https://github.com/apollographql/apollo-server/issues/5009) [PR #5089](https://github.com/apollographql/apollo-server/pull/5089)

## v2.22.2

Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Provide this function to transform the structure of error objects before they're
</td>
<td>

Provide this function to transform the structure of GraphQL response objects before they're sent to a client. The function takes a [`GraphQLResponse`](https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-types/src/index.ts#L77-L82) object and a [`GraphQLRequestContext`](https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-types/src/index.ts#L95-L130) object, and it should return a `GraphQLResponse` object.
Provide this function to transform the structure of GraphQL response objects before they're sent to a client. The function takes a [`GraphQLResponse`](https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-types/src/index.ts#L77-L82) object and a [`GraphQLRequestContext`](https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-types/src/index.ts#L95-L130) object, and it should return a `GraphQLResponse` object, or null to preserve the existing structure.
</td>
</tr>

Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export interface GraphQLServerOptions<
validationRules?: Array<(context: ValidationContext) => any>;
executor?: GraphQLExecutor;
formatResponse?: (
response: GraphQLResponse | null,
response: GraphQLResponse,
requestContext: GraphQLRequestContext<TContext>,
) => GraphQLResponse
) => GraphQLResponse | null;
fieldResolver?: GraphQLFieldResolver<any, TContext>;
debug?: boolean;
tracing?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/requestPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export interface GraphQLRequestPipelineConfig<TContext> {

formatError?: (error: GraphQLError) => GraphQLFormattedError;
formatResponse?: (
response: GraphQLResponse | null,
response: GraphQLResponse,
requestContext: GraphQLRequestContext<TContext>,
) => GraphQLResponse;
) => GraphQLResponse | null;

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
Expand Down

0 comments on commit ad4c3ac

Please sign in to comment.