Directive to check authentication against AWS cognito
> npm install
import { AuthDirective, authTypeDefs, getAuthContext } from 'aws-cognito-graphql-drective';
const generateContext: ContextFunction<{event: APIGatewayEvent}, MyGraphQLContext> =
async ({event: {headers}}) => ({
auth: await getAuthContext(headers, {
awsRegion: '',
userPoolId: ''
})
});
export const handler = new ApolloServer({
context: generateContext,
typeDefs: merge(authTypeDefs, myTypeDefs),
// ..
schemaDirectives: {
auth: AuthDirective
}
}).createHandler();
type Query {
authRequiredQuery: MyResult @auth
adminGroupOnlyQuery: MyResult @auth(groups: ["admin"])
}