@aws-amplify/graphql-generation-transformer

中文文档
1.2.9发布于 2026/10/01Apache-2.0TypeScriptCommonJS近 30 天下载 5.2万

Amplify GraphQL @generation transformer

原始使用文档
文档目录7 节
  1. Installation
  2. Directive Definition
  3. Features
  4. Examples
  5. Basic Usage
  6. Advanced Configuration
  7. Limitations

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.

版本与发布记录

@aws-amplify/graphql-generation-transformer 共发布 45 个版本,首次发布于 2024/08/16;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.2.9latest2026/10/011 个月前
1.2.82026/07/143 个月前
1.2.72026/07/014 个月前
1.2.62026/03/247 个月前
1.2.52026/02/069 个月前
1.2.42025/06/101.4 年前

其他发布通道:raven → 0.1.1-raven.7,async-lambda → 0.2.1-async-lambda.0,gen2-migration-0930 → 0.2.2-gen2-migration-0930.0,ai → 0.2.2-ai.3,gen2-migration-1015 → 0.2.4-gen2-migration-1015.0,ai-streaming → 0.2.6-ai-streaming.0。

关于 @aws-amplify/graphql-generation-transformer 的常见问题

@aws-amplify/graphql-generation-transformer 是什么?

Amplify GraphQL @generation transformer

如何安装 @aws-amplify/graphql-generation-transformer?

在项目目录运行 npm install @aws-amplify/graphql-generation-transformer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.3.0)、aws-cdk-lib(^2.224.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws-amplify/graphql-generation-transformer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws-amplify/graphql-generation-transformer 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aws-amplify/graphql-generation-transformer 可以商用吗?

@aws-amplify/graphql-generation-transformer 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-amplify/graphql-generation-transformer 的下载量有多少?

根据 npm 官方下载统计,@aws-amplify/graphql-generation-transformer 在 2026/10/07 – 2026/11/05 这 30 天内被下载 52,442 次,日均约 1,748 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws-amplify/graphql-generation-transformer 还在维护吗?

最新版本 1.2.9 发布于 2026/10/01(1 个月前);至今共发布 45 个版本,其中过去 12 个月发布了 5 个;首次发布于 2024/08/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。