4.1 Add a Remote Source
In this lesson you'll learn how to add a Remote Source to your project in order to fetch information from external third-party web services.
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 source
We'll navigate to the Schema Builder, find the Remote Sources section in the left sidebar, and then click
We'll use the following infomration:
|Type||Use the radio button to select |
|Base URL||This field displays after selecting a type. |
The last step is to add our
Custom type definitions, which will allow us to define the structure of our
REST API using
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 source
Would you like to know more?
Here's a video on configuring a REST remote source:
#SDL & our custom type definitions
Schema Definition Language or
SDL is a way to define the shape of data that can be queried in a
GraphQL API. It describes the schema or types of data available, their relationships, and how the data can be queried. We need to tell Hygraph the shape of the data to expect and make available.
REST API can use multiple endpoints to return fixed data structures, a
GraphQL API - not being limited to returning fixed structures - will expose just one. The custom type definitions that we added above allow us to specify the shape of the response coming from the API, so we can query the
REST API as if it were native
Would you like to know more? Check out this document on GraphQL core concepts
Once you've configured a Remote Source, move on to our next lesson:4.2 Remote Fields