Directive to check authentication against AWS cognito
> npm install
import { AuthDirective, authTypeDefs, getAuthContext } from 'aws-cognito-graphql-drective';
import { merge } from 'lodash';
export const handler = new ApolloServer({
context: async ({headers}) => ({
auth: await getAuthContext(headers, configuration)
}),
typeDefs: merge(authTypeDefs, myTypeDefs),
// ..
schemaDirectives: {
auth: AuthDirective
}
}).createHandler();
type Query {
anonymousQuery: MyResult
authRequiredQuery: MyResult @auth
adminGroupOnlyQuery: MyResult @auth(groups: ["admin"])
}
This library includes utilities for easy, quick setup in common environments.
import {generateLambdaContextFromAPIGateway} from 'aws-cognito-graphql-directive';
new ApolloServer({
context: generateLambdaContextFromAPIGateway(configuration, {
// ... other context
})
})