5m
Exercise 3: A listing's activities (⏳ 5 min)
Uncomment the following lines from the listings.graphql schema:
listings.graphql
type Listing {# ...other Listing fields# EXERCISE: LISTING ACTIVITIES"The activities available for this listing"activities: [Activity!]!}# EXERCISE: LISTING ACTIVITIEStype Activity {id: ID!name: String!description: Stringterrain: StringgroupSize: Int}
Task!
Save your changes. rover dev will now give you an error:
error[E029]: Encountered 6 build errors while trying to build a supergraph.Caused by:CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Listing.activities`. It must have a `@connect` directive or appear in `@connect(selection:)`.CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Activity.id`. It must have a `@connect` directive or appear in `@connect(selection:)`.CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Activity.name`. It must have a `@connect` directive or appear in `@connect(selection:)`.CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Activity.description`. It must have a `@connect` directive or appear in `@connect(selection:)`.CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Activity.terrain`. It must have a `@connect` directive or appear in `@connect(selection:)`.CONNECTORS_UNRESOLVED_FIELD: [listings] No connector resolves field `Activity.groupSize`. It must have a `@connect` directive or appear in `@connect(selection:)`.
Exercise #3 Goal
🎯 Retrieve data for the Listing.activities field.
Use this REST API endpoint:
https://activities-rest-api-0d717e1922e0.herokuapp.com/location/:id/activities
After successfully completing the exercise, you should get data back when running the GetListingActivities operation below:
GetListingActivities
query GetListingActivities($listingId: ID!) {listing(id: $listingId) {idtitleactivities {idnamedescriptionterraingroupSize}}}
For the Variables section:
{"listingId": "listing-1"}
Recap: $this
Check your work
Answer the following questions after you've completed the exercise. Lost? Check out the hints and solution below.
For the listing with id
listing-1, which of the following statements about the listing's activities are true?How many network calls did the
GetListingActivities operation make?💭 Hints
✅ Solution
listings.graphql
extend schema# ...other schema extensions@source(name: "activities"http: { baseURL: "https://activities-rest-api-0d717e1922e0.herokuapp.com" })type Listing {# ...other Listing fields"The activities available for this listing"activities: [Activity!]!@connect(source: "activities"http: { GET: "/location/{$this.id}/activities" }selection: """idnamedescriptionterraingroupSize""")}# EXERCISE: LISTING ACTIVITIEStype Activity {id: ID!name: String!description: Stringterrain: StringgroupSize: Int}