https://hasura.io/docs/1.0/graphql/manual/remote-schemas/index.html

Remote Schemas

Introduction

Hasura は認証とアクセスコントロール機能を備えた CRUD と realtime GraphQL API を提供しますが、多くの場合それだけでは不十分で、独自ロジックを処理するための API が必要となることでしょう。例えば支払いのための API や、自分自身のデータベースにはないデータを取得するための API が必要となるでしょう。

Hasura gives you CRUD + realtime GraphQL APIs with authorization & access control. However, in many cases, you will need to write APIs (queries, mutations) that contain custom logic. For example, implementing a payment API, or querying data that is not in your database.

そういうケースに対応するために Hasura には Hasura の外部にある GraphQL schemas を Hasura へと取り込み、統合された単一の GraphQL API を提供する機能を持っています。自動的に Schema を縫い合わせてくれるような機能だと考えてください。そのために必要な作業は、まず独自ロジックを実行するための GraphQL service を立て、次にそのサーバーの HTTP endpoint を Hasura に教えてあげます。これで作業は終わりです。自分で立てる GraphQL サーバーはどの言語、どのフレームワークを使っても構いません。

Hasura has the ability to merge remote GraphQL schemas and provide a unified GraphQL API. Think of it like automated schema stitching. All you need to do is build your own GraphQL service and then provide the HTTP endpoint to Hasura. Your GraphQL service can be written in any language or framework.

Remote Schema がどのように機能するか図示したのが次の図です。

This is what Hasura running with “Remote schemas” looks like:

Screen Shot 2020-07-27 at 14.56.15

Use cases

  • 支払い API ような独自に定義する必要のあるビジネスロジックが必要な場合
  • 自分の用意したデータベースの外部にあるデータを取得する必要がある場合(つまり Hasura のデータベースではなく、Auth0 が持つユーザー情報を取得するケースなど)
  • Custom business logic, like a payment API
  • Querying data that is not available in your database

こういう場合に Remote Schema がうまく機能します。Hasura とは別の GraphQL サーバーを自分で立て、その GraphQL Schema、つまり "Remote Schema " を Hasura が自動生成した Schema と統合します。さらに Remote Schema は一つに限定されません。複数の Remote Schema を統合することが可能です。こうして統合された schema は、統合対象となった schema の和集合と考えることができます。

You can handle these use cases by writing resolvers in a custom GraphQL server and making Hasura merge this “remote schema” with the existing auto-generated schema. You can also add multiple remote schemas. Think of the merged schema as a union of top-level nodes from each of the sub-schemas.

Hasura が自動生成した GraphQL API に認証とアクセスコントロール機能を追加したい場合には、次の資料を参照してください。

Note

If you are looking for adding authorization & access control for your app users to the GraphQL APIs that are auto-generated via Hasura, head to Authentication & Authorization

Remote schema relationships

Hasura がもつ table と remote schema のテーブルに relationship を持たせる remote relationship という機能もあります。Remote schema relationships を参照ください。

You can create remote relationships between your tables and tables from your remote schema. Read more about this in the Remote schema relationships section.