1.0.6 • Published 4 years ago

aws-cognito-graphql-directive v1.0.6

Weekly downloads
73
License
MIT
Repository
github
Last release
4 years ago

aws-cognito-graphql-directive

Build Status codecov

Directive to check authentication against AWS cognito

Installation

> npm install

Setup

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();

Requiring authentication

type Query {

    authRequiredQuery: MyResult @auth
    adminGroupOnlyQuery: MyResult @auth(groups: ["admin"])

}