-
Notifications
You must be signed in to change notification settings - Fork 535
Raw GraphQL request on req object #197
Comments
Maybe this issue will be helpful for you graphql/graphql-js#662 Also |
@richardwillars Using one of the arguments ( |
If I was using GET I guess that'd work, though in my case I'm using POST. Don't think there's anything in there for that |
any updates? |
I think you can do this if you add your own body parser. const graphqlHTTP = require('express-graphql');
const bodyParser = require('body-parser');
const {formatError} = require('graphql');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.use('/', graphqlHTTP(function (req) {
return {
schema: Schema,
graphiql: true,
rootValue: {},
context: buildContext(req),
formatError: e => {
const query = req.body.query;
const variables = req.body.variables;
console.log('Error!', query, JSON.stringify(variables, null, 2));
return formatError(e);
}
};
})); |
@richardwillars Since const graphqlHTTP = require('express-graphql');
const {formatError} = require('graphql');
app.use('/', graphqlHTTP(function (req, res, params) {
return {
schema: Schema,
graphiql: true,
rootValue: {},
context: buildContext(req),
formatError: e => {
const query = params.query;
const variables = params.variables;
console.log('Error!', query, JSON.stringify(variables, null, 2));
return formatError(e);
}
};
})); |
Hello
I'd like to output the original GraphQL query (and any variables) to the console whenever an error is thrown in order to make debugging easier. At the moment I can't see any way of doing this as req.body isn't available as express-graphql is doing it's own body parsing, and the raw query doesn't seem to get passed anywhere.
The closest thing I've found so far is fieldNodes which is an object describing the query, but it's still quite difficult to reverse engineer the original query from this.
Could we get the raw query added to the express req object?
Thanks!
The text was updated successfully, but these errors were encountered: