Last active
September 2, 2020 13:40
-
-
Save Friss/90604b5f53ad4bb38146a8f49c730c13 to your computer and use it in GitHub Desktop.
Apollo error test
This file contains 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
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var apolloServerExpress = require('apollo-server-express'); | |
var {graphqlExpress, graphiqlExpress} = apolloServerExpress; | |
var makeExecutableSchema = require('graphql-tools').makeExecutableSchema; | |
var typeDefs = ` | |
type Query { | |
testString: String | |
} | |
`; | |
var resolvers = { | |
Query: { | |
testString(_, args) { | |
return 'Error test'; | |
}, | |
}, | |
}; | |
var app = express(); | |
app.use( | |
'/graphql', | |
bodyParser.json(), | |
graphqlExpress({ | |
schema: makeExecutableSchema({typeDefs, resolvers}), | |
}) | |
); | |
app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'})); | |
// catch 404 and forward to error handler | |
app.use(function(req, res, next) { | |
console.log('In 404'); | |
var err = new Error('Not Found'); | |
err.status = 404; | |
next(err); | |
}); | |
// error handler | |
app.use(function(err, req, res, next) { | |
console.log('In error handler'); | |
// set locals, only providing error in development | |
res.locals.message = err.message; | |
res.locals.error = req.app.get('env') === 'development' ? err : {}; | |
// render the error page | |
res.status(err.status || 500); | |
res.json({err}); | |
}); | |
app.listen(8888, () => | |
console.log(`GraphiQL is now running on http://localhost:${8888}/graphiql`) | |
); |
This file contains 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
zfriss@BOSMM2TX2V7HTD8 graphql-test $ node error-test.js | |
GraphiQL is now running on http://localhost:8888/graphiql | |
In 404 | |
In error handler | |
Error: Can't set headers after they are sent. | |
at validateHeader (_http_outgoing.js:504:11) | |
at ServerResponse.setHeader (_http_outgoing.js:511:3) | |
at ServerResponse.header (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/response.js:730:10) | |
at ServerResponse.send (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/response.js:170:12) | |
at ServerResponse.json (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/response.js:256:15) | |
at /Users/zfriss/Desktop/Dev/ion/ionstats-server/error-test.js:50:7 | |
at Layer.handle_error (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/router/layer.js:71:5) | |
at trim_prefix (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/router/index.js:315:13) | |
at /Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/router/index.js:284:7 | |
at Function.process_params (/Users/zfriss/Desktop/Dev/ion/ionstats-server/node_modules/express/lib/router/index.js:335:12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#4527 same error with express-session and nest/graphql