Last active
January 13, 2019 14:21
-
-
Save philsch/adce29d2f7f59f6bcbba432c4a34a12f to your computer and use it in GitHub Desktop.
Blogpost: Monitor your GraphQL Apollo Server in Google Cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
introspection: true, | |
playground: true, | |
formatError: (error) => { | |
/* | |
* Database connection error should appear in logs | |
* but not in Error Report as this is not considered a bug | |
*/ | |
if (error.originalError instanceof DatabaseError) { | |
console.error('Database error occurred', error); | |
return error; | |
} | |
/* | |
* Some other Apollo error like wrong user input | |
* we don't need to log or report this, | |
* but still return the error back to the client | |
*/ | |
if (error.originalError instanceof ApolloError) { | |
return error; | |
} | |
/* | |
* Something unexpected is wrong | |
*/ | |
errorReporting.report(error.originalError.stack); // report to Google Error Report | |
console.error(error); // log the error | |
return {message: 'Internal Server Error'} // do not reveal error details to the client | |
} | |
}); | |
const app = express(); | |
server.applyMiddleware({app, path: '/graphql'}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment