Amplify GraphQL Auth Transformer

7.2.82 · active · verified Wed Apr 22

The `graphql-auth-transformer` is a core, internal component of the AWS Amplify CLI's API category, specifically designed to process the `@auth` directive within GraphQL schemas. It allows developers to declare comprehensive authorization rules directly in their GraphQL Schema Definition Language (SDL), which the Amplify CLI then translates into corresponding AWS AppSync resolvers, AWS Identity and Access Management (IAM) policies, and Amazon Cognito User Pool configurations. This package is part of the larger `@aws-amplify/amplify-category-api` umbrella, which receives frequent updates, with the current package version being 7.2.82. Its primary differentiator is simplifying the definition and deployment of granular access control for GraphQL APIs powered by AWS AppSync, abstracting away much of the underlying complex AWS security primitives into declarative schema directives. It significantly reduces the boilerplate traditionally associated with securing GraphQL endpoints on AWS, making robust authorization accessible to a wider range of developers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a GraphQL model with owner-based, group-based, and public authorization rules using the `@auth` directive, and then deploy it with the Amplify CLI.

/* amplify/backend/api/myapi/schema.graphql */

type Todo @model @auth(rules: [
  { allow: owner },
  { allow: groups, groups: ["Admins"], operations: [create, read, update, delete] },
  { allow: public, operations: [read] }
]) {
  id: ID!
  name: String!
  description: String
  owner: String
}

// To apply this schema and provision backend resources:
// 1. Save this file as amplify/backend/api/<your-api-name>/schema.graphql
// 2. Ensure Amplify CLI is initialized in your project:
//    amplify init
// 3. Add the API category:
//    amplify add api
//    (Choose GraphQL, provide a name, select 'Authorize and configure with AWS IAM and Amazon Cognito User Pools', etc.)
// 4. Push the changes to deploy your backend:
//    amplify push --yes

view raw JSON →