-
Notifications
You must be signed in to change notification settings - Fork 2k
/
collectCacheControlHints.ts
41 lines (36 loc) 路 1.06 KB
/
collectCacheControlHints.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { GraphQLSchema, graphql } from 'graphql';
import {
CacheHint,
CacheControlExtensionOptions,
plugin,
} from '../';
import pluginTestHarness from 'apollo-server-core/dist/utils/pluginTestHarness';
export async function collectCacheControlHints(
schema: GraphQLSchema,
source: string,
options?: CacheControlExtensionOptions,
): Promise<CacheHint[]> {
// Because this test helper looks at the formatted extensions, we always want
// to include them in the response rather than allow them to be stripped
// out.
const pluginInstance = plugin({
...options,
stripFormattedExtensions: false,
});
const requestContext = await pluginTestHarness({
pluginInstance,
schema,
graphqlRequest: {
query: source,
},
executor: async (requestContext) => {
return await graphql({
schema,
source: requestContext.request.query,
contextValue: requestContext.context,
});
}
});
expect(requestContext.response.errors).toBeUndefined();
return requestContext.response.extensions!.cacheControl.hints;
}