Hygraph
Docs

#Lesson 5.2 - Add remote fields

In this lesson, you will add a remote field to the Product model. Remote fields fetch data from a remote source in the context of a specific model entry. The field uses a value from the entry itself, in this case productSlug, as the argument passed to the external API, so the reviews returned are always scoped to that product.

This is different from a top-level remote field, which fetches remote data independently of any entry. That is covered in lesson 5.3.

#Add a remote field to the Product model

You will use the HyDemoAPI remote source configured in lesson 5.1 to add a Reviews field to the Product model.

Add a remote field to the Product model
  1. Open the Product model in the Schema editor and from the right sidebar, add a REST remote field.

  2. Fill in the following information:

    FieldInput
    Display nameReviews
    API IDAuto-completed. Leave as is.
    Remote sourceHyDemoAPI is selected by default. Leave as is.
    MethodGET is selected by default. Leave as is.
    Return typeSelect Reviews from the dropdown
    Path/api/reviews/product/{{doc.productSlug}}

    The Path appends to the remote source base URL. {{doc.productSlug}} references the productSlug field on the current Product entry, which scopes the review data to that specific product.

  3. Click Add to save.

#What's next

Lesson 5.3 - Add top-level remote fields

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