

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# [リゾルバ]
<a name="sam-property-graphqlapi-resolver"></a>

GraphQL API のフィールドにリゾルバーを設定します。 AWS Serverless Application Model (AWS SAM) は [JavaScript パイプラインリゾルバー](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html)をサポートします。

## 構文
<a name="sam-property-graphqlapi-resolver-syntax"></a>

 AWS Serverless Application Model (AWS SAM) テンプレートでこのエンティティを宣言するには、次の構文を使用します。

### YAML
<a name="sam-property-graphqlapi-resolver-syntax-yaml"></a>

```
OperationType:
  LogicalId:
    Caching: [CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-cachingconfig.html)
    CodeUri: String
    FieldName: String
    InlineCode: String 
    MaxBatchSize: Integer
    Pipeline: List
    Runtime: Runtime
    Sync: [SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-syncconfig.html)
```

## プロパティ
<a name="sam-property-graphqlapi-resolver-properties"></a>

`Caching`  <a name="sam-graphqlapi-resolver-caching"></a>
キャッシュが有効になっているリゾルバーのキャッシュ構成です。  
タイプ: [CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-cachingconfig.html)  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-cachingconfig)`プロパティに直接渡されます。

`CodeUri`  <a name="sam-graphqlapi-resolver-codeuri"></a>
リゾルバー関数コードの Amazon Simple Storage Service (Amazon S3) URI、またはローカルフォルダへのパスです。  
ローカルフォルダへのパスを指定する場合、 CloudFormation はデプロイ前にファイルを最初に Amazon S3 にアップロードする必要があります。 AWS SAM CLI を使用することで、この処理を円滑化することができます。詳細については、「[がデプロイ時にローカルファイル AWS SAM をアップロードする方法](deploy-upload-local-files.md)」を参照してください。  
`CodeUri` または が指定されていない場合、 AWS SAM `InlineCode`はリクエストを最初のパイプライン関数に`InlineCode`リダイレクトし、最後のパイプライン関数からレスポンスを受け取る を生成します。  
*タイプ*: 文字列  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[CodeS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-codes3location)`プロパティに直接渡されます。

`FieldName`  <a name="sam-graphqlapi-resolver-fieldname"></a>
リゾルバーの名前です。このプロパティを指定して、`LogicalId` 値を上書きします。  
*タイプ*: 文字列  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[FieldName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-fieldname)`プロパティに直接渡されます。

`InlineCode`  <a name="sam-graphqlapi-resolver-inlinecode"></a>
リクエスト関数とレスポンス関数が含まれるリゾルバーコードです。  
`CodeUri` または が指定されていない場合、 AWS SAM `InlineCode`はリクエストを最初のパイプライン関数に`InlineCode`リダイレクトし、最後のパイプライン関数からレスポンスを受け取る を生成します。  
*タイプ*: 文字列  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[Code](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-code)`プロパティに直接渡されます。

`LogicalId`  <a name="sam-graphqlapi-resolver-logicalid"></a>
リゾルバーの一意の名前です。GraphQL スキーマでは、リゾルバーが使用されるフィールド名が、リゾルバー名と一致する必要があります。`LogicalId` にも、それと同じフィールド名を使用してください。  
*タイプ*: 文字列  
*必須*: はい  
*CloudFormation 互換性*: このプロパティは に固有 AWS SAM であり、 CloudFormation 同等のものはありません。

`MaxBatchSize`  <a name="sam-graphqlapi-resolver-maxbatchsize"></a>
`BatchInvoke` オペレーションの単一の AWS Lambda 機能に送信されるリゾルバーリクエスト入力の最大数を指定します。  
*タイプ:* 整数  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[MaxBatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-maxbatchsize)`プロパティに直接渡されます。

`OperationType`  <a name="sam-graphqlapi-resolver-operationtype"></a>
リゾルバーに関連付けられている GraphQL オペレーションタイプです。例えば、`Query`、`Mutation`、または `Subscription` などです。単一の `OperationType` 内にある `LogicalId` で、複数のリゾルバーをネストすることができます。  
*タイプ*: 文字列  
*必須*: はい  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[TypeName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-typename)`プロパティに直接渡されます。

`Pipeline`  <a name="sam-graphqlapi-resolver-pipeline"></a>
パイプランリゾルバーにリンクされている関数。リスト内の論理 ID で関数を指定します。  
*タイプ*: リスト  
*必須:* はい  
*CloudFormation 互換性*: このプロパティは に固有 AWS SAM であり、 CloudFormation 同等のプロパティはありません。これは、`AWS::AppSync::Resolver` リソースの `[PipelineConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-pipelineconfig)` プロパティに似ています。

