@envelop/graphql-jit 6.0.4 → 6.0.5-alpha-20230928192808-d2969aaa

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 CHANGED
@@ -29,6 +29,7 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
29
29
  }
30
30
  cacheEntry = {
31
31
  query: () => compilationResult,
32
+ stringify: r => JSON.stringify(r),
32
33
  };
33
34
  }
34
35
  else {
@@ -47,7 +48,15 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
47
48
  (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
48
49
  setExecuteFn((0, core_1.makeExecute)(function jitExecutor(args) {
49
50
  const cacheEntry = getCacheEntry(args);
50
- return cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
51
+ const result$ = cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
52
+ if (isPromise(result$)) {
53
+ return result$.then(r => {
54
+ r.stringify = cacheEntry.stringify;
55
+ return r;
56
+ });
57
+ }
58
+ result$.stringify = cacheEntry.stringify;
59
+ return result$;
51
60
  }));
52
61
  }
53
62
  },
@@ -56,12 +65,23 @@ const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
56
65
  (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
57
66
  setSubscribeFn((0, core_1.makeSubscribe)(async function jitSubscriber(args) {
58
67
  const cacheEntry = getCacheEntry(args);
59
- return cacheEntry.subscribe
68
+ const result$ = cacheEntry.subscribe
60
69
  ? cacheEntry.subscribe(args.rootValue, args.contextValue, args.variableValues)
61
70
  : cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
71
+ if (isPromise(result$)) {
72
+ return result$.then(r => {
73
+ r.stringify = cacheEntry.stringify;
74
+ return r;
75
+ });
76
+ }
77
+ result$.stringify = cacheEntry.stringify;
78
+ return result$;
62
79
  }));
63
80
  }
64
81
  },
65
82
  };
66
83
  };
67
84
  exports.useGraphQlJit = useGraphQlJit;
85
+ function isPromise(p) {
86
+ return p?.then != null;
87
+ }
package/esm/index.js CHANGED
@@ -26,6 +26,7 @@ export const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
26
26
  }
27
27
  cacheEntry = {
28
28
  query: () => compilationResult,
29
+ stringify: r => JSON.stringify(r),
29
30
  };
30
31
  }
31
32
  else {
@@ -44,7 +45,15 @@ export const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
44
45
  (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
45
46
  setExecuteFn(makeExecute(function jitExecutor(args) {
46
47
  const cacheEntry = getCacheEntry(args);
47
- return cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
48
+ const result$ = cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
49
+ if (isPromise(result$)) {
50
+ return result$.then(r => {
51
+ r.stringify = cacheEntry.stringify;
52
+ return r;
53
+ });
54
+ }
55
+ result$.stringify = cacheEntry.stringify;
56
+ return result$;
48
57
  }));
49
58
  }
50
59
  },
@@ -53,11 +62,22 @@ export const useGraphQlJit = (compilerOptions = {}, pluginOptions = {}) => {
53
62
  (pluginOptions.enableIf && (await pluginOptions.enableIf(args)))) {
54
63
  setSubscribeFn(makeSubscribe(async function jitSubscriber(args) {
55
64
  const cacheEntry = getCacheEntry(args);
56
- return cacheEntry.subscribe
65
+ const result$ = cacheEntry.subscribe
57
66
  ? cacheEntry.subscribe(args.rootValue, args.contextValue, args.variableValues)
58
67
  : cacheEntry.query(args.rootValue, args.contextValue, args.variableValues);
68
+ if (isPromise(result$)) {
69
+ return result$.then(r => {
70
+ r.stringify = cacheEntry.stringify;
71
+ return r;
72
+ });
73
+ }
74
+ result$.stringify = cacheEntry.stringify;
75
+ return result$;
59
76
  }));
60
77
  }
61
78
  },
62
79
  };
63
80
  };
81
+ function isPromise(p) {
82
+ return p?.then != null;
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envelop/graphql-jit",
3
- "version": "6.0.4",
3
+ "version": "6.0.5-alpha-20230928192808-d2969aaa",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@envelop/core": "^4.0.3",
@@ -1,9 +1,14 @@
1
1
  import { ExecutionArgs, ExecutionResult } from 'graphql';
2
2
  import { CompiledQuery, CompilerOptions } from 'graphql-jit';
3
3
  import { Plugin } from '@envelop/core';
4
+ type JSONStringifier = (result: any) => string;
4
5
  type JITCacheEntry = {
5
6
  query: CompiledQuery['query'];
6
7
  subscribe?: CompiledQuery['subscribe'];
8
+ stringify: JSONStringifier;
9
+ };
10
+ export type ExecutionResultWithSerializer = ExecutionResult & {
11
+ stringify?: JSONStringifier;
7
12
  };
8
13
  export interface JITCache {
9
14
  get(key: string): JITCacheEntry | undefined;
@@ -17,7 +22,7 @@ export declare const useGraphQlJit: (compilerOptions?: Partial<CompilerOptions>,
17
22
  /**
18
23
  * Callback triggered in case of GraphQL Jit compilation error.
19
24
  */
20
- onError?: ((r: ExecutionResult) => void) | undefined;
25
+ onError?: ((r: ExecutionResultWithSerializer) => void) | undefined;
21
26
  /**
22
27
  * Custom cache instance
23
28
  */
@@ -1,9 +1,14 @@
1
1
  import { ExecutionArgs, ExecutionResult } from 'graphql';
2
2
  import { CompiledQuery, CompilerOptions } from 'graphql-jit';
3
3
  import { Plugin } from '@envelop/core';
4
+ type JSONStringifier = (result: any) => string;
4
5
  type JITCacheEntry = {
5
6
  query: CompiledQuery['query'];
6
7
  subscribe?: CompiledQuery['subscribe'];
8
+ stringify: JSONStringifier;
9
+ };
10
+ export type ExecutionResultWithSerializer = ExecutionResult & {
11
+ stringify?: JSONStringifier;
7
12
  };
8
13
  export interface JITCache {
9
14
  get(key: string): JITCacheEntry | undefined;
@@ -17,7 +22,7 @@ export declare const useGraphQlJit: (compilerOptions?: Partial<CompilerOptions>,
17
22
  /**
18
23
  * Callback triggered in case of GraphQL Jit compilation error.
19
24
  */
20
- onError?: ((r: ExecutionResult) => void) | undefined;
25
+ onError?: ((r: ExecutionResultWithSerializer) => void) | undefined;
21
26
  /**
22
27
  * Custom cache instance
23
28
  */