Created
October 24, 2017 08:13
-
-
Save zapkub/83a408f3db25682d20740045f43d153d 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
const rawSchema = { | |
typeDefs: ` | |
type Query { | |
gqlTools: String | |
} | |
`, | |
resolvers: { | |
Query: { | |
gqlTools: () => 'Hi from gqlTools' | |
} | |
} | |
} | |
const protectResolver = ['gqlTools'] | |
function shouldWrapWithAuth(resolverName) { | |
// check if protectResolver include resolverName | |
} | |
Object.keys(rawSchema.resolvers.Query).forEach(resolverKey => { | |
// loop query resolver to wrap with | |
// authentication | |
if(shouldWrapWithAuth(resolverKey)) { | |
return (source,args,context) => { | |
if(!context.user) return null | |
return await rawSchema.resolvers.Query[resolverKey](source, args, context) | |
} | |
} else { | |
// return original resolver if not want to protect | |
return rawSchema.resolvers.Query[resolverKey] | |
} | |
}) | |
const extraSchema = makeExecutableSchema() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment