aws-cognito-graphql-directive
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

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"])

}

Package Sidebar

Install

npm i aws-cognito-graphql-directive

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

22 kB

Total Files

13

Last publish

Collaborators

  • anigenero