@graphql-mesh/transform-rate-limit 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf

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.
@@ -1,10 +1,9 @@
1
- 'use strict';
2
-
3
- const utils = require('@graphql-tools/utils');
4
- const graphql = require('graphql');
5
- const stringInterpolation = require('@graphql-mesh/string-interpolation');
6
- const crossHelpers = require('@graphql-mesh/cross-helpers');
7
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
5
+ const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
6
+ const utils_1 = require("@graphql-tools/utils");
8
7
  class RateLimitTransform {
9
8
  constructor(options) {
10
9
  this.pathRateLimitDef = new Map();
@@ -28,22 +27,22 @@ class RateLimitTransform {
28
27
  if (transformedSchema) {
29
28
  const errors = [];
30
29
  const resolverData = {
31
- env: crossHelpers.process.env,
30
+ env: cross_helpers_1.process.env,
32
31
  root: rootValue,
33
32
  args,
34
33
  context,
35
34
  info,
36
35
  };
37
- const typeInfo = new graphql.TypeInfo(transformedSchema);
36
+ const typeInfo = new graphql_1.TypeInfo(transformedSchema);
38
37
  let remainingFields = 0;
39
- const newDocument = graphql.visit(executionRequest.document, graphql.visitWithTypeInfo(typeInfo, {
38
+ const newDocument = (0, graphql_1.visit)(executionRequest.document, (0, graphql_1.visitWithTypeInfo)(typeInfo, {
40
39
  Field: () => {
41
40
  const parentType = typeInfo.getParentType();
42
41
  const fieldDef = typeInfo.getFieldDef();
43
42
  const path = `${parentType.name}.${fieldDef.name}`;
44
43
  const rateLimitConfig = this.pathRateLimitDef.get(path);
45
44
  if (rateLimitConfig) {
46
- const identifier = stringInterpolation.stringInterpolator.parse(rateLimitConfig.identifier, resolverData);
45
+ const identifier = string_interpolation_1.stringInterpolator.parse(rateLimitConfig.identifier, resolverData);
47
46
  const mapKey = `${identifier}-${path}`;
48
47
  let remainingTokens = this.tokenMap.get(mapKey);
49
48
  if (remainingTokens == null) {
@@ -55,7 +54,7 @@ class RateLimitTransform {
55
54
  this.timeouts.add(timeout);
56
55
  }
57
56
  if (remainingTokens === 0) {
58
- errors.push(new graphql.GraphQLError(`Rate limit of "${path}" exceeded for "${identifier}"`));
57
+ errors.push(new graphql_1.GraphQLError(`Rate limit of "${path}" exceeded for "${identifier}"`));
59
58
  // Remove this field from the selection set
60
59
  return null;
61
60
  }
@@ -72,7 +71,7 @@ class RateLimitTransform {
72
71
  throw errors[0];
73
72
  }
74
73
  else if (errors.length > 0) {
75
- throw new utils.AggregateError(errors);
74
+ throw new utils_1.AggregateError(errors);
76
75
  }
77
76
  }
78
77
  this.errors.set(delegationContext, errors);
@@ -94,5 +93,4 @@ class RateLimitTransform {
94
93
  return result;
95
94
  }
96
95
  }
97
-
98
- module.exports = RateLimitTransform;
96
+ exports.default = RateLimitTransform;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,9 +1,8 @@
1
- import { AggregateError } from '@graphql-tools/utils';
2
- import { TypeInfo, visit, visitWithTypeInfo, GraphQLError } from 'graphql';
3
- import { stringInterpolator } from '@graphql-mesh/string-interpolation';
1
+ import { GraphQLError, TypeInfo, visit, visitWithTypeInfo } from 'graphql';
4
2
  import { process } from '@graphql-mesh/cross-helpers';
5
-
6
- class RateLimitTransform {
3
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
4
+ import { AggregateError } from '@graphql-tools/utils';
5
+ export default class RateLimitTransform {
7
6
  constructor(options) {
8
7
  this.pathRateLimitDef = new Map();
9
8
  this.tokenMap = new Map();
@@ -92,5 +91,3 @@ class RateLimitTransform {
92
91
  return result;
93
92
  }
94
93
  }
95
-
96
- export default RateLimitTransform;
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-mesh/transform-rate-limit",
3
- "version": "1.0.0-alpha-20220804093904-8e2e41f7f",
3
+ "version": "1.0.0-alpha-20230420220344-25b6b92bf",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "0.79.0-alpha-20220804093904-8e2e41f7f",
7
- "@graphql-mesh/utils": "1.0.0-alpha-20220804093904-8e2e41f7f",
8
- "graphql": "*"
6
+ "@graphql-mesh/cross-helpers": "^0.3.4",
7
+ "@graphql-mesh/types": "1.0.0-alpha-20230420220344-25b6b92bf",
8
+ "@graphql-mesh/utils": "1.0.0-alpha-20230420220344-25b6b92bf",
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/utils": "8.9.0",
14
- "tslib": "^2.4.0"
14
+ "@graphql-mesh/string-interpolation": "0.4.4"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -19,21 +19,28 @@
19
19
  "directory": "packages/transforms/rate-limit"
20
20
  },
21
21
  "license": "MIT",
22
- "main": "index.js",
23
- "module": "index.mjs",
24
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
25
25
  "typescript": {
26
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
27
27
  },
28
+ "type": "module",
28
29
  "exports": {
29
30
  ".": {
30
- "require": "./index.js",
31
- "import": "./index.mjs"
32
- },
33
- "./*": {
34
- "require": "./*.js",
35
- "import": "./*.mjs"
31
+ "require": {
32
+ "types": "./typings/index.d.cts",
33
+ "default": "./cjs/index.js"
34
+ },
35
+ "import": {
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"
42
+ }
36
43
  },
37
44
  "./package.json": "./package.json"
38
45
  }
39
- }
46
+ }
@@ -0,0 +1,13 @@
1
+ import { ExecutionResult } from 'graphql';
2
+ import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
3
+ import type { DelegationContext } from '@graphql-tools/delegate';
4
+ import { ExecutionRequest } from '@graphql-tools/utils';
5
+ export default class RateLimitTransform implements MeshTransform {
6
+ private pathRateLimitDef;
7
+ private tokenMap;
8
+ private timeouts;
9
+ constructor(options: MeshTransformOptions<YamlConfig.RateLimitTransformConfig[]>);
10
+ private errors;
11
+ transformRequest(executionRequest: ExecutionRequest, delegationContext: DelegationContext): ExecutionRequest;
12
+ transformResult(result: ExecutionResult, delegationContext: DelegationContext): ExecutionResult<import("graphql/jsutils/ObjMap").ObjMap<unknown>, import("graphql/jsutils/ObjMap").ObjMap<unknown>>;
13
+ }
@@ -1,7 +1,7 @@
1
+ import { ExecutionResult } from 'graphql';
1
2
  import { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types';
2
- import { ExecutionRequest } from '@graphql-tools/utils';
3
3
  import type { DelegationContext } from '@graphql-tools/delegate';
4
- import { ExecutionResult } from 'graphql';
4
+ import { ExecutionRequest } from '@graphql-tools/utils';
5
5
  export default class RateLimitTransform implements MeshTransform {
6
6
  private pathRateLimitDef;
7
7
  private tokenMap;