Created
February 8, 2019 07:14
-
-
Save zackify/12d5ef354b04aac440bbf744dc7d43b7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { mapValues } from 'lodash'; | |
const authCheck = (resolver, isPublic) => (parent, args, context, info) => { | |
if (isPublic || context.user) { | |
return resolver(parent, args, context, info); | |
} | |
return ApolloError({ code: 401 }); | |
}; | |
export default (resolvers, publicResolvers = []) => | |
mapValues(resolvers, resolver => | |
mapValues(resolver, item => { | |
return authCheck(item, publicResolvers.includes(item.name)); | |
}), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment