Skip to content

Commit

Permalink
remove calculate headers as a function (#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
evans authored Jul 13, 2018
1 parent 7f157da commit 78dcf4f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 0 additions & 4 deletions packages/apollo-server-core/src/caching.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ExecutionResult } from 'graphql';
import { CacheControlFormat } from 'apollo-cache-control';

export type HttpHeaderCalculation = (
responses: Array<ExecutionResult & { extensions?: Record<string, any> }>,
) => Record<string, string>;

export function calculateCacheControlHeaders(
responses: Array<ExecutionResult & { extensions?: Record<string, any> }>,
): Record<string, string> {
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ValidationContext,
GraphQLFieldResolver,
} from 'graphql';
import { HttpHeaderCalculation } from './caching';
import { GraphQLExtension } from 'graphql-extensions';
import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { KeyValueCache } from 'apollo-server-caching';
Expand Down Expand Up @@ -42,7 +41,7 @@ export interface GraphQLServerOptions<
cacheControl?:
| boolean
| (CacheControlExtensionOptions & {
calculateHttpHeaders?: boolean | HttpHeaderCalculation;
calculateHttpHeaders?: boolean;
stripFormattedExtensions?: boolean;
});
extensions?: Array<() => GraphQLExtension>;
Expand Down
9 changes: 3 additions & 6 deletions packages/apollo-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PersistedQueryNotSupportedError,
PersistedQueryNotFoundError,
} from 'apollo-server-errors';
import { calculateCacheControlHeaders, HttpHeaderCalculation } from './caching';
import { calculateCacheControlHeaders } from './caching';

export interface HttpQueryRequest {
method: string;
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function runHttpQuery(
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test';
let cacheControl:
| CacheControlExtensionOptions & {
calculateHttpHeaders: boolean | HttpHeaderCalculation;
calculateHttpHeaders: boolean;
stripFormattedExtensions: boolean;
}
| undefined;
Expand Down Expand Up @@ -445,10 +445,7 @@ export async function runHttpQuery(

if (cacheControl) {
if (cacheControl.calculateHttpHeaders) {
const calculatedHeaders =
typeof cacheControl.calculateHttpHeaders === 'function'
? cacheControl.calculateHttpHeaders(responses)
: calculateCacheControlHeaders(responses);
const calculatedHeaders = calculateCacheControlHeaders(responses);

responseInit.headers = {
...responseInit.headers,
Expand Down

0 comments on commit 78dcf4f

Please sign in to comment.