Prerequisites
To integrate with AWS Cognito, you will need the following environment variables in the root of your project.
COGNITO_USER_POOL_ID=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
Create the Cognito User Entity
Use the createAwsCognitoUserResolver
to create a CognitoUser resolver using the environment variables described above.
in backend/cognito/index.ts
export const cognitoUser = createAwsCognitoUserResolver({
userPoolId: process.env.COGNITO_USER_POOL_ID,
region: process.env.AWS_DEFAULT_REGION,
});
createAwsCognitoUserResolver
returns an object that contains a resolver, an entity, and a provider for AWS Cognito.
The resolver must be added to your Graphweaver resolvers:
backend/schema/index.ts
import { cognitoUser } from '../cognito';
export const resolvers = [cognitoUser.resolver];
backend/index.ts
import { resolvers } from './schema';
const graphweaver = new Graphweaver<AuthorizationContext>({
resolvers,
});
export const handler = graphweaver.handler();