Skip to content

Commit f8e6e15

Browse files
authored
Fix cache control (#1614)
* Fix cacheControl in ApolloServer * changelog * Update benchmark * Cache node_modules * Try to use object spread
1 parent 62cd473 commit f8e6e15

File tree

11 files changed

+122
-50
lines changed

11 files changed

+122
-50
lines changed

.changeset/young-cats-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-modules': patch
3+
---
4+
5+
Fix missing ApolloServer cacheControl in GraphQLResolveInfo

.github/workflows/benchmark.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ jobs:
1919
uses: actions/setup-node@master
2020
with:
2121
node-version: ${{ matrix.node_version }}
22-
23-
- name: Get yarn cache
24-
id: yarn-cache
25-
run: echo "::set-output name=dir::$(yarn cache dir)"
26-
- name: Cache Yarn
27-
uses: actions/cache@v2
22+
23+
- uses: actions/cache@v2
24+
name: Cache node_modules
2825
with:
29-
path: ${{ steps.yarn-cache.outputs.dir }}
30-
key: ${{ runner.os }}-${{ matrix.node_version }}-yarn-${{ hashFiles('yarn.lock') }}
26+
path: '**/node_modules'
27+
key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
3128
restore-keys: |
32-
${{ runner.os }}-${{ matrix.node_version }}-yarn-
29+
${{ runner.os }}-yarn-${{ matrix.node_version }}
30+
${{ runner.os }}-yarn-
3331
3432
- name: Install
3533
run: yarn

.github/workflows/canary.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ jobs:
2828
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
2929
env:
3030
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
31-
- name: Get yarn cache
32-
id: yarn-cache
33-
run: echo "::set-output name=dir::$(yarn cache dir)"
34-
- name: Cache Yarn
35-
uses: actions/cache@v2
31+
- uses: actions/cache@v2
32+
name: Cache node_modules
3633
with:
37-
path: ${{ steps.yarn-cache.outputs.dir }}
38-
key: ${{ runner.os }}-14-yarn-${{ hashFiles('yarn.lock') }}
34+
path: '**/node_modules'
35+
key: ${{ runner.os }}-yarn-14-${{ hashFiles('**/yarn.lock') }}
3936
restore-keys: |
40-
${{ runner.os }}-14-yarn-
37+
${{ runner.os }}-yarn-14
38+
${{ runner.os }}-yarn-
4139
- name: Install Dependencies using Yarn
4240
run: yarn install --ignore-engines && git checkout yarn.lock
4341
- name: Release Canary

.github/workflows/ci.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ jobs:
2020
with:
2121
node-version: ${{ matrix.node_version }}
2222

23-
- name: Get yarn cache
24-
id: yarn-cache
25-
run: echo "::set-output name=dir::$(yarn cache dir)"
26-
- name: Cache Yarn
27-
uses: actions/cache@v2
23+
- uses: actions/cache@v2
24+
name: Cache node_modules
2825
with:
29-
path: ${{ steps.yarn-cache.outputs.dir }}
30-
key: ${{ runner.os }}-${{ matrix.node_version }}-yarn-${{ hashFiles('yarn.lock') }}
26+
path: '**/node_modules'
27+
key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
3128
restore-keys: |
32-
${{ runner.os }}-${{ matrix.node_version }}-yarn-
29+
${{ runner.os }}-yarn-${{ matrix.node_version }}
30+
${{ runner.os }}-yarn-
3331
3432
- name: Install
3533
run: yarn

.github/workflows/release.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ jobs:
2929
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
3030
env:
3131
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
32-
- name: Get yarn cache
33-
id: yarn-cache
34-
run: echo "::set-output name=dir::$(yarn cache dir)"
35-
- name: Cache Yarn
36-
uses: actions/cache@v2
32+
- uses: actions/cache@v2
33+
name: Cache node_modules
3734
with:
38-
path: ${{ steps.yarn-cache.outputs.dir }}
39-
key: ${{ runner.os }}-14-yarn-${{ hashFiles('yarn.lock') }}
35+
path: '**/node_modules'
36+
key: ${{ runner.os }}-yarn-14-${{ hashFiles('**/yarn.lock') }}
4037
restore-keys: |
41-
${{ runner.os }}-14-yarn-
38+
${{ runner.os }}-yarn-14
39+
${{ runner.os }}-yarn-
4240
- name: Install Dependencies using Yarn
4341
run: yarn install --ignore-engines && git checkout yarn.lock
4442
- name: Create Release Pull Request or Publish to npm

benchmark/basic.case.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const executeApp = app.createExecution();
9999
const apolloWithDIExecutor = appWithDI.createApolloExecutor();
100100
const executeApolloWithDI = (args: ExecutionArgs) => {
101101
return apolloWithDIExecutor({
102+
schema: args.schema,
102103
document: args.document,
103104
operationName: args.operationName,
104105
context: args.contextValue,
@@ -111,6 +112,7 @@ const executeApolloWithDI = (args: ExecutionArgs) => {
111112
const apolloExecutor = app.createApolloExecutor();
112113
const executeApollo = (args: ExecutionArgs) => {
113114
return apolloExecutor({
115+
schema: args.schema,
114116
document: args.document,
115117
operationName: args.operationName,
116118
context: args.contextValue,

packages/graphql-modules/src/application/apollo.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ export interface ApolloRequestContext {
1111
document: DocumentNode;
1212
operationName?: string | null;
1313
context?: any;
14+
schema: GraphQLSchema;
1415
request: {
1516
variables?: { [name: string]: any } | null;
1617
};
1718
}
1819

1920
export function apolloExecutorCreator({
2021
createExecution,
21-
schema,
2222
}: {
2323
createExecution: Application['createExecution'];
24-
schema: GraphQLSchema;
2524
}): Application['createApolloExecutor'] {
2625
return function createApolloExecutor(options) {
2726
const executor = createExecution(options);
2827
return function executorAdapter(requestContext: ApolloRequestContext) {
2928
return executor({
30-
schema,
29+
schema: requestContext.schema,
3130
document: requestContext.document,
3231
operationName: requestContext.operationName,
3332
variableValues: requestContext.request.variables,

packages/graphql-modules/src/application/application.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export function createApplication(
139139
});
140140
const createApolloExecutor = apolloExecutorCreator({
141141
createExecution,
142-
schema,
143142
});
144143

145144
instantiateSingletonProviders({

packages/graphql-modules/src/application/context.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injector, ReflectiveInjector } from '../di';
22
import { ResolvedProvider } from '../di/resolution';
33
import { ID } from '../shared/types';
4-
import { once } from '../shared/utils';
4+
import { once, merge } from '../shared/utils';
55
import type { InternalAppContext, ModulesMap } from './application';
66
import { attachGlobalProvidersMap } from './di';
77
import { CONTEXT } from './tokens';
@@ -112,10 +112,9 @@ export function createContextBuilder({
112112
});
113113

114114
// Create a context for application-level ExecutionContext
115-
appContext = {
116-
...context,
115+
appContext = merge(context, {
117116
injector: operationAppInjector,
118-
};
117+
});
119118

120119
// Track Providers with OnDestroy hooks
121120
registerProvidersToDestroy(operationAppInjector);
@@ -151,23 +150,24 @@ export function createContextBuilder({
151150
// Same as on application level, we need to collect providers with OnDestroy hooks
152151
registerProvidersToDestroy(operationModuleInjector);
153152

154-
contextCache[moduleId] = {
155-
...ctx,
153+
contextCache[moduleId] = merge(ctx, {
156154
injector: operationModuleInjector,
157155
moduleId,
158-
};
156+
});
159157
}
160158

161159
return contextCache[moduleId];
162160
}
163161

164-
const sharedContext = {
162+
const sharedContext = merge(
165163
// We want to pass the received context
166-
...(context || {}),
167-
// Here's something very crutial
168-
// It's a function that is used in module's context creation
169-
ɵgetModuleContext: getModuleContext,
170-
};
164+
context || {},
165+
{
166+
// Here's something very crutial
167+
// It's a function that is used in module's context creation
168+
ɵgetModuleContext: getModuleContext,
169+
}
170+
);
171171

172172
attachGlobalProvidersMap({
173173
injector: operationAppInjector,

packages/graphql-modules/src/shared/utils.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,29 @@ export function uniqueId(isNotUsed: (id: string) => boolean) {
107107
export function isNotSchema<T>(obj: any): obj is T {
108108
return obj instanceof GraphQLSchema === false;
109109
}
110+
111+
export function merge<S extends object, T extends object>(
112+
source: S,
113+
target: T
114+
): S & T {
115+
const result: any = {
116+
...source,
117+
...target,
118+
};
119+
120+
function attachSymbols<O extends T | S>(obj: O): void {
121+
const symbols = Object.getOwnPropertySymbols(obj) as Array<keyof O>;
122+
123+
for (const symbol of symbols) {
124+
result[symbol] = obj[symbol];
125+
}
126+
}
127+
128+
if (source) {
129+
attachSymbols(source);
130+
}
131+
132+
attachSymbols(target);
133+
134+
return result;
135+
}

0 commit comments

Comments
 (0)