@envelop/response-cache 9.1.1 → 9.2.0
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/LICENSE +3 -1
- package/cjs/hash-sha256.js +2 -2
- package/cjs/in-memory-cache.js +1 -1
- package/cjs/plugin.js +35 -38
- package/esm/hash-sha256.js +2 -2
- package/esm/in-memory-cache.js +1 -1
- package/esm/plugin.js +36 -39
- package/package.json +6 -6
- package/typings/hash-sha256.d.cts +1 -1
- package/typings/hash-sha256.d.ts +1 -1
- package/typings/plugin.d.cts +5 -5
- package/typings/plugin.d.ts +5 -5
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020
|
|
3
|
+
Copyright (c) 2018-2020 Graphcool
|
|
4
|
+
Copyright (c) 2020-2021 Prisma
|
|
5
|
+
Copyright (c) 2021- The Guild
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/cjs/hash-sha256.js
CHANGED
|
@@ -8,8 +8,8 @@ function hashSHA256(text) {
|
|
|
8
8
|
return (0, promise_helpers_1.handleMaybePromise)(() => fetch_1.crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array), arrayBuf => {
|
|
9
9
|
const outputUint8Array = new Uint8Array(arrayBuf);
|
|
10
10
|
let hash = '';
|
|
11
|
-
for (
|
|
12
|
-
const hex =
|
|
11
|
+
for (const hexNum of outputUint8Array) {
|
|
12
|
+
const hex = hexNum.toString(16);
|
|
13
13
|
hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
|
|
14
14
|
}
|
|
15
15
|
return hash;
|
package/cjs/in-memory-cache.js
CHANGED
|
@@ -72,7 +72,7 @@ const createInMemoryCache = (params) => {
|
|
|
72
72
|
},
|
|
73
73
|
invalidate(entitiesToRemove) {
|
|
74
74
|
for (const { typename, id } of entitiesToRemove) {
|
|
75
|
-
purgeEntity(id
|
|
75
|
+
purgeEntity(id == null ? typename : buildEntityId(typename, id));
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
};
|
package/cjs/plugin.js
CHANGED
|
@@ -96,10 +96,9 @@ const getDocumentWithMetadataAndTTL = (0, utils_1.memoize4)(function addTypeName
|
|
|
96
96
|
};
|
|
97
97
|
return [(0, graphql_1.visit)(document, (0, graphql_1.visitWithTypeInfo)(typeInfo, visitor)), ttl];
|
|
98
98
|
});
|
|
99
|
-
function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache)(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = exports.defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = exports.defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process
|
|
100
|
-
?
|
|
101
|
-
|
|
102
|
-
: false, }) {
|
|
99
|
+
function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache)(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = exports.defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = exports.defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process === 'undefined'
|
|
100
|
+
? false
|
|
101
|
+
: process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG'], }) {
|
|
103
102
|
const cacheFactory = typeof cache === 'function' ? (0, utils_1.memoize1)(cache) : () => cache;
|
|
104
103
|
const ignoredTypesMap = new Set(ignoredTypes);
|
|
105
104
|
const typePerSchemaCoordinateMap = new Map();
|
|
@@ -136,14 +135,15 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
136
135
|
...(directive && {
|
|
137
136
|
[utils_1.MapperKind.COMPOSITE_TYPE]: type => {
|
|
138
137
|
const cacheControlAnnotations = (0, utils_1.getDirective)(schema, type, 'cacheControl');
|
|
139
|
-
cacheControlAnnotations
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
if (cacheControlAnnotations)
|
|
139
|
+
for (const cacheControl of cacheControlAnnotations) {
|
|
140
|
+
if (cacheControl.maxAge != null) {
|
|
141
|
+
ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
|
|
142
|
+
}
|
|
143
|
+
if (cacheControl.scope) {
|
|
144
|
+
scopePerSchemaCoordinate[type.name] = cacheControl.scope;
|
|
145
|
+
}
|
|
142
146
|
}
|
|
143
|
-
if (cacheControl.scope) {
|
|
144
|
-
scopePerSchemaCoordinate[type.name] = cacheControl.scope;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
147
|
return type;
|
|
148
148
|
},
|
|
149
149
|
}),
|
|
@@ -156,14 +156,15 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
156
156
|
}
|
|
157
157
|
if (directive) {
|
|
158
158
|
const cacheControlAnnotations = (0, utils_1.getDirective)(schema, fieldConfig, 'cacheControl');
|
|
159
|
-
cacheControlAnnotations
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
if (cacheControlAnnotations)
|
|
160
|
+
for (const cacheControl of cacheControlAnnotations) {
|
|
161
|
+
if (cacheControl.maxAge != null) {
|
|
162
|
+
ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
|
|
163
|
+
}
|
|
164
|
+
if (cacheControl.scope) {
|
|
165
|
+
scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
|
|
166
|
+
}
|
|
162
167
|
}
|
|
163
|
-
if (cacheControl.scope) {
|
|
164
|
-
scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
168
|
}
|
|
168
169
|
return fieldConfig;
|
|
169
170
|
},
|
|
@@ -174,7 +175,6 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
174
175
|
return;
|
|
175
176
|
}
|
|
176
177
|
const identifier = new Map();
|
|
177
|
-
const types = new Set();
|
|
178
178
|
let currentTtl;
|
|
179
179
|
let skip = false;
|
|
180
180
|
const sessionId = session(onExecuteParams.args.contextValue);
|
|
@@ -210,7 +210,6 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
210
210
|
entity.id = data[idField];
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
types.add(entity.typename);
|
|
214
213
|
if (entity.typename in ttlPerSchemaCoordinate) {
|
|
215
214
|
const maybeTtl = ttlPerSchemaCoordinate[entity.typename];
|
|
216
215
|
currentTtl = calculateTtl(maybeTtl, currentTtl);
|
|
@@ -222,13 +221,14 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
222
221
|
const fieldData = data[fieldName];
|
|
223
222
|
if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
|
|
224
223
|
const inferredTypes = typePerSchemaCoordinateMap.get(`${entity.typename}.${fieldName}`);
|
|
225
|
-
inferredTypes
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
if (inferredTypes)
|
|
225
|
+
for (const inferredType of inferredTypes) {
|
|
226
|
+
if (inferredType in ttlPerSchemaCoordinate) {
|
|
227
|
+
const maybeTtl = ttlPerSchemaCoordinate[inferredType];
|
|
228
|
+
currentTtl = calculateTtl(maybeTtl, currentTtl);
|
|
229
|
+
}
|
|
230
|
+
identifier.set(inferredType, { typename: inferredType });
|
|
229
231
|
}
|
|
230
|
-
identifier.set(inferredType, { typename: inferredType });
|
|
231
|
-
});
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
}
|
|
@@ -295,9 +295,7 @@ function useResponseCache({ cache = (0, in_memory_cache_js_1.createInMemoryCache
|
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
297
|
function maybeCacheResult(result, setResult) {
|
|
298
|
-
|
|
299
|
-
result.data = removeMetadataFieldsFromResult(result.data, onEntity);
|
|
300
|
-
}
|
|
298
|
+
result.data &&= removeMetadataFieldsFromResult(result.data, onEntity);
|
|
301
299
|
// we only use the global ttl if no currentTtl has been determined.
|
|
302
300
|
let finalTtl = currentTtl ?? globalTtl;
|
|
303
301
|
if (onTtl) {
|
|
@@ -366,9 +364,7 @@ function handleAsyncIterableResult(handler) {
|
|
|
366
364
|
}
|
|
367
365
|
const newResult = { ...payload.result };
|
|
368
366
|
// Handle initial/single result
|
|
369
|
-
|
|
370
|
-
newResult.data = removeMetadataFieldsFromResult(newResult.data);
|
|
371
|
-
}
|
|
367
|
+
newResult.data &&= removeMetadataFieldsFromResult(newResult.data);
|
|
372
368
|
// Handle Incremental results
|
|
373
369
|
if ('hasNext' in newResult && newResult.incremental) {
|
|
374
370
|
newResult.incremental = newResult.incremental.map(value => {
|
|
@@ -445,14 +441,15 @@ function removeMetadataFieldsFromResult(data, onEntity) {
|
|
|
445
441
|
}
|
|
446
442
|
// clone the data to avoid mutation
|
|
447
443
|
data = { ...data };
|
|
448
|
-
const typename = data
|
|
444
|
+
const typename = data['__responseCacheTypeName'] ?? data['__typename'];
|
|
449
445
|
if (typeof typename === 'string') {
|
|
450
446
|
const entity = { typename };
|
|
451
|
-
delete data
|
|
452
|
-
if (data
|
|
453
|
-
(typeof data
|
|
454
|
-
|
|
455
|
-
|
|
447
|
+
delete data['__responseCacheTypeName'];
|
|
448
|
+
if (data['__responseCacheId'] &&
|
|
449
|
+
(typeof data['__responseCacheId'] === 'string' ||
|
|
450
|
+
typeof data['__responseCacheId'] === 'number')) {
|
|
451
|
+
entity.id = data['__responseCacheId'];
|
|
452
|
+
delete data['__responseCacheId'];
|
|
456
453
|
}
|
|
457
454
|
onEntity?.(entity, data);
|
|
458
455
|
}
|
package/esm/hash-sha256.js
CHANGED
|
@@ -5,8 +5,8 @@ export function hashSHA256(text) {
|
|
|
5
5
|
return handleMaybePromise(() => crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array), arrayBuf => {
|
|
6
6
|
const outputUint8Array = new Uint8Array(arrayBuf);
|
|
7
7
|
let hash = '';
|
|
8
|
-
for (
|
|
9
|
-
const hex =
|
|
8
|
+
for (const hexNum of outputUint8Array) {
|
|
9
|
+
const hex = hexNum.toString(16);
|
|
10
10
|
hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
|
|
11
11
|
}
|
|
12
12
|
return hash;
|
package/esm/in-memory-cache.js
CHANGED
|
@@ -69,7 +69,7 @@ export const createInMemoryCache = (params) => {
|
|
|
69
69
|
},
|
|
70
70
|
invalidate(entitiesToRemove) {
|
|
71
71
|
for (const { typename, id } of entitiesToRemove) {
|
|
72
|
-
purgeEntity(id
|
|
72
|
+
purgeEntity(id == null ? typename : buildEntityId(typename, id));
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
};
|
package/esm/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import jsonStableStringify from 'fast-json-stable-stringify';
|
|
2
2
|
import { getOperationAST, isListType, isNonNullType, isUnionType, Kind, print, TypeInfo, visit, visitWithTypeInfo, } from 'graphql';
|
|
3
|
-
import { getDocumentString, isAsyncIterable
|
|
3
|
+
import { getDocumentString, isAsyncIterable } from '@envelop/core';
|
|
4
4
|
import { getDirective, MapperKind, mapSchema, memoize1, memoize4, mergeIncrementalResult, } from '@graphql-tools/utils';
|
|
5
5
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
|
6
6
|
import { hashSHA256 } from './hash-sha256.js';
|
|
@@ -87,10 +87,9 @@ const getDocumentWithMetadataAndTTL = memoize4(function addTypeNameToDocument(do
|
|
|
87
87
|
};
|
|
88
88
|
return [visit(document, visitWithTypeInfo(typeInfo, visitor)), ttl];
|
|
89
89
|
});
|
|
90
|
-
export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process
|
|
91
|
-
?
|
|
92
|
-
|
|
93
|
-
: false, }) {
|
|
90
|
+
export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl = Infinity, session, enabled, ignoredTypes = [], ttlPerType, ttlPerSchemaCoordinate = {}, scopePerSchemaCoordinate = {}, idFields = ['id'], invalidateViaMutation = true, buildResponseCacheKey = defaultBuildResponseCacheKey, getDocumentString = defaultGetDocumentString, shouldCacheResult = defaultShouldCacheResult, onTtl, includeExtensionMetadata = typeof process === 'undefined'
|
|
91
|
+
? false
|
|
92
|
+
: process.env['NODE_ENV'] === 'development' || !!process.env['DEBUG'], }) {
|
|
94
93
|
const cacheFactory = typeof cache === 'function' ? memoize1(cache) : () => cache;
|
|
95
94
|
const ignoredTypesMap = new Set(ignoredTypes);
|
|
96
95
|
const typePerSchemaCoordinateMap = new Map();
|
|
@@ -127,14 +126,15 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
127
126
|
...(directive && {
|
|
128
127
|
[MapperKind.COMPOSITE_TYPE]: type => {
|
|
129
128
|
const cacheControlAnnotations = getDirective(schema, type, 'cacheControl');
|
|
130
|
-
cacheControlAnnotations
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
if (cacheControlAnnotations)
|
|
130
|
+
for (const cacheControl of cacheControlAnnotations) {
|
|
131
|
+
if (cacheControl.maxAge != null) {
|
|
132
|
+
ttlPerSchemaCoordinate[type.name] = cacheControl.maxAge * 1000;
|
|
133
|
+
}
|
|
134
|
+
if (cacheControl.scope) {
|
|
135
|
+
scopePerSchemaCoordinate[type.name] = cacheControl.scope;
|
|
136
|
+
}
|
|
133
137
|
}
|
|
134
|
-
if (cacheControl.scope) {
|
|
135
|
-
scopePerSchemaCoordinate[type.name] = cacheControl.scope;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
138
|
return type;
|
|
139
139
|
},
|
|
140
140
|
}),
|
|
@@ -147,14 +147,15 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
147
147
|
}
|
|
148
148
|
if (directive) {
|
|
149
149
|
const cacheControlAnnotations = getDirective(schema, fieldConfig, 'cacheControl');
|
|
150
|
-
cacheControlAnnotations
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
if (cacheControlAnnotations)
|
|
151
|
+
for (const cacheControl of cacheControlAnnotations) {
|
|
152
|
+
if (cacheControl.maxAge != null) {
|
|
153
|
+
ttlPerSchemaCoordinate[schemaCoordinates] = cacheControl.maxAge * 1000;
|
|
154
|
+
}
|
|
155
|
+
if (cacheControl.scope) {
|
|
156
|
+
scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
|
|
157
|
+
}
|
|
153
158
|
}
|
|
154
|
-
if (cacheControl.scope) {
|
|
155
|
-
scopePerSchemaCoordinate[schemaCoordinates] = cacheControl.scope;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
159
|
}
|
|
159
160
|
return fieldConfig;
|
|
160
161
|
},
|
|
@@ -165,7 +166,6 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
168
|
const identifier = new Map();
|
|
168
|
-
const types = new Set();
|
|
169
169
|
let currentTtl;
|
|
170
170
|
let skip = false;
|
|
171
171
|
const sessionId = session(onExecuteParams.args.contextValue);
|
|
@@ -201,7 +201,6 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
201
201
|
entity.id = data[idField];
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
types.add(entity.typename);
|
|
205
204
|
if (entity.typename in ttlPerSchemaCoordinate) {
|
|
206
205
|
const maybeTtl = ttlPerSchemaCoordinate[entity.typename];
|
|
207
206
|
currentTtl = calculateTtl(maybeTtl, currentTtl);
|
|
@@ -213,13 +212,14 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
213
212
|
const fieldData = data[fieldName];
|
|
214
213
|
if (fieldData == null || (Array.isArray(fieldData) && fieldData.length === 0)) {
|
|
215
214
|
const inferredTypes = typePerSchemaCoordinateMap.get(`${entity.typename}.${fieldName}`);
|
|
216
|
-
inferredTypes
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
if (inferredTypes)
|
|
216
|
+
for (const inferredType of inferredTypes) {
|
|
217
|
+
if (inferredType in ttlPerSchemaCoordinate) {
|
|
218
|
+
const maybeTtl = ttlPerSchemaCoordinate[inferredType];
|
|
219
|
+
currentTtl = calculateTtl(maybeTtl, currentTtl);
|
|
220
|
+
}
|
|
221
|
+
identifier.set(inferredType, { typename: inferredType });
|
|
220
222
|
}
|
|
221
|
-
identifier.set(inferredType, { typename: inferredType });
|
|
222
|
-
});
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -286,9 +286,7 @@ export function useResponseCache({ cache = createInMemoryCache(), ttl: globalTtl
|
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
288
|
function maybeCacheResult(result, setResult) {
|
|
289
|
-
|
|
290
|
-
result.data = removeMetadataFieldsFromResult(result.data, onEntity);
|
|
291
|
-
}
|
|
289
|
+
result.data &&= removeMetadataFieldsFromResult(result.data, onEntity);
|
|
292
290
|
// we only use the global ttl if no currentTtl has been determined.
|
|
293
291
|
let finalTtl = currentTtl ?? globalTtl;
|
|
294
292
|
if (onTtl) {
|
|
@@ -357,9 +355,7 @@ function handleAsyncIterableResult(handler) {
|
|
|
357
355
|
}
|
|
358
356
|
const newResult = { ...payload.result };
|
|
359
357
|
// Handle initial/single result
|
|
360
|
-
|
|
361
|
-
newResult.data = removeMetadataFieldsFromResult(newResult.data);
|
|
362
|
-
}
|
|
358
|
+
newResult.data &&= removeMetadataFieldsFromResult(newResult.data);
|
|
363
359
|
// Handle Incremental results
|
|
364
360
|
if ('hasNext' in newResult && newResult.incremental) {
|
|
365
361
|
newResult.incremental = newResult.incremental.map(value => {
|
|
@@ -436,14 +432,15 @@ function removeMetadataFieldsFromResult(data, onEntity) {
|
|
|
436
432
|
}
|
|
437
433
|
// clone the data to avoid mutation
|
|
438
434
|
data = { ...data };
|
|
439
|
-
const typename = data
|
|
435
|
+
const typename = data['__responseCacheTypeName'] ?? data['__typename'];
|
|
440
436
|
if (typeof typename === 'string') {
|
|
441
437
|
const entity = { typename };
|
|
442
|
-
delete data
|
|
443
|
-
if (data
|
|
444
|
-
(typeof data
|
|
445
|
-
|
|
446
|
-
|
|
438
|
+
delete data['__responseCacheTypeName'];
|
|
439
|
+
if (data['__responseCacheId'] &&
|
|
440
|
+
(typeof data['__responseCacheId'] === 'string' ||
|
|
441
|
+
typeof data['__responseCacheId'] === 'number')) {
|
|
442
|
+
entity.id = data['__responseCacheId'];
|
|
443
|
+
delete data['__responseCacheId'];
|
|
447
444
|
}
|
|
448
445
|
onEntity?.(entity, data);
|
|
449
446
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/response-cache",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
7
|
-
"@envelop/core": "^5.
|
|
6
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
|
|
7
|
+
"@envelop/core": "^5.6.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/utils": "^11.
|
|
10
|
+
"@graphql-tools/utils": "^11.2.0",
|
|
11
11
|
"@whatwg-node/fetch": "^0.10.0",
|
|
12
12
|
"@whatwg-node/promise-helpers": "^1.2.4",
|
|
13
13
|
"fast-json-stable-stringify": "^2.1.0",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "https://github.com/graphql-hive/
|
|
20
|
-
"directory": "packages/plugins/response-cache"
|
|
19
|
+
"url": "https://github.com/graphql-hive/graphql-yoga.git",
|
|
20
|
+
"directory": "packages/envelop/plugins/response-cache"
|
|
21
21
|
},
|
|
22
22
|
"author": "Kamil Kisiela <kamilkisiela@gmail.com>",
|
|
23
23
|
"license": "MIT",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
1
|
+
import type { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
2
2
|
export declare function hashSHA256(text: string): MaybePromise<string>;
|
package/typings/hash-sha256.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
1
|
+
import type { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
2
2
|
export declare function hashSHA256(text: string): MaybePromise<string>;
|
package/typings/plugin.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExecutionArgs } from 'graphql';
|
|
2
|
-
import { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
|
|
3
|
-
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
1
|
+
import type { ExecutionArgs } from 'graphql';
|
|
2
|
+
import type { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
|
|
3
|
+
import type { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
4
|
import type { Cache, CacheEntityRecord } from './cache.cjs';
|
|
5
5
|
/**
|
|
6
6
|
* Function for building the response cache key based on the input parameters
|
|
@@ -122,7 +122,7 @@ export type ResponseCacheOnTtlFunction<PluginContext> = (payload: {
|
|
|
122
122
|
*/
|
|
123
123
|
export declare const defaultBuildResponseCacheKey: (params: {
|
|
124
124
|
documentString: string;
|
|
125
|
-
variableValues: ExecutionArgs[
|
|
125
|
+
variableValues: ExecutionArgs['variableValues'];
|
|
126
126
|
operationName?: Maybe<string>;
|
|
127
127
|
sessionId: Maybe<string>;
|
|
128
128
|
}) => MaybePromise<string>;
|
|
@@ -151,6 +151,6 @@ export type ResponseCacheExtensions = {
|
|
|
151
151
|
export type ResponseCacheExecutionResult = ExecutionResult<ObjMap<unknown>, {
|
|
152
152
|
responseCache?: ResponseCacheExtensions;
|
|
153
153
|
}>;
|
|
154
|
-
export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata
|
|
154
|
+
export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
|
|
155
155
|
export declare function resultWithMetadata(result: ExecutionResult, metadata: ResponseCacheExtensions): ResponseCacheExecutionResult;
|
|
156
156
|
export declare const cacheControlDirective = "\n enum CacheControlScope {\n PUBLIC\n PRIVATE\n }\n\n directive @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT\n";
|
package/typings/plugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExecutionArgs } from 'graphql';
|
|
2
|
-
import { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
|
|
3
|
-
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
1
|
+
import type { ExecutionArgs } from 'graphql';
|
|
2
|
+
import type { ExecutionResult, Maybe, ObjMap, Plugin } from '@envelop/core';
|
|
3
|
+
import type { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
4
4
|
import type { Cache, CacheEntityRecord } from './cache.js';
|
|
5
5
|
/**
|
|
6
6
|
* Function for building the response cache key based on the input parameters
|
|
@@ -122,7 +122,7 @@ export type ResponseCacheOnTtlFunction<PluginContext> = (payload: {
|
|
|
122
122
|
*/
|
|
123
123
|
export declare const defaultBuildResponseCacheKey: (params: {
|
|
124
124
|
documentString: string;
|
|
125
|
-
variableValues: ExecutionArgs[
|
|
125
|
+
variableValues: ExecutionArgs['variableValues'];
|
|
126
126
|
operationName?: Maybe<string>;
|
|
127
127
|
sessionId: Maybe<string>;
|
|
128
128
|
}) => MaybePromise<string>;
|
|
@@ -151,6 +151,6 @@ export type ResponseCacheExtensions = {
|
|
|
151
151
|
export type ResponseCacheExecutionResult = ExecutionResult<ObjMap<unknown>, {
|
|
152
152
|
responseCache?: ResponseCacheExtensions;
|
|
153
153
|
}>;
|
|
154
|
-
export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata
|
|
154
|
+
export declare function useResponseCache<PluginContext extends Record<string, any> = {}>({ cache, ttl: globalTtl, session, enabled, ignoredTypes, ttlPerType, ttlPerSchemaCoordinate, scopePerSchemaCoordinate, idFields, invalidateViaMutation, buildResponseCacheKey, getDocumentString, shouldCacheResult, onTtl, includeExtensionMetadata }: UseResponseCacheParameter<PluginContext>): Plugin<PluginContext>;
|
|
155
155
|
export declare function resultWithMetadata(result: ExecutionResult, metadata: ResponseCacheExtensions): ResponseCacheExecutionResult;
|
|
156
156
|
export declare const cacheControlDirective = "\n enum CacheControlScope {\n PUBLIC\n PRIVATE\n }\n\n directive @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT\n";
|