Skip to content

Commit

Permalink
feat: Log errors when thrown in context initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
schickling committed Dec 30, 2017
1 parent 91cf014 commit c16f70b
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,24 @@ export class GraphQLServer {

app.post(
endpoint,
graphqlExpress(async request => ({
schema: this.executableSchema,
tracing: tracing(request),
context:
typeof this.context === 'function'
? await this.context({ request })
: this.context,
})),
graphqlExpress(async request => {
let context
try {
context =
typeof this.context === 'function'
? await this.context({ request })
: this.context
} catch (e) {
console.error(e)
throw e
}

return {
schema: this.executableSchema,
tracing: tracing(request),
context,
}
}),
)

if (!disablePlayground) {
Expand Down Expand Up @@ -157,13 +167,17 @@ export class GraphQLServer {
execute,
subscribe,
onOperation: async (message, connection, webSocket) => {
return {
...connection,
context:
let context
try {
context =
typeof this.context === 'function'
? await this.context({ connection })
: this.context,
: this.context
} catch (e) {
console.error(e)
throw e
}
return { ...connection, context }
},
},
{
Expand Down

0 comments on commit c16f70b

Please sign in to comment.