@graphql-mesh/transform-cache 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648

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.
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeCacheKey = void 0;
4
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
5
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
6
+ function computeCacheKey(options) {
7
+ const argsHash = options.args ? (0, string_interpolation_1.hashObject)(options.args) : '';
8
+ const fieldNamesHash = (0, string_interpolation_1.hashObject)(options.info.fieldNodes);
9
+ if (!options.keyStr) {
10
+ return `${options.info.parentType.name}-${options.info.fieldName}-${argsHash}-${fieldNamesHash}`;
11
+ }
12
+ const templateData = {
13
+ typeName: options.info.parentType.name,
14
+ fieldName: options.info.fieldName,
15
+ args: options.args,
16
+ argsHash,
17
+ fieldNamesHash,
18
+ info: options.info || null,
19
+ env: cross_helpers_1.process.env,
20
+ };
21
+ return string_interpolation_1.stringInterpolator.parse(options.keyStr, templateData);
22
+ }
23
+ exports.computeCacheKey = computeCacheKey;
@@ -1,46 +1,26 @@
1
- 'use strict';
2
-
3
- const resolversComposition = require('@graphql-tools/resolvers-composition');
4
- const stringInterpolation = require('@graphql-mesh/string-interpolation');
5
- const crossHelpers = require('@graphql-mesh/cross-helpers');
6
- const utils = require('@graphql-mesh/utils');
7
- const schema = require('@graphql-tools/schema');
8
-
9
- function computeCacheKey(options) {
10
- const argsHash = options.args ? stringInterpolation.hashObject(options.args) : '';
11
- const fieldNamesHash = stringInterpolation.hashObject(options.info.fieldNodes);
12
- if (!options.keyStr) {
13
- return `${options.info.parentType.name}-${options.info.fieldName}-${argsHash}-${fieldNamesHash}`;
14
- }
15
- const templateData = {
16
- typeName: options.info.parentType.name,
17
- fieldName: options.info.fieldName,
18
- args: options.args,
19
- argsHash,
20
- fieldNamesHash,
21
- info: options.info || null,
22
- env: crossHelpers.process.env,
23
- };
24
- return stringInterpolation.stringInterpolator.parse(options.keyStr, templateData);
25
- }
26
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@graphql-mesh/utils");
4
+ const resolvers_composition_1 = require("@graphql-tools/resolvers-composition");
5
+ const schema_1 = require("@graphql-tools/schema");
6
+ const compute_cache_key_js_1 = require("./compute-cache-key.js");
27
7
  class CacheTransform {
28
8
  constructor(options) {
29
9
  this.options = options;
30
10
  this.noWrap = true;
31
11
  this.shouldWaitLocal = {};
32
12
  }
33
- transformSchema(schema$1) {
13
+ transformSchema(schema) {
34
14
  var _a;
35
15
  const { config, cache } = this.options;
36
- const sourceResolvers = utils.extractResolvers(schema$1);
16
+ const sourceResolvers = (0, utils_1.extractResolvers)(schema);
37
17
  const compositions = {};
38
18
  for (const cacheItem of config) {
39
19
  const effectingOperations = ((_a = cacheItem.invalidate) === null || _a === void 0 ? void 0 : _a.effectingOperations) || [];
40
20
  for (const { operation, matchKey } of effectingOperations) {
41
21
  compositions[operation] = originalResolver => async (root, args, context, info) => {
42
22
  const result = await originalResolver(root, args, context, info);
43
- const cacheKey = computeCacheKey({
23
+ const cacheKey = (0, compute_cache_key_js_1.computeCacheKey)({
44
24
  keyStr: matchKey,
45
25
  args,
46
26
  info,
@@ -51,7 +31,7 @@ class CacheTransform {
51
31
  }
52
32
  compositions[cacheItem.field] = originalResolver => async (root, args, context, info) => {
53
33
  var _a, _b;
54
- const cacheKey = computeCacheKey({
34
+ const cacheKey = (0, compute_cache_key_js_1.computeCacheKey)({
55
35
  keyStr: cacheItem.cacheKey,
56
36
  args,
57
37
  info,
@@ -96,9 +76,9 @@ class CacheTransform {
96
76
  }
97
77
  };
98
78
  }
99
- const wrappedResolvers = resolversComposition.composeResolvers(sourceResolvers, compositions);
100
- return schema.addResolversToSchema({
101
- schema: schema$1,
79
+ const wrappedResolvers = (0, resolvers_composition_1.composeResolvers)(sourceResolvers, compositions);
80
+ return (0, schema_1.addResolversToSchema)({
81
+ schema,
102
82
  resolvers: wrappedResolvers,
103
83
  updateResolversInPlace: true,
104
84
  });
@@ -148,5 +128,4 @@ class CacheTransform {
148
128
  });
149
129
  }
150
130
  }
151
-
152
- module.exports = CacheTransform;
131
+ exports.default = CacheTransform;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,19 @@
1
+ import { process } from '@graphql-mesh/cross-helpers';
2
+ import { hashObject, stringInterpolator } from '@graphql-mesh/string-interpolation';
3
+ export function computeCacheKey(options) {
4
+ const argsHash = options.args ? hashObject(options.args) : '';
5
+ const fieldNamesHash = hashObject(options.info.fieldNodes);
6
+ if (!options.keyStr) {
7
+ return `${options.info.parentType.name}-${options.info.fieldName}-${argsHash}-${fieldNamesHash}`;
8
+ }
9
+ const templateData = {
10
+ typeName: options.info.parentType.name,
11
+ fieldName: options.info.fieldName,
12
+ args: options.args,
13
+ argsHash,
14
+ fieldNamesHash,
15
+ info: options.info || null,
16
+ env: process.env,
17
+ };
18
+ return stringInterpolator.parse(options.keyStr, templateData);
19
+ }
@@ -1,28 +1,8 @@
1
- import { composeResolvers } from '@graphql-tools/resolvers-composition';
2
- import { hashObject, stringInterpolator } from '@graphql-mesh/string-interpolation';
3
- import { process } from '@graphql-mesh/cross-helpers';
4
1
  import { extractResolvers } from '@graphql-mesh/utils';
2
+ import { composeResolvers } from '@graphql-tools/resolvers-composition';
5
3
  import { addResolversToSchema } from '@graphql-tools/schema';
6
-
7
- function computeCacheKey(options) {
8
- const argsHash = options.args ? hashObject(options.args) : '';
9
- const fieldNamesHash = hashObject(options.info.fieldNodes);
10
- if (!options.keyStr) {
11
- return `${options.info.parentType.name}-${options.info.fieldName}-${argsHash}-${fieldNamesHash}`;
12
- }
13
- const templateData = {
14
- typeName: options.info.parentType.name,
15
- fieldName: options.info.fieldName,
16
- args: options.args,
17
- argsHash,
18
- fieldNamesHash,
19
- info: options.info || null,
20
- env: process.env,
21
- };
22
- return stringInterpolator.parse(options.keyStr, templateData);
23
- }
24
-
25
- class CacheTransform {
4
+ import { computeCacheKey } from './compute-cache-key.js';
5
+ export default class CacheTransform {
26
6
  constructor(options) {
27
7
  this.options = options;
28
8
  this.noWrap = true;
@@ -146,5 +126,3 @@ class CacheTransform {
146
126
  });
147
127
  }
148
128
  }
149
-
150
- export default CacheTransform;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transform-cache",
3
- "version": "1.0.0-alpha-3fc47d119.0",
3
+ "version": "1.0.0-alpha-20230420181317-a95037648",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-3fc47d119.0",
7
- "@graphql-mesh/utils": "1.0.0-alpha-3fc47d119.0",
8
- "graphql": "*"
6
+ "@graphql-mesh/cross-helpers": "^0.3.4",
7
+ "@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
8
+ "@graphql-mesh/utils": "1.0.0-alpha-20230420181317-a95037648",
9
+ "@graphql-tools/utils": "^9.2.1",
10
+ "graphql": "*",
11
+ "tslib": "^2.4.0"
9
12
  },
10
13
  "dependencies": {
11
- "@graphql-mesh/cross-helpers": "0.2.0",
12
- "@graphql-mesh/string-interpolation": "0.3.0",
13
- "@graphql-tools/resolvers-composition": "6.5.0",
14
- "@graphql-tools/schema": "8.5.0",
15
- "@graphql-tools/utils": "8.8.0",
16
- "dayjs": "1.11.4",
17
- "tslib": "^2.4.0"
14
+ "@graphql-mesh/string-interpolation": "0.4.4",
15
+ "@graphql-tools/resolvers-composition": "6.5.18",
16
+ "@graphql-tools/schema": "9.0.18",
17
+ "dayjs": "1.11.7"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -22,21 +22,28 @@
22
22
  "directory": "packages/transforms/cache"
23
23
  },
24
24
  "license": "MIT",
25
- "main": "index.js",
26
- "module": "index.mjs",
27
- "typings": "index.d.ts",
25
+ "main": "cjs/index.js",
26
+ "module": "esm/index.js",
27
+ "typings": "typings/index.d.ts",
28
28
  "typescript": {
29
- "definition": "index.d.ts"
29
+ "definition": "typings/index.d.ts"
30
30
  },
31
+ "type": "module",
31
32
  "exports": {
32
33
  ".": {
33
- "require": "./index.js",
34
- "import": "./index.mjs"
35
- },
36
- "./*": {
37
- "require": "./*.js",
38
- "import": "./*.mjs"
34
+ "require": {
35
+ "types": "./typings/index.d.cts",
36
+ "default": "./cjs/index.js"
37
+ },
38
+ "import": {
39
+ "types": "./typings/index.d.ts",
40
+ "default": "./esm/index.js"
41
+ },
42
+ "default": {
43
+ "types": "./typings/index.d.ts",
44
+ "default": "./esm/index.js"
45
+ }
39
46
  },
40
47
  "./package.json": "./package.json"
41
48
  }
42
- }
49
+ }
@@ -0,0 +1,6 @@
1
+ import { GraphQLResolveInfo } from 'graphql';
2
+ export declare function computeCacheKey(options: {
3
+ keyStr: string | undefined;
4
+ args: Record<string, any>;
5
+ info: GraphQLResolveInfo;
6
+ }): string;
@@ -0,0 +1,13 @@
1
+ import { GraphQLSchema } from 'graphql';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
+ export default class CacheTransform implements MeshTransform {
4
+ private options;
5
+ noWrap: boolean;
6
+ private readonly shouldWaitLocal;
7
+ constructor(options: MeshTransformOptions<YamlConfig.CacheTransformConfig[]>);
8
+ transformSchema(schema: GraphQLSchema): GraphQLSchema;
9
+ private shouldWait;
10
+ private setShouldWait;
11
+ private cleanupShouldWait;
12
+ private waitAndReturn;
13
+ }
@@ -1,5 +1,5 @@
1
- import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
2
1
  import { GraphQLSchema } from 'graphql';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
3
  export default class CacheTransform implements MeshTransform {
4
4
  private options;
5
5
  noWrap: boolean;