Skip to content

Commit e63fc96

Browse files
committed
logging
1 parent ca6659d commit e63fc96

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

src/GraphQL/helpers/queryComplexity.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GraphQLError } from 'graphql';
2+
import logger from '../../logger';
23

34
function calculateQueryComplexity(operation, fragments) {
45
let maxDepth = 0;
@@ -72,25 +73,23 @@ function createComplexityValidationPlugin(getConfig) {
7273
);
7374

7475
if (graphQLDepth !== -1 && depth > graphQLDepth) {
75-
throw new GraphQLError(
76-
`GraphQL query depth of ${depth} exceeds maximum allowed depth of ${graphQLDepth}`,
77-
{
78-
extensions: {
79-
http: { status: 400 },
80-
},
81-
}
82-
);
76+
const message = `GraphQL query depth of ${depth} exceeds maximum allowed depth of ${graphQLDepth}`;
77+
logger.warn(message);
78+
throw new GraphQLError(message, {
79+
extensions: {
80+
http: { status: 400 },
81+
},
82+
});
8383
}
8484

8585
if (graphQLFields !== -1 && fields > graphQLFields) {
86-
throw new GraphQLError(
87-
`Number of GraphQL fields (${fields}) exceeds maximum allowed (${graphQLFields})`,
88-
{
89-
extensions: {
90-
http: { status: 400 },
91-
},
92-
}
93-
);
86+
const message = `Number of GraphQL fields (${fields}) exceeds maximum allowed (${graphQLFields})`;
87+
logger.warn(message);
88+
throw new GraphQLError(message, {
89+
extensions: {
90+
http: { status: 400 },
91+
},
92+
});
9493
}
9594
},
9695
}),

src/RestQuery.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
var SchemaController = require('./Controllers/SchemaController');
55
var Parse = require('parse/node').Parse;
6+
var logger = require('./logger').default;
67
const triggers = require('./triggers');
78
const { continueWhile } = require('parse/lib/node/promiseUtils');
89
const AlwaysSelectedKeys = ['objectId', 'createdAt', 'updatedAt', 'ACL'];
@@ -467,10 +468,9 @@ _UnsafeRestQuery.prototype.checkSubqueryDepth = function () {
467468
}
468469
const depth = this.context._subqueryDepth || 0;
469470
if (depth > rc.subqueryDepth) {
470-
throw new Parse.Error(
471-
Parse.Error.INVALID_QUERY,
472-
`Subquery nesting depth exceeds maximum allowed depth of ${rc.subqueryDepth}`
473-
);
471+
const message = `Subquery nesting depth exceeds maximum allowed depth of ${rc.subqueryDepth}`;
472+
logger.warn(message);
473+
throw new Parse.Error(Parse.Error.INVALID_QUERY, message);
474474
}
475475
};
476476

@@ -898,17 +898,15 @@ _UnsafeRestQuery.prototype.validateIncludeComplexity = function () {
898898
if (rc.includeDepth !== -1 && this.include && this.include.length > 0) {
899899
const maxDepth = Math.max(...this.include.map(path => path.length));
900900
if (maxDepth > rc.includeDepth) {
901-
throw new Parse.Error(
902-
Parse.Error.INVALID_QUERY,
903-
`Include depth of ${maxDepth} exceeds maximum allowed depth of ${rc.includeDepth}`
904-
);
901+
const message = `Include depth of ${maxDepth} exceeds maximum allowed depth of ${rc.includeDepth}`;
902+
logger.warn(message);
903+
throw new Parse.Error(Parse.Error.INVALID_QUERY, message);
905904
}
906905
}
907906
if (rc.includeCount !== -1 && this.include && this.include.length > rc.includeCount) {
908-
throw new Parse.Error(
909-
Parse.Error.INVALID_QUERY,
910-
`Number of include fields (${this.include.length}) exceeds maximum allowed (${rc.includeCount})`
911-
);
907+
const message = `Number of include fields (${this.include.length}) exceeds maximum allowed (${rc.includeCount})`;
908+
logger.warn(message);
909+
throw new Parse.Error(Parse.Error.INVALID_QUERY, message);
912910
}
913911
};
914912

0 commit comments

Comments
 (0)