Error handling and logging
GraphQL servers can be tricky to debug. The following functions can help find error faster in many cases.
ForbidUndefinedInResolve can be used during debugging to find mistakes in resolve functions faster. Usually, resolve functions only return undefined due to programmer error.
forbidUndefinedInResolve takes a GraphQLSchema as input, and modifies it in place to throw an error when a resolve function returns undefined, telling you exactly which resolver returned undefined.
This function may be deprecated in the near future. Instead of using addErrorLoggingToSchema, the
formatError option of
graphqlHTTP should be used, which was recently added in graphql-js v0.5.0
addErrorLoggingToSchema takes two arguments:
schema must be an instance of
logger must be an Object with a callable property
log. Every time an error occurs,
logger.log(e) will be called.