Comments (2)
Part of the philosophy of this package is to do things the Koa way, allowing people to use normal middleware and app error handlers to do the things they need.
here is how I log errors in one of my GraphQL APIs:
const app = new Koa()
// … Setup middleware, etc.
app.on('error', error => {
if (error.graphqlErrors) {
const unexposed = error.graphqlErrors.filter(
({ originalError }) =>
// Originally thrown in resolvers (not a GraphQL validation error).
originalError &&
// Not specifically marked to be exposed to the client.
!originalError.expose
)
if (unexposed.length) {
console.group('Unexposed GraphQL errors:')
unexposed.forEach(error => {
console.log('\x1b[31m')
console.log(error.toString())
console.log('\x1b[2m', error.stack)
console.log('\x1b[0m')
})
console.groupEnd()
}
} else console.error(error)
})
Don't worry about the \x
looking codes, they are to colorize the console output.
If some errors are not exposed to the client, this error handler logs them on the server. The idea is that if any errors are exposed to the client, it is not a server error and as such should not be logged as an error on the server. Instead you should see the errors in your browser console, or however your GraphQL client reports errors.
from graphql-api-koa.
Thanks for the response, but that solution did not work
Since it's an exception thrown in the execute
function, it doesn't fire and events or passes through any middleware, so I've managed to see the graphql errors by wrapping the route definition in a try catch block
try {
router.post('/graphql', errorHandler(), execute({ schema }));
} catch (error) {
console.error(error);
throw error;
}
from graphql-api-koa.
Related Issues (12)
- babel eslint parser missing? HOT 1
- Add possibility to reformat error in errorHandler HOT 13
- Resolver error status code is not respected HOT 2
- Subscriptions support HOT 2
- Use in Typescript HOT 1
- graphql peer dependency 0.13.1 ? HOT 2
- The presence of errors should not discard data HOT 1
- Add format error functionality HOT 1
- [email protected] HOT 1
- Add information to docs on how to add additional fields in error HOT 2
- Support graphql v15 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-api-koa.