`Runtime`  <a name="sam-graphqlapi-resolver-runtime"></a>
パイプラインリゾルバーまたは関数のランタイムです。使用する名前とバージョンを指定します。  
タイプ: [Runtime](sam-property-graphqlapi-resolver-runtime.md)  
*必須:* はい  
*CloudFormation 互換性*: このプロパティは に固有 AWS SAM であり、 CloudFormation 同等のプロパティはありません。これは、`AWS::AppSync::Resolver` リソースの `[Runtime](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-runtime)` プロパティに似ています。

`Sync`  <a name="sam-graphqlapi-resolver-sync"></a>
リゾルバーの同期構成について説明します。  
リゾルバーが呼び出されたときに、どの競合検出戦略および解決戦略を使用するかを指定します。  
タイプ: [SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-syncconfig.html)  
*必須:* いいえ  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver`リソースの `[SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-syncconfig)`プロパティに直接渡されます。

## 例
<a name="sam-property-graphqlapi-resolver-examples"></a>

### AWS SAM 生成されたリゾルバー関数コードを使用し、フィールドを変数として保存する
<a name="sam-property-graphqlapi-resolver-examples-example1"></a>

以下は、この例の GraphQL スキーマです。

```
schema {
  query: Query
  mutation: Mutation
}

type Query {
  getPost(id: ID!): Post
}

type Mutation {
  addPost(author: String!, title: String!, content: String!): Post!
}

type Post {
  id: ID!
  author: String
  title: String
  content: String
}
```

 AWS SAM テンプレートのスニペットを次に示します。

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyGraphQLApi:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      ...
      Functions:
        preprocessPostItem:
          ...
        createPostItem:
          ...
      Resolvers:
        Mutation:
          addPost:
            Runtime:
              Name: APPSYNC_JS
              Version: 1.0.0
            Pipeline:
            - preprocessPostItem
            - createPostItem
```

 AWS SAM テンプレートでは、 `CodeUri`または を指定しません`InlineCode`。デプロイ時に、 はリゾルバーの次のインラインコード AWS SAM を自動的に生成します。

```
export function request(ctx) {
  return {};
}

export function response(ctx) {
  return ctx.prev.result;
}
```

このデフォルトリゾルバーコードは、リクエストを最初のパイプライン関数にリダイレクトし、最後のパイプライン関数からレスポンスを受け取ります。

最初のパイプライン関数では、提供された `args` フィールドを使用してリクエストオブジェクトを解析し、変数を作成することができます。作成後、関数内でこれらの変数を使用できます。以下は、`preprocessPostItem` 関数の例です。

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  const author = ctx.args.author;
  const title = ctx.args.title;
  const content = ctx.args.content;
  
  // Use variables to process data
  
}

export function response(ctx) {
  return ctx.result;
}
```

# 実行時間
<a name="sam-property-graphqlapi-resolver-runtime"></a>

パイプラインリゾルバーまたは関数のランタイムです。使用する名前とバージョンを指定します。

## 構文
<a name="sam-property-graphqlapi-resolver-runtime-syntax"></a>

 AWS Serverless Application Model (AWS SAM) テンプレートでこのエンティティを宣言するには、次の構文を使用します。

### YAML
<a name="sam-property-graphqlapi-resolver-runtime-syntax-yaml"></a>

```
Name: String
Version: String
```

## プロパティ
<a name="sam-property-graphqlapi-resolver-runtime-properties"></a>

`Name`  <a name="sam-graphqlapi-resolver-runtime-name"></a>
使用するランタイムの名前です。現在許容されている値は、`APPSYNC_JS` のみです。  
*タイプ*: 文字列  
*必須*: はい  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver AppSyncRuntime` オブジェクトの `[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-appsyncruntime.html#cfn-appsync-resolver-appsyncruntime-name)`プロパティに直接渡されます。

`Version`  <a name="sam-graphqlapi-resolver-runtime-version"></a>
使用するランタイムのバージョンです。現在許容されているバージョンは、`1.0.0` のみです。  
*タイプ*: 文字列  
*必須*: はい  
*CloudFormation 互換性*: このプロパティは、 `AWS::AppSync::Resolver AppSyncRuntime` オブジェクトの `[RuntimeVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-appsyncruntime.html#cfn-appsync-resolver-appsyncruntime-runtimeversion)`プロパティに直接渡されます。