Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions docs/docs/third-party-graphql.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
---
title: Using Third-party GraphQL APIs
title: サードパーティー GraphQL APIの使用
---

Gatsby v2 introduces a simple way to integrate any GraphQL API into Gatsby's GraphQL. You can integrate both third-party APIs, like GitHub's, APIs of services like GraphCMS or your custom GraphQL API.
Gatsby v2 では、プラグイン 1 つでどんな GraphQL API でも GatsbyGraphQL に統合できます。これは、GitHub などのサードパーティー API、GraphCMS などのサービスの API、あるいは独自の GraphQL API なども含みます。

## Basic example
## 基本的な例

First install the plugin.
最初に、プラグインをインストールします。

```shell
npm install gatsby-source-graphql
```

Provided there is a GraphQL API under a `url`, adding it to an API just requires adding this to the config.
`url` の下に GraphQL API がある場合、それを API に追加するには以下を設定に追加するだけです。

```js:title=gatsby-config.js
module.exports = {
plugins: [
{
resolve: "gatsby-source-graphql",
options: {
// This type will contain remote schema Query type
// このタイプには、リモートスキーマのクエリタイプが含まれます
typeName: "SWAPI",
// This is the field under which it's accessible
// これはアクセス可能なフィールドです
fieldName: "swapi",
// URL to query from
// クエリ元の URL です
url: "https://api.graphcms.com/simple/v1/swapi",
},
},
],
}
```

See all configuration options in the [plugin docs](/packages/gatsby-source-graphql)
すべての設定ファイルのオプションは[プラグインドキュメント](/packages/gatsby-source-graphql)をご覧ください。

Third-party APIs will be available under the `fieldName` specified, so you can query through it normally.
サードパーティーの API は、指定された `fieldName` で使用できるため、通常どおりクエリを実行できます。

```graphql
{
# Field name parameter defines how you can access a third-party API
# フィールド名パラメーターは、サードパーティーの API にアクセスする方法を指定します
swapi {
allSpecies {
name
Expand All @@ -47,11 +47,11 @@ Third-party APIs will be available under the `fieldName` specified, so you can q
}
```

Note that types of the third-party API will be prefixed with `${typeName}_`. You need to prefix it too, e.g. when using variables or fragments.
サードパーティー API のタイプには、`${typeName}_` という接頭辞が付きます。変数またはフラグメントを使用する場合などにも、接頭辞が必要です。

```graphql
{
# Field name parameter defines how you can access third-party API
# フィールド名パラメーターは、サードパーティー API にアクセスする方法を指定します
swapi {
allSpecies {
... on SWAPI_Species {
Expand All @@ -62,9 +62,9 @@ Note that types of the third-party API will be prefixed with `${typeName}_`. You
}
```

## Creating pages dynamically through third-party APIs
## サードパーティー API を使用してページを動的に作成する

You can also create pages dynamically by adding a `createPages` callback in `gatsby-node.js`. For example you can create a page for every Star Wars species.
`gatsby-node.js` に `createPages` コールバックを追加して、ページを動的に作成することもできます。たとえば、下記の例ではスターウォーズに登場する全ての種族のページを作成できます。

```js:title=gatsby-node.js
const path = require(`path`)
Expand Down Expand Up @@ -93,10 +93,10 @@ exports.createPages = async ({ actions, graphql }) => {
}
```

## Further reading
## もっと詳しく

- [gatsby-source-graphql docs](/packages/gatsby-source-graphql)
- [Example with GitHub API](https://github.com/freiksenet/gatsby-github-displayer)
- [Example with GraphCMS](https://github.com/freiksenet/gatsby-graphcms)
- [Example with Hasura](https://github.com/hasura/graphql-engine/tree/master/community/sample-apps/gatsby-postgres-graphql)
- [Example with AWS AppSync](https://github.com/aws-samples/aws-appsync-gatsby-sample)
- [gatsby-source-graphql ドキュメント](/packages/gatsby-source-graphql)
- [GitHub API を使用した例](https://github.com/freiksenet/gatsby-github-displayer)
- [GraphCMS を使用した例](https://github.com/freiksenet/gatsby-graphcms)
- [Hasura を使用した例](https://github.com/hasura/graphql-engine/tree/master/community/sample-apps/gatsby-postgres-graphql)
- [AWS AppSync を使用した例](https://github.com/aws-samples/aws-appsync-gatsby-sample)