Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created October 24, 2017 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapkub/83a408f3db25682d20740045f43d153d to your computer and use it in GitHub Desktop.
Save zapkub/83a408f3db25682d20740045f43d153d to your computer and use it in GitHub Desktop.
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