@envelop/resource-limitations 2.6.0 → 2.6.1-alpha-20220901205925-b1fd44a9

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,10 +11,15 @@ yarn add @envelop/resource-limitations
11
11
  ## Usage Example
12
12
 
13
13
  ```ts
14
+ import { parse, validate, execute, subscribe } from 'graphql'
14
15
  import { envelop } from '@envelop/core'
15
16
  import { useResourceLimitations } from '@envelop/resource-limitations'
16
17
 
17
18
  const getEnveloped = envelop({
19
+ parse,
20
+ validate,
21
+ execute,
22
+ subscribe,
18
23
  plugins: [
19
24
  // ... other plugins ...
20
25
  useResourceLimitations({
package/cjs/index.js CHANGED
@@ -125,25 +125,23 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
125
125
  },
126
126
  Document: {
127
127
  leave(documentNode) {
128
- var _a;
129
128
  if (totalNodeCost === 0) {
130
129
  totalNodeCost = 1;
131
130
  }
132
131
  if (totalNodeCost > params.nodeCostLimit) {
133
132
  context.reportError(new graphql_1.GraphQLError(`Cannot request more than ${params.nodeCostLimit} nodes in a single document. Please split your operation into multiple sub operations or reduce the amount of requested nodes.`, documentNode));
134
133
  }
135
- (_a = params.reportNodeCost) === null || _a === void 0 ? void 0 : _a.call(params, totalNodeCost, executionArgs);
134
+ params.reportNodeCost?.(totalNodeCost, executionArgs);
136
135
  },
137
136
  },
138
137
  };
139
138
  };
140
139
  exports.ResourceLimitationValidationRule = ResourceLimitationValidationRule;
141
140
  const useResourceLimitations = (params) => {
142
- var _a, _b, _c, _d;
143
- const paginationArgumentMaximum = (_a = params === null || params === void 0 ? void 0 : params.paginationArgumentMaximum) !== null && _a !== void 0 ? _a : exports.defaultPaginationArgumentMaximum;
144
- const paginationArgumentMinimum = (_b = params === null || params === void 0 ? void 0 : params.paginationArgumentMinimum) !== null && _b !== void 0 ? _b : exports.defaultPaginationArgumentMinimum;
145
- const nodeCostLimit = (_c = params === null || params === void 0 ? void 0 : params.nodeCostLimit) !== null && _c !== void 0 ? _c : exports.defaultNodeCostLimit;
146
- const extensions = (_d = params === null || params === void 0 ? void 0 : params.extensions) !== null && _d !== void 0 ? _d : false;
141
+ const paginationArgumentMaximum = params?.paginationArgumentMaximum ?? exports.defaultPaginationArgumentMaximum;
142
+ const paginationArgumentMinimum = params?.paginationArgumentMinimum ?? exports.defaultPaginationArgumentMinimum;
143
+ const nodeCostLimit = params?.nodeCostLimit ?? exports.defaultNodeCostLimit;
144
+ const extensions = params?.extensions ?? false;
147
145
  const nodeCostMap = new WeakMap();
148
146
  const handleResult = ({ result, args }) => {
149
147
  const nodeCost = nodeCostMap.get(args);
@@ -164,7 +162,7 @@ const useResourceLimitations = (params) => {
164
162
  nodeCostLimit,
165
163
  paginationArgumentMaximum,
166
164
  paginationArgumentMinimum,
167
- paginationArgumentTypes: params === null || params === void 0 ? void 0 : params.paginationArgumentScalars,
165
+ paginationArgumentTypes: params?.paginationArgumentScalars,
168
166
  reportNodeCost: extensions
169
167
  ? (nodeCost, ref) => {
170
168
  nodeCostMap.set(ref, nodeCost);
package/esm/index.js CHANGED
@@ -122,24 +122,22 @@ export const ResourceLimitationValidationRule = (params) => (context, executionA
122
122
  },
123
123
  Document: {
124
124
  leave(documentNode) {
125
- var _a;
126
125
  if (totalNodeCost === 0) {
127
126
  totalNodeCost = 1;
128
127
  }
129
128
  if (totalNodeCost > params.nodeCostLimit) {
130
129
  context.reportError(new GraphQLError(`Cannot request more than ${params.nodeCostLimit} nodes in a single document. Please split your operation into multiple sub operations or reduce the amount of requested nodes.`, documentNode));
131
130
  }
132
- (_a = params.reportNodeCost) === null || _a === void 0 ? void 0 : _a.call(params, totalNodeCost, executionArgs);
131
+ params.reportNodeCost?.(totalNodeCost, executionArgs);
133
132
  },
134
133
  },
135
134
  };
136
135
  };
137
136
  export const useResourceLimitations = (params) => {
138
- var _a, _b, _c, _d;
139
- const paginationArgumentMaximum = (_a = params === null || params === void 0 ? void 0 : params.paginationArgumentMaximum) !== null && _a !== void 0 ? _a : defaultPaginationArgumentMaximum;
140
- const paginationArgumentMinimum = (_b = params === null || params === void 0 ? void 0 : params.paginationArgumentMinimum) !== null && _b !== void 0 ? _b : defaultPaginationArgumentMinimum;
141
- const nodeCostLimit = (_c = params === null || params === void 0 ? void 0 : params.nodeCostLimit) !== null && _c !== void 0 ? _c : defaultNodeCostLimit;
142
- const extensions = (_d = params === null || params === void 0 ? void 0 : params.extensions) !== null && _d !== void 0 ? _d : false;
137
+ const paginationArgumentMaximum = params?.paginationArgumentMaximum ?? defaultPaginationArgumentMaximum;
138
+ const paginationArgumentMinimum = params?.paginationArgumentMinimum ?? defaultPaginationArgumentMinimum;
139
+ const nodeCostLimit = params?.nodeCostLimit ?? defaultNodeCostLimit;
140
+ const extensions = params?.extensions ?? false;
143
141
  const nodeCostMap = new WeakMap();
144
142
  const handleResult = ({ result, args }) => {
145
143
  const nodeCost = nodeCostMap.get(args);
@@ -160,7 +158,7 @@ export const useResourceLimitations = (params) => {
160
158
  nodeCostLimit,
161
159
  paginationArgumentMaximum,
162
160
  paginationArgumentMinimum,
163
- paginationArgumentTypes: params === null || params === void 0 ? void 0 : params.paginationArgumentScalars,
161
+ paginationArgumentTypes: params?.paginationArgumentScalars,
164
162
  reportNodeCost: extensions
165
163
  ? (nodeCost, ref) => {
166
164
  nodeCostMap.set(ref, nodeCost);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@envelop/resource-limitations",
3
- "version": "2.6.0",
3
+ "version": "2.6.1-alpha-20220901205925-b1fd44a9",
4
4
  "description": "A rate-limit implementation based on resource limitations and static calculation of the score (similar to GitHub GraphQL API)",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "@envelop/core": "^2.6.0",
7
+ "@envelop/core": "2.6.1-alpha-20220901205925-b1fd44a9",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@envelop/extended-validation": "^1.9.0",
11
+ "@envelop/extended-validation": "1.9.1-alpha-20220901205925-b1fd44a9",
12
12
  "@graphql-tools/utils": "^8.8.0",
13
13
  "tslib": "^2.4.0"
14
14
  },