#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.
-
Navigate to the Schema editor and click +Add next to Remote Sources.
-
Fill in the following information:
Field Input Select remote source type Custom source Display Name HyDemoAPI Type REST Base URL https://demo-api.hygraph.workers.devThe base URL is the root endpoint for all remote fields that use this source. Individual remote fields append their own paths to this base.
-
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.
SDL stands for Schema Definition Language. It is the syntax used to define types and their fields in a GraphQL schema. The type definitions added here describe the structure of the data the HyDemoAPI returns, so Hygraph can expose those types in the project's GraphQL schema.
-
For each type definition, click +Add custom type definition and paste the snippets:
ReviewReviews -
Click Add Remote Source to save the configuration.
Your finished remote source should look like this:
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 fieldsOr, go to the Tutorial overview for the full lesson list.