I am trying to do preprocessing to scope my apollo-server (graphql) resolver results based off the user's authentication (which is expressed in a token in my header). I am not sure of the best way to do this, and this is what I have so far:
// Graphql Options
const GraphqlOptions = {
schema: executableSchema,
debugging: true,
----> pre: [{ method: preMongoose, assign: 'm1'}],
context: {
user: Mongoose.model('User'),
SomethingElse: Mongoose.model('SomethingElse')
}
};
In my preMongoose file
'use strict';
const preMongoose = (request, reply) => {
// code to modify mongoose model's pre to only return results based off
// request's auth token
};
module.exports = preMongoose;