---
schema_version: "1"
id: ca7f57df3f130b7e9d6498c811e5e5d2430db341cac51d7472c22c7ba94534b2
title: Anypoint DataGraph のオブジェクト種別間のリンクのしくみ
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/datagraph/linking.md
canonical_url: https://docs.mulesoft.com/jp/datagraph/linking
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d7c7f3806ae206b6a50bd5df24fc4f0945dc0414e1e14d610cef7ef62154053d
description: MuleSoft Documentation Site
latest: true
---
# Anypoint DataGraph のオブジェクト種別間のリンクのしくみ

現在のオブジェクト種別を別の対象オブジェクト種別にリンクして、クエリ結果を向上させることができます。リンクにより、異なるオブジェクトを説明する 2 つの関連する種別の項目を結合して、この 2 つの種別をつなぎ合わせることができます。

現在の種別のコラボレーションが有効になっていなくても、現在のオブジェクト種別を対象オブジェクト種別にリンクできますが、対象のコラボレーションが有効になっている必要があります。コラボレーションのしくみについての詳細は、「[Anypoint DataGraph でのオブジェクト種別コラボレーションの有効化](https://docs.mulesoft.com/jp/datagraph/collaboration)」を参照してください。

## [](#オブジェクト種別間のリンクの作成)オブジェクト種別間のリンクの作成

2 つの API スキーマがあり、1 つに ​`Order`​ オブジェクト種別、もう 1 つに ​`Customer`​ オブジェクト種別があるとします。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">注文スキーマ</th>
<th class="tableblock halign-left valign-top">顧客スキーマ</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">ordersByOrderId (orderId:String!):Order
--------------------
--------------------
Order
--------------------
orderId: String!
Items: Item[]
customerId: String!</code></pre>
</div>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">customersByCustomerId (customerId:String!): Customer
--------------------
--------------------
Customer
--------------------
customerId: String!
name: String!</code></pre>
</div>
</div></div></td>
</tr>
</tbody>
</table>

現在、統合スキーマは次のようになっています。

```none
ordersByOrderId (orderId:String!):Order
customersByCustomerId (customerId:String!): Customer
--------------------
--------------------
Order
--------------------
orderId: String!
Items: Item[]
customerId: String!
--------------------
--------------------
Customer
--------------------
customerId: String!
name: String!
```

現在のこの設定で、注文データセットと顧客データセットを同時に照会するには、両方の種別を別々に照会する必要があります。

```none
ordersByOrderId (orderId: “123”) {
  orderId
  customerId
}
customersByCustomerId (customerId: “CC83”) {
  customerId
  name
}
```

また、注文の顧客データを照会するには、その注文に関連付けられている顧客 ID が必要です。

ただし、​`Order`​ オブジェクト種別には ​`customerId`​ を返す項目があります。​`customerId: String!`​ を​_外部キー_​として、​`Order`​ オブジェクト種別を ​`Customer`​ オブジェクト種別に​_リンク_​すれば、​`Customer`​ を対象種別として参照できます。このリンクによって選択した外部キーが ​`Customer`​ 種別の主キー ​`customerId:String!`​ にマッピングされます。

その結果、次のようになります。

- `Order`​ オブジェクト種別に ​`Customer`​ という新しい項目が作成され、リンクされた ​`Customer`​ オブジェクト種別を返します。
- API スキーマで生成された新しいオブジェクト種別が ​`Customer`​ API スキーマの種別への参照として機能するため、​`Customer`​ API スキーマに行った変更が ​`Order`​ API スキーマに影響することがありません。
    
    ```none
    ordersByOrderId (orderId:String!):Order
    --------------------
    --------------------
    Order
    --------------------
    orderId: String!
    Items: Item[]
    customer: Customer
    --------------------
    --------------------
    Customer
    --------------------
    --------------------
    customerId: String!
    ```

更新された統合スキーマで、​`Order`​ 種別が ​`Customer`​ 種別にリンクされていることがわかります。

```none
ordersByOrderId (orderId:String!):Order
--------------------
--------------------
Order
--------------------
orderId: String!
Items: Item[]
customer: Customer
--------------------
--------------------
Customer
--------------------
--------------------
customerId: String
name: String
```

リンク後は、統合スキーマの消費者が、関連付けられている ​`customerId`​ を知らなくても、​`Order`​ データセットと関連する ​`Customer`​ データセットを同時に照会できます。

```none
ordersByOrderId (orderId: “123”) {
  orderId
  customer {
    name
  }
}
```

## [](#複合キーを使用するオブジェクト種別間のリンクの作成)複合キーを使用するオブジェクト種別間のリンクの作成

種別のデフォルトのクエリメソッドに​_複合キー_​を使用することもできます。

デフォルトのクエリメソッドに ​`customerId`​ と ​`customerStatus`​ の複合キーを使用する ​`Customer`​ 対象種別について考えてみます。

```none
customerDetail (id: string!, status: string!): Customer
--------------------
--------------------
Customer
--------------------
customerDetail: string!, string!
customerId: String!
customerStatus: String!
```

`Order`​ スキーマは上記と同じであるものとします。

```none
ordersByOrderId (orderId:String!):Order
--------------------
--------------------
Order
--------------------
orderId: String!
Items: Item[]
customerId: String!
```

`Customer`​ 種別を ​`Order`​ 種別の対象としてリンクすると、統合スキーマにリンクが次のように示されます。

```none
ordersByOrderId (orderId:String!):Order
--------------------
--------------------
Order
--------------------
orderId: String!
Items: Item[]
customerId: Customer
customerStatus: Customer
--------------------
--------------------
Customer
--------------------
--------------------
customerDetail: String!, String!
customerId: String!
customerStatus: String!
```

## [](#関連リソース)関連リソース

- [オブジェクト種別間のリンクの作成および編集](https://docs.mulesoft.com/jp/datagraph/manage-links)