@envelop/graphql-jit 5.0.0-alpha-d0d0776.0 → 5.0.0-alpha-ccec0fc.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 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) => { ... } // custom error handler
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(), // Pass in a custom cache instance, by default a new LRU cache is created which uses the default `max` and `ttl` settings
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
@@ -1,32 +1,35 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const core = require('@envelop/core');
6
- const graphql = require('graphql');
7
- const graphqlJit = require('graphql-jit');
8
- const lru = require('tiny-lru');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- const lru__default = /*#__PURE__*/_interopDefaultLegacy(lru);
13
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGraphQlJit = void 0;
4
+ const tslib_1 = require("tslib");
14
5
  /* eslint-disable no-console */
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-nocheck MAKE ME WORK
8
+ const core_1 = require("@envelop/core");
9
+ const graphql_1 = require("@graphql-tools/graphql");
10
+ const graphql_jit_1 = require("graphql-jit");
11
+ const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
12
+ const compat_1 = require("@graphql-tools/compat");
15
13
  const DEFAULT_MAX = 1000;
16
14
  const DEFAULT_TTL = 3600000;
17
15
  const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
18
16
  const documentSourceMap = new WeakMap();
19
- const jitCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru__default["default"](DEFAULT_MAX, DEFAULT_TTL);
17
+ const jitCache = typeof pluginOptions.cache !== 'undefined'
18
+ ? pluginOptions.cache
19
+ : new lru_cache_1.default({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
20
20
  function getCacheEntry(args) {
21
+ var _a;
21
22
  let cacheEntry;
22
23
  const documentSource = documentSourceMap.get(args.document);
23
24
  if (documentSource) {
24
25
  cacheEntry = jitCache.get(documentSource);
25
26
  }
26
27
  if (!cacheEntry) {
27
- const compilationResult = graphqlJit.compileQuery(args.schema, args.document, args.operationName ?? undefined, compilerOptions);
28
- if (!graphqlJit.isCompiledQuery(compilationResult)) {
29
- if (pluginOptions?.onError) {
28
+ // TODO: CACHE ME
29
+ const schema = compat_1.compatSchema.toGraphQLJS(args.schema);
30
+ const compilationResult = (0, graphql_jit_1.compileQuery)(schema, args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined, compilerOptions);
31
+ if (!(0, graphql_jit_1.isCompiledQuery)(compilationResult)) {
32
+ if (pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.onError) {
30
33
  pluginOptions.onError(compilationResult);
31
34
  }
32
35
  else {
@@ -47,7 +50,7 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
47
50
  }
48
51
  return {
49
52
  onParse({ params: { source } }) {
50
- const key = source instanceof graphql.Source ? source.body : source;
53
+ const key = source instanceof graphql_1.Source ? source.body : source;
51
54
  return ({ result }) => {
52
55
  if (!result || result instanceof Error)
53
56
  return;
@@ -56,7 +59,7 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
56
59
  },
57
60
  async onExecute({ args, setExecuteFn }) {
58
61
  if (!pluginOptions.enableIf || (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
59
- setExecuteFn(core.makeExecute(function jitExecutor(args) {
62
+ setExecuteFn((0, core_1.makeExecute)(function jitExecutor(args) {
60
63
  const cacheEntry = getCacheEntry(args);
61
64
  return cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
62
65
  }));
@@ -64,7 +67,7 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
64
67
  },
65
68
  async onSubscribe({ args, setSubscribeFn }) {
66
69
  if (!pluginOptions.enableIf || (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
67
- setSubscribeFn(core.makeSubscribe(async function jitSubscriber(args) {
70
+ setSubscribeFn((0, core_1.makeSubscribe)(async function jitSubscriber(args) {
68
71
  const cacheEntry = getCacheEntry(args);
69
72
  return cacheEntry.subscribe
70
73
  ? cacheEntry.subscribe(args.rootValue, args.contextValue, args.variableValues)
@@ -74,5 +77,4 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
74
77
  },
75
78
  };
76
79
  };
77
-
78
80
  exports.useGraphQlJit = useGraphQlJit;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,24 +1,31 @@
1
+ /* eslint-disable no-console */
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-nocheck MAKE ME WORK
1
4
  import { makeExecute, makeSubscribe } from '@envelop/core';
2
- import { Source } from 'graphql';
5
+ import { Source } from '@graphql-tools/graphql';
3
6
  import { compileQuery, isCompiledQuery } from 'graphql-jit';
4
- import lru from 'tiny-lru';
5
-
6
- /* eslint-disable no-console */
7
+ import LRU from 'lru-cache';
8
+ import { compatSchema } from '@graphql-tools/compat';
7
9
  const DEFAULT_MAX = 1000;
8
10
  const DEFAULT_TTL = 3600000;
9
- const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
11
+ export const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
10
12
  const documentSourceMap = new WeakMap();
11
- const jitCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL);
13
+ const jitCache = typeof pluginOptions.cache !== 'undefined'
14
+ ? pluginOptions.cache
15
+ : new LRU({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
12
16
  function getCacheEntry(args) {
17
+ var _a;
13
18
  let cacheEntry;
14
19
  const documentSource = documentSourceMap.get(args.document);
15
20
  if (documentSource) {
16
21
  cacheEntry = jitCache.get(documentSource);
17
22
  }
18
23
  if (!cacheEntry) {
19
- const compilationResult = compileQuery(args.schema, args.document, args.operationName ?? undefined, compilerOptions);
24
+ // TODO: CACHE ME
25
+ const schema = compatSchema.toGraphQLJS(args.schema);
26
+ const compilationResult = compileQuery(schema, args.document, (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined, compilerOptions);
20
27
  if (!isCompiledQuery(compilationResult)) {
21
- if (pluginOptions?.onError) {
28
+ if (pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.onError) {
22
29
  pluginOptions.onError(compilationResult);
23
30
  }
24
31
  else {
@@ -66,5 +73,3 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
66
73
  },
67
74
  };
68
75
  };
69
-
70
- export { useGraphQlJit };
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@envelop/graphql-jit",
3
- "version": "5.0.0-alpha-d0d0776.0",
3
+ "version": "5.0.0-alpha-ccec0fc.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
6
+ "@envelop/core": "3.0.0-alpha-ccec0fc.0",
7
+ "@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0",
8
+ "graphql": "^15 | ^16"
8
9
  },
9
10
  "dependencies": {
11
+ "@graphql-tools/compat": "0.0.1-alpha-e7752ba5.0",
10
12
  "graphql-jit": "^0.7.0",
11
- "tiny-lru": "7.0.6"
13
+ "lru-cache": "^6.0.0"
12
14
  },
13
15
  "repository": {
14
16
  "type": "git",
@@ -17,33 +19,42 @@
17
19
  },
18
20
  "author": "Dotan Simha <dotansimha@gmail.com>",
19
21
  "license": "MIT",
20
- "main": "index.js",
21
- "module": "index.mjs",
22
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
23
25
  "typescript": {
24
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
25
27
  },
28
+ "type": "module",
26
29
  "exports": {
27
30
  ".": {
28
31
  "require": {
29
- "default": "./index.js",
30
- "types": "./index.d.ts"
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./cjs/index.js"
31
34
  },
32
35
  "import": {
33
- "default": "./index.mjs",
34
- "types": "./index.d.ts"
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ },
39
+ "default": {
40
+ "types": "./typings/index.d.ts",
41
+ "default": "./esm/index.js"
35
42
  }
36
43
  },
37
44
  "./*": {
38
45
  "require": {
39
- "default": "./*.js",
40
- "types": "./*.d.ts"
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./cjs/*.js"
41
48
  },
42
49
  "import": {
43
- "default": "./*.mjs",
44
- "types": "./*.d.ts"
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
52
+ },
53
+ "default": {
54
+ "types": "./typings/*.d.ts",
55
+ "default": "./esm/*.js"
45
56
  }
46
57
  },
47
58
  "./package.json": "./package.json"
48
59
  }
49
- }
60
+ }
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from '@envelop/core';
2
- import { ExecutionArgs, ExecutionResult } from 'graphql';
2
+ import { ExecutionArgs, ExecutionResult } from '@graphql-tools/graphql';
3
3
  import { CompilerOptions, CompiledQuery } from 'graphql-jit';
4
4
  declare type JITCacheEntry = {
5
5
  query: CompiledQuery['query'];