apollo-server-core: capture context creation failure in GraphQL error

This commit is contained in:
Evans Hauser 2018-05-02 23:47:15 -07:00
parent 5aeb36f3d7
commit 0fe53a68da
No known key found for this signature in database
GPG key ID: 88AF586817F52EEC

View file

@ -195,7 +195,25 @@ export async function runHttpQuery(
//appease typescript compiler, otherwise could use || {}
context = {};
} else if (typeof context === 'function') {
context = await context();
try {
context = await context();
} catch (e) {
e.message = `Context creation failed: ${e.message}`;
throw new HttpQueryError(
500,
JSON.stringify({
errors: formatApolloErrors([e], {
formatter: optionsObject.formatError,
debug,
logFunction: optionsObject.logFunction,
}),
}),
true,
{
'Content-Type': 'application/json',
},
);
}
} else if (isBatch) {
context = Object.assign(
Object.create(Object.getPrototypeOf(context)),