@envelop/graphql-jit 4.3.0 → 4.4.0-alpha-98c6b00.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/README.md +18 -18
- package/cjs/index.js +4 -2
- package/esm/index.js +4 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ yarn add @envelop/graphql-jit
|
|
|
11
11
|
## Usage Example
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { envelop } from '@envelop/core'
|
|
15
|
-
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
14
|
+
import { envelop } from '@envelop/core'
|
|
15
|
+
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
16
16
|
|
|
17
17
|
const getEnveloped = envelop({
|
|
18
18
|
plugins: [
|
|
@@ -22,11 +22,11 @@ const getEnveloped = envelop({
|
|
|
22
22
|
// your compiler options here. See https://github.com/zalando-incubator/graphql-jit#compiledquery--compilequeryschema-document-operationname-compileroptions
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
onError: (e: Error) => {
|
|
25
|
+
onError: (e: Error) => {} // custom error handler
|
|
26
26
|
}
|
|
27
|
-
)
|
|
28
|
-
]
|
|
29
|
-
})
|
|
27
|
+
)
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
## Conditional Execution
|
|
@@ -34,8 +34,8 @@ const getEnveloped = envelop({
|
|
|
34
34
|
If you wish to conditionally use the JIT executor based on the incoming request, you can use `enableIf` config flag and return a `boolean` based on the `ExecutionArgs`:
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
import { envelop } from '@envelop/core'
|
|
38
|
-
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
37
|
+
import { envelop } from '@envelop/core'
|
|
38
|
+
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
39
39
|
|
|
40
40
|
const getEnveloped = envelop({
|
|
41
41
|
plugins: [
|
|
@@ -45,11 +45,11 @@ const getEnveloped = envelop({
|
|
|
45
45
|
// your compiler options here. See https://github.com/zalando-incubator/graphql-jit#compiledquery--compilequeryschema-document-operationname-compileroptions
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
enableIf: executionArgs => executionArgs.contextValue.shouldUseJit
|
|
48
|
+
enableIf: executionArgs => executionArgs.contextValue.shouldUseJit
|
|
49
49
|
}
|
|
50
|
-
)
|
|
51
|
-
]
|
|
52
|
-
})
|
|
50
|
+
)
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
## Configuring JIT cache
|
|
@@ -57,8 +57,8 @@ const getEnveloped = envelop({
|
|
|
57
57
|
You can configure the JIT cache with the following options:
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
|
-
import { envelop } from '@envelop/core'
|
|
61
|
-
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
60
|
+
import { envelop } from '@envelop/core'
|
|
61
|
+
import { useGraphQlJit } from '@envelop/graphql-jit'
|
|
62
62
|
|
|
63
63
|
const getEnveloped = envelop({
|
|
64
64
|
plugins: [
|
|
@@ -68,11 +68,11 @@ const getEnveloped = envelop({
|
|
|
68
68
|
// your compiler options here
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
cache: lru()
|
|
71
|
+
cache: lru() // Pass in a custom cache instance, by default a new LRU cache is created which uses the default `max` and `ttl` settings
|
|
72
72
|
}
|
|
73
|
-
)
|
|
74
|
-
]
|
|
75
|
-
})
|
|
73
|
+
)
|
|
74
|
+
]
|
|
75
|
+
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
## Notes
|
package/cjs/index.js
CHANGED
|
@@ -6,12 +6,14 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const core_1 = require("@envelop/core");
|
|
7
7
|
const graphql_1 = require("graphql");
|
|
8
8
|
const graphql_jit_1 = require("graphql-jit");
|
|
9
|
-
const
|
|
9
|
+
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
10
10
|
const DEFAULT_MAX = 1000;
|
|
11
11
|
const DEFAULT_TTL = 3600000;
|
|
12
12
|
const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
|
|
13
13
|
const documentSourceMap = new WeakMap();
|
|
14
|
-
const jitCache = typeof pluginOptions.cache !== 'undefined'
|
|
14
|
+
const jitCache = typeof pluginOptions.cache !== 'undefined'
|
|
15
|
+
? pluginOptions.cache
|
|
16
|
+
: new lru_cache_1.default({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
15
17
|
function getCacheEntry(args) {
|
|
16
18
|
var _a;
|
|
17
19
|
let cacheEntry;
|
package/esm/index.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { makeExecute, makeSubscribe } from '@envelop/core';
|
|
3
3
|
import { Source } from 'graphql';
|
|
4
4
|
import { compileQuery, isCompiledQuery } from 'graphql-jit';
|
|
5
|
-
import
|
|
5
|
+
import LRU from 'lru-cache';
|
|
6
6
|
const DEFAULT_MAX = 1000;
|
|
7
7
|
const DEFAULT_TTL = 3600000;
|
|
8
8
|
export const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
|
|
9
9
|
const documentSourceMap = new WeakMap();
|
|
10
|
-
const jitCache = typeof pluginOptions.cache !== 'undefined'
|
|
10
|
+
const jitCache = typeof pluginOptions.cache !== 'undefined'
|
|
11
|
+
? pluginOptions.cache
|
|
12
|
+
: new LRU({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
11
13
|
function getCacheEntry(args) {
|
|
12
14
|
var _a;
|
|
13
15
|
let cacheEntry;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/graphql-jit",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-alpha-98c6b00.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"@envelop/core": "^2.4.0",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"graphql-jit": "^0.7.0",
|
|
11
|
-
"
|
|
11
|
+
"lru-cache": "^6.0.0"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|