Easily restore your project to a previous version with our new Instant One-click Backup Recovery
Hygraph
Docs

4.1 Add a Remote Source

#Overview

This step of our Getting Started tutorial covers Remote Sources, our Content Federation utility.

A Remote Source is a custom resolver entry point for your schema that allows data to be sourced from an external third-party web service and accepts field values from other Hygraph fields as arguments.

You'll be able to add content from other systems and sources to the Hygraph API without having to migrate the content itself.

Remote content can take two shapes in your Hygraph project: a Remote Field or a Top-level Remote Field. We'll learn more about them in the following step of our tutorial.

There are many use cases where moving content into the CMS isn't possible or desirable. In our e-commerce project, we're fetching remote data for product reviews.

Let's get to it.

#Configuring our remote source

Since we want to use remote content in our project, the first step is to create a Remote Source in our project Schema. We'll connect a REST API using our DEMO Hygraph API.

Let's configure our remote source:

Configuring our remote sourceConfiguring our remote source

We'll navigate to the Schema Builder, find the Remote Sources section in the left sidebar, and then click +Add.

We'll use the following information:

FieldInput
Select remote source typeCustom source
Display NameHyDemoAPI
TypeUse the radio button to select REST
Base URLThis field displays after selecting a type.
Add http://federatethis.com/. This will be the base endpoint of our API, which Remote fields will use to send queries.

Finally, since REST API responses can have different shapes, we need to define a structure. We'll do this by adding Custom type definitions, which will allow us to define the REST API structure using GraphQL SDL, so we can query the REST API as if it were native GraphQL.

We will be adding six custom type definitions. For each one, click on +Add custom type definition and paste the following snippets:

Your finished remote source should look like this:

Finished remote sourceFinished remote source

#Additional resources

This optional video is not part of the getting started tutorial but it shows a great step-by-step of how to configure a REST remote source!