I am running Apollo lambda server for GraphQL. I want to intercept the GraphQL query/mutation from the POST request body and parse it so I can find out which query/mutation the
You could use graphql-js
like so:
const { parse, visit } = require('graphql');
const query = `
{
books {
...rest of the query
}
}
`
const ast = parse(query);
const newAst = visit(ast, {
enter(node, key, parent, path, ancestors) {
// do some work
},
leave(node, key, parent, path, ancestors) {
// do some more work
}
});
I belive this is what graphql server implementations uses under the hood, I could be mistaken though.