apollo-server-core
Advanced tools
Comparing version 1.3.5 to 1.4.0-alpha.0
export { runQuery, LogFunction, LogMessage, LogStep, LogAction } from './runQuery'; | ||
export { runHttpQuery, HttpQueryRequest, HttpQueryError } from './runHttpQuery'; | ||
export { default as GraphQLOptions, resolveGraphqlOptions } from './graphqlOptions'; | ||
export { ApolloError, toApolloError, ParseError, ValidationError, AuthenticationError, formatError } from './errors'; |
@@ -12,2 +12,9 @@ "use strict"; | ||
exports.resolveGraphqlOptions = graphqlOptions_1.resolveGraphqlOptions; | ||
var errors_1 = require("./errors"); | ||
exports.ApolloError = errors_1.ApolloError; | ||
exports.toApolloError = errors_1.toApolloError; | ||
exports.ParseError = errors_1.ParseError; | ||
exports.ValidationError = errors_1.ValidationError; | ||
exports.AuthenticationError = errors_1.AuthenticationError; | ||
exports.formatError = errors_1.formatError; | ||
//# sourceMappingURL=index.js.map |
@@ -51,2 +51,3 @@ "use strict"; | ||
var graphqlOptions_1 = require("./graphqlOptions"); | ||
var errors_1 = require("./errors"); | ||
var HttpQueryError = (function (_super) { | ||
@@ -72,3 +73,3 @@ __extends(HttpQueryError, _super); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var isGetRequest, optionsObject, e_1, formatErrorFn, requestPayload, isBatch, requests, responses, gqlResponse; | ||
var isGetRequest, optionsObject, e_1, formatErrorFn, debugDefault, debug, requestPayload, isBatch, requests, responses, gqlResponse; | ||
return __generator(this, function (_a) { | ||
@@ -89,3 +90,7 @@ switch (_a.label) { | ||
case 4: | ||
formatErrorFn = optionsObject.formatError || graphql_1.formatError; | ||
formatErrorFn = function (error) { | ||
return optionsObject.formatError(errors_1.formatError(error)) || errors_1.formatError; | ||
}; | ||
debugDefault = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test'; | ||
debug = optionsObject.debug !== undefined ? optionsObject.debug : debugDefault; | ||
switch (request.method) { | ||
@@ -157,3 +162,3 @@ case 'POST': | ||
validationRules: optionsObject.validationRules, | ||
formatError: formatErrorFn, | ||
formatError: optionsObject.formatError, | ||
formatResponse: optionsObject.formatResponse, | ||
@@ -160,0 +165,0 @@ fieldResolver: optionsObject.fieldResolver, |
@@ -7,2 +7,3 @@ "use strict"; | ||
var apollo_cache_control_1 = require("apollo-cache-control"); | ||
var errors_1 = require("./errors"); | ||
var LogAction; | ||
@@ -28,4 +29,5 @@ (function (LogAction) { | ||
} | ||
function format(errors, formatter) { | ||
return errors.map(function (error) { | ||
function format(errors, options) { | ||
var formatter = options.formatter, debug = options.debug; | ||
return errors.map(function (error) { return errors_1.formatError(error, debug); }).map(function (error) { | ||
if (formatter !== undefined) { | ||
@@ -37,8 +39,8 @@ try { | ||
console.error('Error in formatError function:', err); | ||
var newError = new Error('Internal server error'); | ||
return graphql_1.formatError(newError); | ||
var newError = errors_1.fromGraphQLError(new graphql_1.GraphQLError('Internal server error'), 'INTERNAL_ERROR'); | ||
return errors_1.formatError(newError, debug); | ||
} | ||
} | ||
else { | ||
return graphql_1.formatError(error); | ||
return error; | ||
} | ||
@@ -101,3 +103,6 @@ }); | ||
return Promise.resolve({ | ||
errors: format([syntaxError], options.formatError), | ||
errors: format([errors_1.fromGraphQLError(syntaxError, 'MALFORMED_QUERY')], { | ||
formatter: options.formatError, | ||
debug: debug, | ||
}), | ||
}); | ||
@@ -118,3 +123,8 @@ } | ||
return Promise.resolve({ | ||
errors: format(validationErrors, options.formatError), | ||
errors: format(validationErrors.map(function (err) { | ||
return errors_1.fromGraphQLError(err, 'QUERY_VALIDATION_FAILED'); | ||
}), { | ||
formatter: options.formatError, | ||
debug: debug, | ||
}), | ||
}); | ||
@@ -134,3 +144,6 @@ } | ||
if (result.errors) { | ||
response.errors = format(result.errors, options.formatError); | ||
response.errors = format(result.errors, { | ||
formatter: options.formatError, | ||
debug: debug, | ||
}); | ||
if (debug) { | ||
@@ -155,3 +168,6 @@ result.errors.map(printStackTrace); | ||
return Promise.resolve({ | ||
errors: format([executionError], options.formatError), | ||
errors: format([errors_1.fromGraphQLError(executionError, 'EXECUTION_ERROR')], { | ||
formatter: options.formatError, | ||
debug: debug, | ||
}), | ||
}); | ||
@@ -158,0 +174,0 @@ } |
{ | ||
"name": "apollo-server-core", | ||
"version": "1.3.5", | ||
"version": "1.4.0-alpha.0", | ||
"description": "Core engine for Apollo GraphQL server", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,1 +13,9 @@ export { | ||
} from './graphqlOptions'; | ||
export { | ||
ApolloError, | ||
toApolloError, | ||
ParseError, | ||
ValidationError, | ||
AuthenticationError, | ||
formatError, | ||
} from './errors'; |
@@ -1,8 +0,2 @@ | ||
import { | ||
parse, | ||
getOperationAST, | ||
DocumentNode, | ||
formatError, | ||
ExecutionResult, | ||
} from 'graphql'; | ||
import { parse, getOperationAST, DocumentNode, ExecutionResult } from 'graphql'; | ||
import { runQuery } from './runQuery'; | ||
@@ -13,2 +7,3 @@ import { | ||
} from './graphqlOptions'; | ||
import { formatError } from './errors'; | ||
@@ -60,3 +55,8 @@ export interface HttpQueryRequest { | ||
} | ||
const formatErrorFn = optionsObject.formatError || formatError; | ||
const formatErrorFn = error => | ||
optionsObject.formatError(formatError(error)) || formatError; | ||
const debugDefault = | ||
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test'; | ||
const debug = | ||
optionsObject.debug !== undefined ? optionsObject.debug : debugDefault; | ||
let requestPayload; | ||
@@ -156,3 +156,3 @@ | ||
validationRules: optionsObject.validationRules, | ||
formatError: formatErrorFn, | ||
formatError: optionsObject.formatError, | ||
formatResponse: optionsObject.formatResponse, | ||
@@ -184,2 +184,4 @@ fieldResolver: optionsObject.fieldResolver, | ||
const gqlResponse = responses[0]; | ||
//This code is run on parse/validation errors and any other error that | ||
//doesn't reach GraphQL execution | ||
if (gqlResponse.errors && typeof gqlResponse.data === 'undefined') { | ||
@@ -186,0 +188,0 @@ throw new HttpQueryError(400, JSON.stringify(gqlResponse), true, { |
@@ -11,3 +11,2 @@ import { | ||
GraphQLError, | ||
formatError, | ||
specifiedRules, | ||
@@ -28,2 +27,4 @@ ValidationContext, | ||
import { fromGraphQLError, formatError } from './errors'; | ||
export interface GraphQLResponse { | ||
@@ -88,4 +89,11 @@ data?: object; | ||
function format(errors: Array<Error>, formatter?: Function): Array<Error> { | ||
return errors.map(error => { | ||
function format( | ||
errors: Array<Error>, | ||
options?: { | ||
formatter?: Function; | ||
debug?: boolean; | ||
}, | ||
): Array<Error> { | ||
const { formatter, debug } = options; | ||
return errors.map(error => formatError(error, debug)).map(error => { | ||
if (formatter !== undefined) { | ||
@@ -96,7 +104,10 @@ try { | ||
console.error('Error in formatError function:', err); | ||
const newError = new Error('Internal server error'); | ||
return formatError(newError); | ||
const newError: GraphQLError = fromGraphQLError( | ||
new GraphQLError('Internal server error'), | ||
'INTERNAL_ERROR', | ||
); | ||
return formatError(newError, debug); | ||
} | ||
} else { | ||
return formatError(error); | ||
return error; | ||
} | ||
@@ -171,3 +182,6 @@ }) as Array<Error>; | ||
return Promise.resolve({ | ||
errors: format([syntaxError], options.formatError), | ||
errors: format([fromGraphQLError(syntaxError, 'MALFORMED_QUERY')], { | ||
formatter: options.formatError, | ||
debug, | ||
}), | ||
}); | ||
@@ -186,5 +200,14 @@ } | ||
logFunction({ action: LogAction.validation, step: LogStep.end }); | ||
if (validationErrors.length) { | ||
return Promise.resolve({ | ||
errors: format(validationErrors, options.formatError), | ||
errors: format( | ||
validationErrors.map(err => | ||
fromGraphQLError(err, 'QUERY_VALIDATION_FAILED'), | ||
), | ||
{ | ||
formatter: options.formatError, | ||
debug, | ||
}, | ||
), | ||
}); | ||
@@ -218,3 +241,6 @@ } | ||
if (result.errors) { | ||
response.errors = format(result.errors, options.formatError); | ||
response.errors = format(result.errors, { | ||
formatter: options.formatError, | ||
debug, | ||
}); | ||
if (debug) { | ||
@@ -241,5 +267,8 @@ result.errors.map(printStackTrace); | ||
return Promise.resolve({ | ||
errors: format([executionError], options.formatError), | ||
errors: format([fromGraphQLError(executionError, 'EXECUTION_ERROR')], { | ||
formatter: options.formatError, | ||
debug, | ||
}), | ||
}); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78025
27
1714
1
4
1