Hygraph
Docs

#Lesson 5.1 - Add a remote source

In this lesson, you will add a remote source to the project schema. Before this step, the schema only returns data stored in Hygraph. After it, the schema includes queryable types from an external REST API that can be fetched alongside Hygraph content.

A remote source is a custom resolver entry point in the schema. It accepts field values from other Hygraph fields as arguments, which is what makes it possible to fetch reviews scoped to a specific product in lesson 5.2.

#Configure the remote source

You will connect a REST API using the Hygraph demo API.

Configuring the remote source
  1. Navigate to the Schema editor and click +Add next to Remote Sources.

  2. Fill in the following information:

    FieldInput
    Select remote source typeCustom source
    Display NameHyDemoAPI
    TypeREST
    Base URLhttps://demo-api.hygraph.workers.dev

    The base URL is the root endpoint for all remote fields that use this source. Individual remote fields append their own paths to this base.

  3. Click Add to save the remote source configuration before adding type definitions.

#Add custom type definitions

REST APIs return fixed data structures. To query a REST API as if it were native GraphQL, Hygraph needs to know the shape of the data it will receive. Custom type definitions provide that shape using GraphQL SDL.

  1. For each type definition, click +Add custom type definition and paste the snippets:

  2. Click Add Remote Source to save the configuration.

Your finished remote source should look like this:

Finished remote source

The Reviews type wraps a list of Review entries. These two types are used by the remote fields in lessons 5.2 and 5.3.

#What's next

Lesson 5.2 - Add remote fields

Or, go to the Tutorial overview for the full lesson list.