@envelop/persisted-operations 4.4.0-alpha-e9434aa.0 → 4.4.0-alpha-05dbec7.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/esm/index.js +6 -22
- package/esm/plugin.js +9 -14
- package/esm/stores/aggregated-store.js +1 -5
- package/esm/stores/inmemory-store.js +1 -5
- package/esm/stores/json-file-store.js +4 -8
- package/esm/types.js +1 -2
- package/esm/utils.js +1 -5
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types.js"), exports);
|
|
18
|
-
__exportStar(require("./utils.js"), exports);
|
|
19
|
-
__exportStar(require("./stores/aggregated-store.js"), exports);
|
|
20
|
-
__exportStar(require("./stores/inmemory-store.js"), exports);
|
|
21
|
-
__exportStar(require("./stores/json-file-store.js"), exports);
|
|
22
|
-
__exportStar(require("./plugin.js"), exports);
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from './stores/aggregated-store.js';
|
|
4
|
+
export * from './stores/inmemory-store.js';
|
|
5
|
+
export * from './stores/json-file-store.js';
|
|
6
|
+
export * from './plugin.js';
|
package/esm/plugin.js
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.usePersistedOperations = exports.readOperationId = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
1
|
+
import { GraphQLError, parse } from 'graphql';
|
|
2
|
+
import { operationIdFromSource } from './utils.js';
|
|
6
3
|
const DEFAULT_OPTIONS = {
|
|
7
4
|
onlyPersisted: false,
|
|
8
5
|
};
|
|
9
6
|
const contextProperty = Symbol('persistedOperationId');
|
|
10
|
-
function readOperationId(context) {
|
|
7
|
+
export function readOperationId(context) {
|
|
11
8
|
return context[contextProperty];
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
const usePersistedOperations = (rawOptions) => {
|
|
10
|
+
export const usePersistedOperations = (rawOptions) => {
|
|
15
11
|
const options = {
|
|
16
12
|
...DEFAULT_OPTIONS,
|
|
17
13
|
...(rawOptions || {}),
|
|
18
14
|
};
|
|
19
15
|
return {
|
|
20
16
|
onParse({ context, params, extendContext, setParsedDocument }) {
|
|
21
|
-
const operationId = options.extractOperationId ? options.extractOperationId(context) :
|
|
17
|
+
const operationId = options.extractOperationId ? options.extractOperationId(context) : operationIdFromSource(params.source);
|
|
22
18
|
if (!operationId) {
|
|
23
19
|
if (options.onlyPersisted) {
|
|
24
|
-
throw new
|
|
20
|
+
throw new GraphQLError('Must provide operation id');
|
|
25
21
|
}
|
|
26
22
|
return;
|
|
27
23
|
}
|
|
28
24
|
const store = typeof options.store === 'function' ? options.store(context) : options.store;
|
|
29
25
|
if (!store) {
|
|
30
|
-
throw new
|
|
26
|
+
throw new GraphQLError('Must provide store for persisted-operations!');
|
|
31
27
|
}
|
|
32
28
|
const rawResult = store.get(operationId);
|
|
33
29
|
if (rawResult) {
|
|
34
|
-
const document = typeof rawResult === 'string' ?
|
|
30
|
+
const document = typeof rawResult === 'string' ? parse(rawResult) : rawResult;
|
|
35
31
|
extendContext({ [contextProperty]: operationId });
|
|
36
32
|
setParsedDocument(document);
|
|
37
33
|
return;
|
|
@@ -40,11 +36,10 @@ const usePersistedOperations = (rawOptions) => {
|
|
|
40
36
|
options.onMissingMatch(context, operationId);
|
|
41
37
|
if (options.onlyPersisted) {
|
|
42
38
|
// we want to throw an error only when "onlyPersisted" is true, otherwise we let execution continue normally
|
|
43
|
-
throw new
|
|
39
|
+
throw new GraphQLError(`Unable to match operation with id '${operationId}'`);
|
|
44
40
|
}
|
|
45
41
|
// if we reach this stage we could not retrieve a persisted operation and we didn't throw any error as onlyPersisted is false
|
|
46
42
|
// hence we let operation continue assuming consumer is not passing an operation id, but a plain query string, with current request.
|
|
47
43
|
},
|
|
48
44
|
};
|
|
49
45
|
};
|
|
50
|
-
exports.usePersistedOperations = usePersistedOperations;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AggregatedStore = void 0;
|
|
4
|
-
class AggregatedStore {
|
|
1
|
+
export class AggregatedStore {
|
|
5
2
|
constructor(stores) {
|
|
6
3
|
this.stores = stores;
|
|
7
4
|
}
|
|
@@ -15,4 +12,3 @@ class AggregatedStore {
|
|
|
15
12
|
return undefined;
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.AggregatedStore = AggregatedStore;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InMemoryStore = void 0;
|
|
4
|
-
class InMemoryStore {
|
|
1
|
+
export class InMemoryStore {
|
|
5
2
|
constructor(options) {
|
|
6
3
|
var _a;
|
|
7
4
|
this.storeData = (_a = options === null || options === void 0 ? void 0 : options.initialData) !== null && _a !== void 0 ? _a : new Map();
|
|
@@ -16,4 +13,3 @@ class InMemoryStore {
|
|
|
16
13
|
this.storeData.delete(operationId);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.InMemoryStore = InMemoryStore;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.JsonFileStore = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
class JsonFileStore {
|
|
1
|
+
import { readFileSync, promises } from 'fs';
|
|
2
|
+
export class JsonFileStore {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.storeData = null;
|
|
8
5
|
}
|
|
@@ -13,12 +10,11 @@ class JsonFileStore {
|
|
|
13
10
|
return this.storeData.get(operationId) || undefined;
|
|
14
11
|
}
|
|
15
12
|
loadFromFileSync(path) {
|
|
16
|
-
const data = JSON.parse(
|
|
13
|
+
const data = JSON.parse(readFileSync(path, 'utf-8'));
|
|
17
14
|
this.storeData = new Map(Object.entries(data));
|
|
18
15
|
}
|
|
19
16
|
async loadFromFile(path) {
|
|
20
|
-
const data = JSON.parse(await
|
|
17
|
+
const data = JSON.parse(await promises.readFile(path, 'utf-8'));
|
|
21
18
|
this.storeData = new Map(Object.entries(data));
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
exports.JsonFileStore = JsonFileStore;
|
package/esm/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/esm/utils.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.operationIdFromSource = void 0;
|
|
4
|
-
function operationIdFromSource(source) {
|
|
1
|
+
export function operationIdFromSource(source) {
|
|
5
2
|
return typeof source === 'string' && source.length && source.indexOf('{') === -1 ? source : undefined;
|
|
6
3
|
}
|
|
7
|
-
exports.operationIdFromSource = operationIdFromSource;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/persisted-operations",
|
|
3
|
-
"version": "4.4.0-alpha-
|
|
3
|
+
"version": "4.4.0-alpha-05dbec7.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-05dbec7.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|