Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@aws-amplify/graphql-generation-transformer

aws-amplify39.1kApache-2.01.2.4TypeScript support: included

Amplify GraphQL @generation transformer

readme

Amplify GraphQL Generation Transformer

The Amplify GraphQL Generation Transformer is a tool that enables the quick and easy creation of AI-powered Generation routes within your AWS AppSync API. This transformer can be leveraged by using the @generation directive to configure AI models and system prompts for generating content.

Installation

npm install @aws-amplify/graphql-generation-transformer

Directive Definition

The @generation directive is defined as follows:

directive @generation(aiModel: String!, systemPrompt: String!, inferenceConfiguration: GenerationInferenceConfiguration) on FIELD_DEFINITION

Features

  1. AI Model Integration: Specify the AI model to be used for generation.
  2. System Prompt Configuration: Define a system prompt to guide the AI's output.
  3. Inference Configuration: Fine-tune generation parameters like max tokens, temperature, and top-p.
  4. Integrates with @auth Directive: Supports existing auth modes like IAM, API key, and Amazon Cognito User Pools.
  5. Resolver Creation: Generates resolvers with tool definitions based on the Query field's return type to interact with the specified AI model.
  6. Bedrock HTTP Data Source Creation: Creates a AppSync HTTP Data Source for Bedrock to interact with the specified AI model.

Examples

Basic Usage

Scalar Type Generation

type Query {
  generateStory(topic: String!): String
    @generation(
      aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
      systemPrompt: "You are a creative storyteller. Generate a short story based on the given topic."
    )
}

Complex Type Generation

type Recipe {
  name: String!
  ingredients: [String!]!
  instructions: [String!]!
  prepTime: Int!
  cookTime: Int!
  servings: Int!
  difficulty: String!
}

type Query {
  generateRecipe(cuisine: String!, dietaryRestrictions: [String]): Recipe
    @generation(
      aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
      systemPrompt: "You are a professional chef specializing in creating recipes. Generate a detailed recipe based on the given cuisine and dietary restrictions."
    )
}

Advanced Configuration

type Query {
  generateCode(description: String!): String
    @generation(
      aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
      systemPrompt: "You are an expert programmer. Generate code based on the given description."
      inferenceConfiguration: { maxTokens: 500, temperature: 0.7, topP: 0.9 }
    )
}

Limitations

  • The @generation directive can only be used on Query fields.
  • The AI model specified must:
    • be supported by Amazon Bedrock's /converse API
    • support tool usage
  • Some AppSync scalar types are not currently supported.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.2.4 (2025-06-09)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.2.3 (2025-04-17)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.2.2 (2025-04-09)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.2.1 (2025-03-06)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.2.0 (2025-02-26)

Features

1.1.5 (2025-02-07)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.1.4 (2025-01-30)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.1.3 (2025-01-16)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.1.2 (2024-12-23)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.1.1 (2024-12-17)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

1.1.0 (2024-11-19)

Bug Fixes

  • ai: forward user-agent with package metadata in generation and conversation requests (#3029) (9a0ac8b)

Features

  • bump conversation and generation transformers to v1 (#3030) (1d9e59e)

0.2.7 (2024-11-14)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.6 (2024-11-08)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.5 (2024-10-28)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.4 (2024-10-17)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.3 (2024-10-10)

Bug Fixes

  • generation: gracefully handle stringified tool_use responses (#2919) (db34e42)
  • generation: remove trailing comma in inferenceConfig resolver code (#2933) (9dde73c)

0.2.2 (2024-10-01)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.1 (2024-09-16)

Note: Version bump only for package @aws-amplify/graphql-generation-transformer

0.2.0 (2024-09-06)

Features

  • conversation: add conversation transformer (#2827) (cee6aef)
  • generation-transformer: add generation transformer (#2820) (a86db4e)