Skip to content

Commit b376fee

Browse files
committed
🚧
1 parent f29abb0 commit b376fee

File tree

5 files changed

+80
-57
lines changed

5 files changed

+80
-57
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from '@graphql-hive/gateway';
2+
3+
export const gatewayConfig = defineConfig({
4+
responseCaching: {
5+
invalidateViaMutation: false,
6+
ttl: 0,
7+
ttlPerType: {
8+
'Query.me': 2000,
9+
},
10+
session: () => null,
11+
},
12+
maskedErrors: false,
13+
});
Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { createExampleSetup, createTenv } from '@internal/e2e';
1+
import { setTimeout } from 'node:timers/promises';
2+
import { createExampleSetup, createTenv, GatewayOptions } from '@internal/e2e';
23
import { benchConfig } from '@internal/testing';
34
import { bench, describe, expect } from 'vitest';
45

56
describe('Response Cache', async () => {
6-
const { gateway, container } = createTenv(__dirname);
7-
const exampleSetup = createExampleSetup(__dirname, 1000);
8-
7+
const { runBench, container } = await makeRunner();
98
const redis = await container({
109
name: 'redis',
1110
healthcheck: ['CMD', 'redis-cli', 'ping'],
@@ -17,58 +16,67 @@ describe('Response Cache', async () => {
1716
containerPort: 6379,
1817
});
1918

20-
const supergraph = await exampleSetup.supergraph();
21-
22-
const { query, operationName, result } = exampleSetup;
23-
24-
const gatewayWithoutCache = await gateway({
25-
supergraph,
26-
args: ['-c', 'gateway-without-cache.config.ts'],
27-
});
28-
bench(
29-
'Without response cache',
30-
async () => {
31-
const response = await gatewayWithoutCache.execute({
32-
query,
33-
operationName,
34-
});
35-
expect(response).toEqual(result);
36-
},
37-
benchConfig,
19+
await runBench(
20+
'With in memory response cache',
21+
'gateway-with-cache.config.ts',
3822
);
23+
await runBench('Without response cache', 'gateway-without-cache.config.ts');
3924

40-
const gatewayWithCache = await gateway({
41-
supergraph,
42-
args: ['-c', 'gateway-with-cache.config.ts'],
43-
});
44-
bench(
45-
'With in memory response cache',
46-
async () => {
47-
const response = await gatewayWithCache.execute({
48-
query,
49-
operationName,
50-
});
51-
expect(response).toEqual(result);
52-
},
53-
benchConfig,
25+
await runBench.skip(
26+
'Without invalidation cache',
27+
'gateway-without-auto-invalidation.config.ts',
5428
);
5529

56-
const gatewayWithRedisCache = await gateway({
57-
supergraph,
58-
args: ['-c', 'gateway-with-redis.config.ts'],
59-
env: {
60-
REDIS_URL: `redis://localhost:${redis.port}`,
61-
},
62-
});
63-
bench(
30+
await runBench.skip(
6431
'With redis response cache',
65-
async () => {
66-
const response = await gatewayWithRedisCache.execute({
67-
query,
68-
operationName,
69-
});
70-
expect(response).toEqual(result);
32+
'gateway-with-redis.config.ts',
33+
{
34+
env: {
35+
REDIS_URL: `redis://localhost:${redis.port}`,
36+
},
7137
},
72-
benchConfig,
7338
);
7439
});
40+
41+
const makeRunner = async () => {
42+
const { gateway, container } = createTenv(__dirname);
43+
const exampleSetup = createExampleSetup(__dirname, 1000);
44+
45+
const supergraph = await exampleSetup.supergraph();
46+
47+
const { query, operationName, result } = exampleSetup;
48+
49+
const runBench = async (
50+
name: string,
51+
configFile: string,
52+
options?: Partial<GatewayOptions>,
53+
) => {
54+
const { execute } = await gateway({
55+
supergraph,
56+
...options,
57+
args: ['-c', configFile, ...(options?.args ?? [])],
58+
});
59+
return bench(
60+
name,
61+
async () => {
62+
const response = await execute({
63+
query,
64+
operationName,
65+
});
66+
expect(response).toEqual(result);
67+
},
68+
benchConfig,
69+
);
70+
};
71+
72+
runBench.skip = async (
73+
name: string,
74+
_configFile: string,
75+
_options?: GatewayOptions,
76+
) => bench.skip(name);
77+
78+
return {
79+
runBench,
80+
container,
81+
};
82+
};

internal/e2e/src/tenv.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ export function createTenv(cwd: string): Tenv {
544544
'node',
545545
// use next available port when starting inspector (note that this does not start inspect, this still needs to be done manually)
546546
// it's not set because in JIT mode because it does not work together (why? no clue)
547-
args.includes('--jit') ? null : '--inspect-port=0',
547+
args.includes('--jit') ? null : '--inspect-port=9999',
548+
// '--inspect',
548549
'--import',
549550
'tsx',
550551
path.resolve(__project, 'packages', 'gateway', 'src', 'bin.ts'),

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"tar-fs": "3.1.1",
8282
"tmp": "0.2.4",
8383
"tsx": "patch:tsx@npm%3A4.20.3#~/.yarn/patches/tsx-npm-4.20.3-7de67a623f.patch",
84-
"vite": "7.1.7"
84+
"vite": "7.1.7",
85+
"@envelop/response-cache": "8.2.0-alpha-20251003143108-b56597767a1f741fbd6420f60af9abdf439fd4b8"
8586
}
8687
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3659,9 +3659,9 @@ __metadata:
36593659
languageName: node
36603660
linkType: hard
36613661

3662-
"@envelop/response-cache@npm:^8.0.0, @envelop/response-cache@npm:^8.0.2":
3663-
version: 8.0.2
3664-
resolution: "@envelop/response-cache@npm:8.0.2"
3662+
"@envelop/response-cache@npm:8.2.0-alpha-20251003143108-b56597767a1f741fbd6420f60af9abdf439fd4b8":
3663+
version: 8.2.0-alpha-20251003143108-b56597767a1f741fbd6420f60af9abdf439fd4b8
3664+
resolution: "@envelop/response-cache@npm:8.2.0-alpha-20251003143108-b56597767a1f741fbd6420f60af9abdf439fd4b8"
36653665
dependencies:
36663666
"@graphql-tools/utils": "npm:^10.0.3"
36673667
"@whatwg-node/fetch": "npm:^0.10.0"
@@ -3672,7 +3672,7 @@ __metadata:
36723672
peerDependencies:
36733673
"@envelop/core": ^5.3.2
36743674
graphql: ^14.0.0 || ^15.0.0 || ^16.0.0
3675-
checksum: 10c0/061435944d782263b52b85fa0cd49b23caa7a880c4a5fada3c4273f149c2ed25dc6ca4668f92283bf99ec0d13ca044581703fe69e7a5b67fdd6f3893f4ee0e13
3675+
checksum: 10c0/7ff40a8d2b88a15681b3412e467f3a1726d559c4d1fdec72cd46d612504ef6047ea8752d8aa47f9776d0a917d65474f47c9e0cfe5c1973ad3ee551f7e1fbd065
36763676
languageName: node
36773677
linkType: hard
36783678

0 commit comments

Comments
 (0)