@envelop/resource-limitations 3.0.3 → 3.0.5-alpha-20221123174711-ba3d0e3a

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
@@ -37,7 +37,7 @@ const buildMissingPaginationFieldErrorMessage = (params) => `Missing pagination
37
37
  ? "the 'first'"
38
38
  : "the 'last'") +
39
39
  ' field argument.';
40
- const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field ${params.fieldName}. ` +
40
+ const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field '${params.fieldName}'. ` +
41
41
  `The value for the '${params.argumentName}' argument must be an integer within ${params.paginationArgumentMinimum}-${params.paginationArgumentMaximum}.`;
42
42
  exports.defaultNodeCostLimit = 500000;
43
43
  exports.defaultPaginationArgumentMaximum = 100;
@@ -67,14 +67,15 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
67
67
  console.warn('Encountered paginated field without pagination arguments.');
68
68
  }
69
69
  else if (hasFirst === true || hasLast === true) {
70
- if ('first' in argumentValues === false && 'last' in argumentValues === false) {
70
+ if (('first' in argumentValues === false && 'last' in argumentValues === false) ||
71
+ (argumentValues.first === null && argumentValues.last === null)) {
71
72
  context.reportError(new graphql_1.GraphQLError(buildMissingPaginationFieldErrorMessage({
72
73
  fieldName: fieldDef.name,
73
74
  hasFirst,
74
75
  hasLast,
75
76
  }), fieldNode));
76
77
  }
77
- else if ('first' in argumentValues === true && 'last' in argumentValues === false) {
78
+ else if ('first' in argumentValues && !argumentValues.last) {
78
79
  if (argumentValues.first < paginationArgumentMinimum ||
79
80
  argumentValues.first > paginationArgumentMaximum) {
80
81
  context.reportError(new graphql_1.GraphQLError(buildInvalidPaginationRangeErrorMessage({
@@ -89,7 +90,7 @@ const ResourceLimitationValidationRule = (params) => (context, executionArgs) =>
89
90
  nodeCost = argumentValues['first'];
90
91
  }
91
92
  }
92
- else if ('last' in argumentValues === true && 'false' in argumentValues === false) {
93
+ else if (!argumentValues.first && 'last' in argumentValues) {
93
94
  if (argumentValues.last < paginationArgumentMinimum ||
94
95
  argumentValues.last > paginationArgumentMaximum) {
95
96
  context.reportError(new graphql_1.GraphQLError(buildInvalidPaginationRangeErrorMessage({
package/esm/index.js CHANGED
@@ -34,7 +34,7 @@ const buildMissingPaginationFieldErrorMessage = (params) => `Missing pagination
34
34
  ? "the 'first'"
35
35
  : "the 'last'") +
36
36
  ' field argument.';
37
- const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field ${params.fieldName}. ` +
37
+ const buildInvalidPaginationRangeErrorMessage = (params) => `Invalid pagination argument for field '${params.fieldName}'. ` +
38
38
  `The value for the '${params.argumentName}' argument must be an integer within ${params.paginationArgumentMinimum}-${params.paginationArgumentMaximum}.`;
39
39
  export const defaultNodeCostLimit = 500000;
40
40
  export const defaultPaginationArgumentMaximum = 100;
@@ -64,14 +64,15 @@ export const ResourceLimitationValidationRule = (params) => (context, executionA
64
64
  console.warn('Encountered paginated field without pagination arguments.');
65
65
  }
66
66
  else if (hasFirst === true || hasLast === true) {
67
- if ('first' in argumentValues === false && 'last' in argumentValues === false) {
67
+ if (('first' in argumentValues === false && 'last' in argumentValues === false) ||
68
+ (argumentValues.first === null && argumentValues.last === null)) {
68
69
  context.reportError(new GraphQLError(buildMissingPaginationFieldErrorMessage({
69
70
  fieldName: fieldDef.name,
70
71
  hasFirst,
71
72
  hasLast,
72
73
  }), fieldNode));
73
74
  }
74
- else if ('first' in argumentValues === true && 'last' in argumentValues === false) {
75
+ else if ('first' in argumentValues && !argumentValues.last) {
75
76
  if (argumentValues.first < paginationArgumentMinimum ||
76
77
  argumentValues.first > paginationArgumentMaximum) {
77
78
  context.reportError(new GraphQLError(buildInvalidPaginationRangeErrorMessage({
@@ -86,7 +87,7 @@ export const ResourceLimitationValidationRule = (params) => (context, executionA
86
87
  nodeCost = argumentValues['first'];
87
88
  }
88
89
  }
89
- else if ('last' in argumentValues === true && 'false' in argumentValues === false) {
90
+ else if (!argumentValues.first && 'last' in argumentValues) {
90
91
  if (argumentValues.last < paginationArgumentMinimum ||
91
92
  argumentValues.last > paginationArgumentMaximum) {
92
93
  context.reportError(new GraphQLError(buildInvalidPaginationRangeErrorMessage({
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@envelop/resource-limitations",
3
- "version": "3.0.3",
3
+ "version": "3.0.5-alpha-20221123174711-ba3d0e3a",
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": "^3.0.3",
7
+ "@envelop/core": "3.0.4-alpha-20221123174711-ba3d0e3a",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@envelop/extended-validation": "^2.0.3",
11
+ "@envelop/extended-validation": "2.0.4-alpha-20221123174711-ba3d0e3a",
12
12
  "@graphql-tools/utils": "^8.8.0",
13
13
  "tslib": "^2.4.0"
14
14
  },