Remote Sources in Hygraph are custom resolver entry points that allow you to source data from external third-party web services and accept field values from other Hygraph fields as arguments. This enables you to enrich your schema with data from other systems without migrating the content itself. Learn more.
How do Remote Sources work in Hygraph?
Remote Sources allow you to add Remote Fields to your schema at either the model or top level. At the model level, you can enrich data within the context of a specific model. At the top level, you can fetch remote data unrelated to Hygraph, which can be consumed by your frontend alongside Hygraph data. This is achieved through Hygraph's Content Federation utility, eliminating the need for separate API requests. More details.
What types of APIs can Remote Sources connect to?
Remote Sources can connect to both RESTful and GraphQL APIs. You can specify the type when configuring a Remote Source, and provide a base URL for all connected Remote Fields. For REST APIs, you define custom types using GraphQL SDL. For GraphQL APIs, custom types are auto-generated via introspection. Configuration guide.
What are Remote Fields and Top Level Remote Fields?
Remote Fields are fields inside a Hygraph model that connect specific remote data to an entry of that model. Top Level Remote Fields are fields inside the Query system model in Hygraph, used to fetch remote data outside the context of a regular model. Both types enable flexible data integration from external sources. Remote Fields documentation.
What is a Custom Type in the context of Remote Sources?
A Custom Type is a GraphQL type used for content coming from a Remote Source. For RESTful Remote Sources, custom types are defined explicitly using GraphQL SDL. For GraphQL Remote Sources, custom types are auto-generated via introspection. Custom types can be nested and combined with auto-generated types inside Hygraph to create a unified schema. Custom Type guide.
How do you add a Remote Source to your Hygraph project?
To add a Remote Source, navigate to the Schema Builder, find the Remote Sources section, and click +Add. Enter a display name, description, and select the API type (REST or GraphQL). Provide a base URL and optional HTTP headers. For REST, define custom types using SDL; for GraphQL, provide introspection details if needed. Step-by-step instructions.
How do you create a custom type definition for a REST API?
When connecting to a REST API, you can define a Custom Type Definition using GraphQL SDL. Use tools like the JSON to SDL converter to transform JSON responses into valid SDL. You can add multiple types and support nesting for complex data structures. Learn more.
How do you create a custom input type definition for Remote Fields?
Custom input types allow you to pass input parameters to your Remote Source endpoint. Define these using GraphQL SDL, specifying the input parameters needed for your queries. Tools like JSON2SDL can help translate JSON objects to SDL. Custom input type guide.
How do you refresh a GraphQL Remote Source in Hygraph?
If your GraphQL API changes (fields, types, etc.), you can refresh the Remote Source by navigating to its configuration and clicking 'Refetch Remote Schema.' This sends a new introspection query, updating available fields in Hygraph. Ensure your remote fields and return types are compatible with the updated schema. More info.
What are some common issues when working with Remote Sources?
Common issues include API rate limiting when querying many entries simultaneously and schema mismatches after updating a Remote Source. Use sensible pagination limits and ensure your custom types and input types match the API's schema. Refer to GraphQL schema documentation for best practices. Known issues and tips.
Use Cases & Benefits
What are the main use cases for Remote Sources in Hygraph?
Remote Sources are ideal when migrating content into the CMS is not possible or desirable. Use cases include integrating e-commerce/product data (price, availability), content from other vendors (e.g., Github, IMDB), and legacy systems. This enables building data-rich applications with a single GraphQL API, providing flexibility for frontend developers and downstream applications. Use case details.
How do Remote Sources help with content federation?
Remote Sources are a key part of Hygraph's Content Federation utility, allowing you to combine content from multiple systems into a single API. This eliminates data silos and enables consistent content delivery across channels and regions. Content Federation guide.
Technical Requirements & Troubleshooting
What GraphQL scalars and types are supported in custom type definitions?
Custom type definitions support all default GraphQL Scalars such as String, Int, Float, Boolean, ID, and additionally Json. Use ! to indicate non-nullable fields and [Type] for lists (arrays). For more details, see the GraphQL schema documentation.
How do you handle API rate limiting when using Remote Sources?
To avoid API rate limiting or blocking when querying many entries at once, use sensible pagination limits within Hygraph. This ensures requests to third-party APIs remain within acceptable thresholds. Best practices.
Support & Resources
Where can I find step-by-step examples for configuring Remote Sources?
Step-by-step examples for configuring Remote Sources, including REST and GraphQL integrations, are available in the Hygraph documentation. These guides provide sample configurations, custom type definitions, and input type setups. See example.
What resources are available for troubleshooting Remote Sources in Hygraph?
Hygraph provides extensive documentation, guides, and community support for troubleshooting Remote Sources. You can access the API Playground for testing queries, consult the Known Issues and Tips section, and join the Hygraph Slack channel for expert assistance.
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 accept field values from other Hygraph fields as arguments.
With Remote Sources, our Content Federation utility, it's possible to add content from other systems and sources to the Hygraph API without having to migrate the content itself.
You can use Remote Sources to add Remote Fields to your schema, at the model or at the top level:
At the model level, you can use them to enrich data, which can then be queried in the context of the model that they're a part of.
At the top level, you can use them to fetch remote data - unrelated to Hygraph - that can be consumed by your frontend alongside your Hygraph data.
Remote Sources enable teams to build optimized, data-rich applications, where they can use existing services paired with new microservices to build user-friendly applications with a single content entry point.
There are many use cases where moving content into the CMS isn't possible or desirable. Examples include content for which there is a different system of record (e-commerce/product data like price or availability, content from a different vendor like Github or IMDBT, etc) and content that is stored in legacy systems that can’t be easily migrated.
Remote Sources allow customers to create a single GraphQL API with content from all these different sources, providing flexibility for front-end developers and downstream applications.
Remote Source: A system or product that holds content that needs to be combined with content in Hygraph, and which can be queried through a RESTful or GraphQL API. A single Remote Source can have different types of content (e.g. an e-commerce system might have products, categories, prices, etc). Every Remote Source has a unique (base) URL, such as Github, Shopify, Hasura, or a custom backend application.
Remote content: Fields you can add to a model to fetch data from a Remote Source. There are two types:
Remote Field: A field inside a Hygraph model that connects specific remote data to an entry of that model. Remote Fields are always related to a single Remote Source, and a single custom type. RESTful Remote Fields are configured with a path to a specific endpoint in the Remote Source, such as user details from Github, or price & availability from Shopify.
Top Level Remote Field: A field inside the Query system model in Hygraph. These fields are used to fetch remote data outside the context of a regular model, which is then sent to your frontend alongside your Hygraph data. This Content Federation utility eliminates the need to make separate API requests for data inside & outside of Hygraph.
Custom Type: A GraphQL type that is used for content coming from a Remote Source. The custom types are combined with the auto-generated types inside Hygraph to create a single schema for content inside Hygraph and in the Remote Source. For RESTful Remote Sources, custom types need to be defined explicitly using SDL for all URL paths that will be queried in the Remote Source. For GraphQL Remote Sources, the custom types are auto-generated by using introspection on the Remote Source.
Custom Input type: A specific kind of GraphQL type that is used to define input parameters for queries to Remote Sources.
In the left sidebar, find the Remote Sources section located at the bottom of the list, and then click on +Add.
Add a Remote Source
Enter a display name and, optionally, include a description. A prefix is auto-generated and will be pre-pended to all types that are created for this Remote Source. It's also possible to enable debugging for this Remote Source, which will provide more information in case of errors. Make sure to disable this once the Remote Source is properly set up.
Set the type to either REST or GraphQL, depending on the type of API that this Remote Source will connect to.
Provide a base URL. All Remote Fields that connect to this Remote Source will use that base URL.
Optionally, you can include HTTP headers that will be added to all API requests for all Remote Fields connected to this Remote Source. Example use cases include authorization and accepted media types.
If you selected REST in step 4, you can now define your custom types. These provide the mapping from the API responses to the GraphQL schema. Custom input types can optionally also be defined here.
If you selected GraphQL in step 4, you can optionally provide an alternative
introspection URL and custom headers to send to the introspection endpoint. If
no separate introspection URL is provided, the base URL will be used (the default
behavior for most GraphQL APIs is to allow querying and introspection on the same
URL). Custom input types
can optionally also be defined here.
When connecting to a remote REST API you will have the option to define a Custom Type Definition, which allows you to specify the shape of the response coming from the API. It will allow you to query the REST API as if it were native GraphQL. These Custom Type Definitions use GraphQL SDL (Schema Definition Language).
In order to create such a definition, you can follow these steps:
While adding a new Remote Source, or editing an existing one, scroll down to Custom Type Definitions and click on +Add.
You can use our JSON to SDL converter tool to transform the JSON response from your API into valid GraphQL SDL. You might need to make a few tweaks to the generated SDL, especially changing the JSON type to Json (note the difference in casing).
Here's an example of what that would look like:
JSON
SDL
Add the SDL for your custom type to the input field. It's possible to add multiple types in a single input field, after saving the types will be moved to separate fields.
Press Create or Save on the top right corner
Custom types also support nesting, so they can make use of another type, as shown below:
typeProduct{
name:String
metaInfo:MetaInfo
slug:String
}
typeMetaInfo{
createdAt:DateTime
createdBy:String
currency:String
}
In this example, the custom Product type makes use of another custom type MetaInfo.
Remote Fields also allow you to pass along input parameters to your Remote Source endpoint. This can be useful if the identifiable information for the remote data isn't kept in Hygraph, but defined on a request basis. This is relevant for both the REST and GraphQL Remote Sources.
To create such a definition and to use it in a query, you will need to follow these steps:
While adding a new Remote Source, or editing an existing one, scroll down to Custom Input Type Definition and click on +Add.
Similar to the Custom Types, you need to use the GraphQL Schema Definition Language (SDL) to define what the input parameter will look like. A tool that could be used here is JSON2SDL, which allows translating a JSON object to a valid SDL. Keep in mind that we are not defining a type here, but an input.
Let's take an example of passing a productId to our Remote API, that will be used as an input argument. The SDL would look like this:
If something changes on your GraphQL API - i.e., adding or removing fields, or changing types - you can refresh the Remote Source.
Refetch Remote Schema
To do this, navigate to the GraphQL Remote Source you want to refresh, click on the context menu, then click on Refetch Remote Schema.
This sends the new introspection query through the API, and once it goes through successfully, you can use the new fields.
If there is an error happening on refetching, please check the Query section of your Remote Source configuration screen. Make sure that your remote fields are not using a type that's been updated or removed, and that the return type is not using it either.
If you work with Remote Sources and you query a lot of entries at the same time, make sure to use sensible pagination limits within Hygraph, so requests to a third-party API are not rate limited or blocked.
When defining a custom type, you can use all the default GraphQL Scalars such as String, Int, Float, Boolean, ID and additionally Json. ! can be used to indicate a field not being nullable, [Type] will indicate a list (array). More info on the object types and fields can be found here: https://graphql.org/learn/schema/
In this example, we will see how we can define and use a custom input type on a Remote Field. We will be using the Github REST API, specifically the usersendpoint.
We'll first add the Github API as a Remote Source and configure the right custom (input) types.
Set up a new remote source as described above, using [https://api.github.com](https://api.github.com) as the base URL, then add a custom type with the following SDL:
typeUser{
avatar_url:String
bio:String
blog:String
company:String
created_at:DateTime
email:String
events_url:String
followers:Int
followers_url:String
following:Int
following_url:String
gists_url:String
gravatar_id:String
hireable:Boolean
html_url:String
id:Int
location:String
login:String
name:String
node_id:String
organizations_url:String
public_gists:Int
public_repos:Int
received_events_url:String
repos_url:String
site_admin:Boolean
starred_url:String
subscriptions_url:String
twitter_username:String
type:String
updated_at:DateTime
url:String
}
Also add a custom input type with the following SDL:
In an appropriate model, set up a REST Remote Field. In this example, we will use a model called Author and set up the Remote Field with apiId githubUserDetails. In the Remote Field config, add an input argument and select the input type to be the previously created githubInput. In the example, we will use the auto-generated API ID githubInput for the input arguments. We'll also set the field to be required since we will make the path depend on the input value.
Untitled
Now configure the Remote Field's path to use the input argument. You can use the autocomplete feature in the handlebars notation for this.
Make sure there is at least one entry for the selected model, and then head over to the API Playground. The input argument can now be used in a query in the following way:
Please note that since we've made the userId parameter required in the custom input type (by adding a ! at the end), there will be an error if we don't supply the value properly.