@aws-amplify/graphql-conversation-transformer

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

Amplify GraphQL @conversation transformer

原始使用文档
文档目录10 节
  1. Table of Contents
  2. Directive Definition
  3. Usage
  4. Configuration Options
  5. Generated Resources
  6. Examples
  7. Basic Usage
  8. Advanced Usage with Tools and Inference Configuration
  9. Best Practices
  10. Troubleshooting

GraphQL @conversation Transformer

The @conversation transformer is a powerful tool for quickly and easily creating AI-powered conversation routes within your AWS AppSync API. This transformer leverages the capabilities of large language models to enable dynamic, context-aware conversations in your GraphQL schema.

Table of Contents

Directive Definition

The @conversation directive is defined as follows:

directive @conversation(
  aiModel: String!
  systemPrompt: String!
  functionName: String
  tools: [ToolMap]
  inferenceConfiguration: ConversationInferenceConfiguration
) on FIELD_DEFINITION

input ToolMap {
  name: String
  description: String
}

input ConversationInferenceConfiguration {
  maxTokens: Int
  temperature: Float
  topP: Float
}

Usage

To use the @conversation directive, add it to a field in your GraphQL schema. This field should be of type ConversationMessage and should be part of the Mutation type.

type Mutation {
  sendMessage(conversationId: ID!, content: String!): ConversationMessage
    @conversation(aiModel: "anthropic.claude-3-haiku-20240307-v1:0", systemPrompt: "You are a helpful AI assistant.")
}

To find the necessary GraphQL types to use with the @conversation directive, see src/graphql-types/conversation-schema-types.ts.

Configuration Options

The @conversation directive accepts the following configuration options:

  • aiModel (required): Specifies the AI model to be used for generating responses.
  • systemPrompt (required): Defines the initial prompt that sets the context for the AI model.
  • functionName (optional): Specifies a custom Lambda function to handle the conversation logic.
  • tools (optional): An array of tool configurations that the AI can use during the conversation.
  • inferenceConfiguration (optional): Fine-tunes the AI model's behavior with parameters like maxTokens, temperature, and topP.

Generated Resources

When you use the @conversation directive, the transformer generates several AWS resources to support the conversation functionality:

  1. DynamoDB Tables:

    • A table for storing conversation sessions
    • A table for storing individual messages
  2. AppSync Resolvers:

    • A pipeline resolver for the conversation mutation
    • A resolver for the assistant's response mutation
    • A subscription resolver for real-time updates
  3. Lambda Function:

    • A default conversation handler (if no custom functionName is provided)
  4. IAM Roles and Policies:

    • Necessary permissions for AppSync to interact with DynamoDB and Lambda
  5. AppSync Data Sources:

    • DynamoDB data sources for conversation and message tables
    • Lambda data source for the conversation handler

Examples

Basic Usage

type Mutation {
  chat(conversationId: ID!, message: String!): ConversationMessage
    @conversation(
      aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
      systemPrompt: "You are a friendly AI assistant. Respond to user queries in a helpful and concise manner."
    )
}

Advanced Usage with Tools and Inference Configuration

type Mutation {
  customerSupport(conversationId: ID!, inquiry: String!): ConversationMessage
    @conversation(
      aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
      systemPrompt: "You are a customer support AI. Help users with their product inquiries and issues."
      tools: [
        { name: "getProductInfo", description: "Retrieves detailed information about a product" }
        { name: "checkOrderStatus", description: "Checks the status of a customer's order" }
      ]
      inferenceConfiguration: { maxTokens: 500, temperature: 0.7, topP: 0.9 }
    )
}

Best Practices

  1. Craft Clear System Prompts: The system prompt sets the tone and context for the conversation route. Make it specific and aligned with your use case.

  2. Use Appropriate AI Models: Choose AI models that suit your application's needs in terms of capabilities and response time.

  3. Implement Error Handling: Always handle potential errors client-side code.

  4. Monitor and Optimize: Regularly review the performance and costs associated with your conversation route.

Troubleshooting

If you encounter issues while using the @conversation transformer, consider the following:

  1. Check Your Schema: Ensure your GraphQL schema is valid and the @conversation directive is used correctly.

  2. Verify AWS Resources: Check that all required AWS resources have been created successfully.

  3. Review Logs: Examine CloudWatch logs for any errors in your Lambda functions or AppSync resolvers.

  4. Test Incrementally: When adding complex features like custom tools, test each addition incrementally to isolate potential issues.

版本与发布记录

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

版本发布日期距今
1.1.17latest2026/10/011 个月前
1.1.162026/07/143 个月前
1.1.152026/07/014 个月前
1.1.142026/03/247 个月前
1.1.132026/02/069 个月前
1.1.122025/06/101.4 年前

其他发布通道:raven → 0.1.1-raven.11,async-lambda → 0.2.1-async-lambda.0,ai → 0.2.1-ai.5,gen2-migration-0930 → 0.2.2-gen2-migration-0930.0,gen2-migration-1015 → 0.3.1-gen2-migration-1015.0,ai-streaming → 0.5.1-ai-streaming.0。

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

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

Amplify GraphQL @conversation transformer

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

在项目目录运行 npm install @aws-amplify/graphql-conversation-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-conversation-transformer 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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