Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.

- `apollo-server-core`: Provide accurate type for `formatResponse` rather than generic `Function` type. [PR #3431](https://github.com/apollographql/apollo-server/pull/3431)
- `apollo-server-core`: Pass complete request context to `formatResponse`, rather than just `context`. [PR #3431](https://github.com/apollographql/apollo-server/pull/3431)

### v2.9.7

> [See complete versioning details.](https://github.com/apollographql/apollo-server/commit/5d94e986f04457ec17114791ee6db3ece4213dd8)
Expand Down
12 changes: 10 additions & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching';
import { DataSource } from 'apollo-datasource';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { GraphQLParseOptions } from 'graphql-tools';
import { GraphQLExecutor, ValueOrPromise } from 'apollo-server-types';
import {
GraphQLExecutor,
ValueOrPromise,
GraphQLResponse,
GraphQLRequestContext,
} from 'apollo-server-types';

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

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

plugins?: ApolloServerPlugin[];
documentStore?: InMemoryLRUCache<DocumentNode>;
Expand Down Expand Up @@ -385,9 +388,7 @@ export async function processGraphQLRequest<TContext>(
if (config.formatResponse) {
const formattedResponse: GraphQLResponse | null = config.formatResponse(
response,
{
context: requestContext.context,
},
requestContext,
Comment on lines -388 to +391

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that was easy 😄I read the PR and thought - "how's he gonna get out of that breaking change?" Interesting and convenient that this was passed in as an object before!

);
if (formattedResponse != null) {
response = formattedResponse;
Expand Down