@graphql-mesh/plugin-response-cache 0.103.17 → 0.104.0-alpha-20250124181238-87366ee8e2a95025d881bdaba556f04d337e8331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +1 -47
- package/esm/index.js +1 -46
- package/package.json +4 -5
- package/typings/index.d.cts +3 -3
- package/typings/index.d.ts +3 -3
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = useMeshResponseCache;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const cache_control_parser_1 = tslib_1.__importDefault(require("cache-control-parser"));
|
|
6
4
|
const response_cache_1 = require("@envelop/response-cache");
|
|
7
5
|
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
8
6
|
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
@@ -145,11 +143,7 @@ function useMeshResponseCache(options) {
|
|
|
145
143
|
ttlPerSchemaCoordinate[ttlConfig.coordinate] = ttlConfig.ttl;
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
|
-
|
|
149
|
-
// To be compared with the calculated one later in `onTtl`
|
|
150
|
-
const ttlByContext = new WeakMap();
|
|
151
|
-
// @ts-expect-error - GatewayPlugin types
|
|
152
|
-
const plugin = (0, plugin_response_cache_1.useResponseCache)({
|
|
146
|
+
return (0, plugin_response_cache_1.useResponseCache)({
|
|
153
147
|
includeExtensionMetadata: options.includeExtensionMetadata != null
|
|
154
148
|
? options.includeExtensionMetadata
|
|
155
149
|
: cross_helpers_1.process.env.DEBUG === '1',
|
|
@@ -163,45 +157,5 @@ function useMeshResponseCache(options) {
|
|
|
163
157
|
cache: getCacheForResponseCache(options.cache),
|
|
164
158
|
ttlPerType,
|
|
165
159
|
ttlPerSchemaCoordinate,
|
|
166
|
-
// Checks the TTL stored in the context
|
|
167
|
-
// Compares it to the calculated one
|
|
168
|
-
// Then it takes the lowest value
|
|
169
|
-
onTtl({ ttl, context }) {
|
|
170
|
-
const ttlForThisContext = ttlByContext.get(context);
|
|
171
|
-
if (ttlForThisContext != null && ttlForThisContext < ttl) {
|
|
172
|
-
return ttlForThisContext;
|
|
173
|
-
}
|
|
174
|
-
return ttl;
|
|
175
|
-
},
|
|
176
160
|
});
|
|
177
|
-
// Checks the TTL stored in the context
|
|
178
|
-
// Takes the lowest value
|
|
179
|
-
function checkTtl(context, ttl) {
|
|
180
|
-
const ttlForThisContext = ttlByContext.get(context);
|
|
181
|
-
if (ttlForThisContext == null || ttl < ttlForThisContext) {
|
|
182
|
-
ttlByContext.set(context, ttl);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
plugin.onFetch = function ({ executionRequest, context }) {
|
|
186
|
-
// Only if it is a subgraph request
|
|
187
|
-
if (executionRequest && context) {
|
|
188
|
-
return function onFetchDone({ response }) {
|
|
189
|
-
const cacheControlHeader = response.headers.get('cache-control');
|
|
190
|
-
if (cacheControlHeader != null) {
|
|
191
|
-
const parsedCacheControl = cache_control_parser_1.default.parse(cacheControlHeader);
|
|
192
|
-
if (parsedCacheControl['max-age'] != null) {
|
|
193
|
-
const maxAgeInSeconds = parsedCacheControl['max-age'];
|
|
194
|
-
const maxAgeInMs = maxAgeInSeconds * 1000;
|
|
195
|
-
checkTtl(context, maxAgeInMs);
|
|
196
|
-
}
|
|
197
|
-
if (parsedCacheControl['s-maxage'] != null) {
|
|
198
|
-
const sMaxAgeInSeconds = parsedCacheControl['s-maxage'];
|
|
199
|
-
const sMaxAgeInMs = sMaxAgeInSeconds * 1000;
|
|
200
|
-
checkTtl(context, sMaxAgeInMs);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
return plugin;
|
|
207
161
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import CacheControlParser from 'cache-control-parser';
|
|
2
1
|
import { defaultBuildResponseCacheKey } from '@envelop/response-cache';
|
|
3
2
|
import { process } from '@graphql-mesh/cross-helpers';
|
|
4
3
|
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
@@ -141,11 +140,7 @@ export default function useMeshResponseCache(options) {
|
|
|
141
140
|
ttlPerSchemaCoordinate[ttlConfig.coordinate] = ttlConfig.ttl;
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
|
|
145
|
-
// To be compared with the calculated one later in `onTtl`
|
|
146
|
-
const ttlByContext = new WeakMap();
|
|
147
|
-
// @ts-expect-error - GatewayPlugin types
|
|
148
|
-
const plugin = useResponseCache({
|
|
143
|
+
return useResponseCache({
|
|
149
144
|
includeExtensionMetadata: options.includeExtensionMetadata != null
|
|
150
145
|
? options.includeExtensionMetadata
|
|
151
146
|
: process.env.DEBUG === '1',
|
|
@@ -159,45 +154,5 @@ export default function useMeshResponseCache(options) {
|
|
|
159
154
|
cache: getCacheForResponseCache(options.cache),
|
|
160
155
|
ttlPerType,
|
|
161
156
|
ttlPerSchemaCoordinate,
|
|
162
|
-
// Checks the TTL stored in the context
|
|
163
|
-
// Compares it to the calculated one
|
|
164
|
-
// Then it takes the lowest value
|
|
165
|
-
onTtl({ ttl, context }) {
|
|
166
|
-
const ttlForThisContext = ttlByContext.get(context);
|
|
167
|
-
if (ttlForThisContext != null && ttlForThisContext < ttl) {
|
|
168
|
-
return ttlForThisContext;
|
|
169
|
-
}
|
|
170
|
-
return ttl;
|
|
171
|
-
},
|
|
172
157
|
});
|
|
173
|
-
// Checks the TTL stored in the context
|
|
174
|
-
// Takes the lowest value
|
|
175
|
-
function checkTtl(context, ttl) {
|
|
176
|
-
const ttlForThisContext = ttlByContext.get(context);
|
|
177
|
-
if (ttlForThisContext == null || ttl < ttlForThisContext) {
|
|
178
|
-
ttlByContext.set(context, ttl);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
plugin.onFetch = function ({ executionRequest, context }) {
|
|
182
|
-
// Only if it is a subgraph request
|
|
183
|
-
if (executionRequest && context) {
|
|
184
|
-
return function onFetchDone({ response }) {
|
|
185
|
-
const cacheControlHeader = response.headers.get('cache-control');
|
|
186
|
-
if (cacheControlHeader != null) {
|
|
187
|
-
const parsedCacheControl = CacheControlParser.parse(cacheControlHeader);
|
|
188
|
-
if (parsedCacheControl['max-age'] != null) {
|
|
189
|
-
const maxAgeInSeconds = parsedCacheControl['max-age'];
|
|
190
|
-
const maxAgeInMs = maxAgeInSeconds * 1000;
|
|
191
|
-
checkTtl(context, maxAgeInMs);
|
|
192
|
-
}
|
|
193
|
-
if (parsedCacheControl['s-maxage'] != null) {
|
|
194
|
-
const sMaxAgeInSeconds = parsedCacheControl['s-maxage'];
|
|
195
|
-
const sMaxAgeInMs = sMaxAgeInSeconds * 1000;
|
|
196
|
-
checkTtl(context, sMaxAgeInMs);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
return plugin;
|
|
203
158
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/plugin-response-cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.104.0-alpha-20250124181238-87366ee8e2a95025d881bdaba556f04d337e8331",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@envelop/core": "^5.0.0",
|
|
10
10
|
"@envelop/response-cache": "^6.1.1",
|
|
11
|
-
"@graphql-mesh/cross-helpers": "^0.4.
|
|
11
|
+
"@graphql-mesh/cross-helpers": "^0.4.9",
|
|
12
12
|
"@graphql-mesh/string-interpolation": "0.5.8",
|
|
13
|
-
"@graphql-mesh/types": "
|
|
14
|
-
"@graphql-mesh/utils": "
|
|
13
|
+
"@graphql-mesh/types": "0.104.0-alpha-20250124181238-87366ee8e2a95025d881bdaba556f04d337e8331",
|
|
14
|
+
"@graphql-mesh/utils": "0.104.0-alpha-20250124181238-87366ee8e2a95025d881bdaba556f04d337e8331",
|
|
15
15
|
"@graphql-tools/utils": "^10.6.2",
|
|
16
16
|
"@graphql-yoga/plugin-response-cache": "^3.1.1",
|
|
17
|
-
"cache-control-parser": "^2.0.6",
|
|
18
17
|
"graphql-yoga": "^5.7.0",
|
|
19
18
|
"tslib": "^2.4.0"
|
|
20
19
|
},
|
package/typings/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from 'graphql-yoga';
|
|
2
2
|
import type { KeyValueCache, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import type { UseResponseCacheParameter } from '@graphql-yoga/plugin-response-cache';
|
|
4
4
|
export type ResponseCacheConfig = Omit<UseResponseCacheParameter, 'cache'> & {
|
|
@@ -20,11 +20,11 @@ export type ResponseCacheConfig = Omit<UseResponseCacheParameter, 'cache'> & {
|
|
|
20
20
|
* Response cache plugin for GraphQL Mesh
|
|
21
21
|
* @param options
|
|
22
22
|
*/
|
|
23
|
-
export default function useMeshResponseCache(options: ResponseCacheConfig):
|
|
23
|
+
export default function useMeshResponseCache(options: ResponseCacheConfig): Plugin;
|
|
24
24
|
/**
|
|
25
25
|
* @deprecated Use new configuration format `ResponseCacheConfig`
|
|
26
26
|
* @param options
|
|
27
27
|
*/
|
|
28
28
|
export default function useMeshResponseCache(options: YamlConfig.ResponseCacheConfig & {
|
|
29
29
|
cache: KeyValueCache;
|
|
30
|
-
}):
|
|
30
|
+
}): Plugin;
|
package/typings/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from 'graphql-yoga';
|
|
2
2
|
import type { KeyValueCache, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
import type { UseResponseCacheParameter } from '@graphql-yoga/plugin-response-cache';
|
|
4
4
|
export type ResponseCacheConfig = Omit<UseResponseCacheParameter, 'cache'> & {
|
|
@@ -20,11 +20,11 @@ export type ResponseCacheConfig = Omit<UseResponseCacheParameter, 'cache'> & {
|
|
|
20
20
|
* Response cache plugin for GraphQL Mesh
|
|
21
21
|
* @param options
|
|
22
22
|
*/
|
|
23
|
-
export default function useMeshResponseCache(options: ResponseCacheConfig):
|
|
23
|
+
export default function useMeshResponseCache(options: ResponseCacheConfig): Plugin;
|
|
24
24
|
/**
|
|
25
25
|
* @deprecated Use new configuration format `ResponseCacheConfig`
|
|
26
26
|
* @param options
|
|
27
27
|
*/
|
|
28
28
|
export default function useMeshResponseCache(options: YamlConfig.ResponseCacheConfig & {
|
|
29
29
|
cache: KeyValueCache;
|
|
30
|
-
}):
|
|
30
|
+
}): Plugin;
|