Typically, GraphQL does not directly handle access control, but delegates this responsibility to any data system with which it interacts. In your case, it sounds like Mongoose.
Since the access control logic is often arbitrary logic (for example, this user was blocked from some content? The publisher of this content limited it to privacy settings?) And it sounds, as in your case, this access control logic is actually normal, it should live in the "permission" function, which returns a value for the GraphQL field.
For example:
var UserType = new GraphQLObjectType({ name: 'User', fields: { name: { type: GraphQLString }, birthday: { type: GraphQLString, resolve(user, context) { var auth = context.myLoggedInAuth; if (myCanAuthSeeBirthday(auth, user)) { return user.birthday; } } } } });
Lee byron
source share