6. Exercise 2: A specific listing's details
5m

Exercise 2: A listing's details ( 5 min)

Uncomment the following lines from the listings.graphql schema.

listings.graphql
# EXERCISE: LISTING DETAILS
"A specific listing"
listing(id: ID!): Listing
Task!

Save your changes. rover dev will now give you an error:

error[E029]: Encountered 1 build error while trying to build a supergraph.
Caused by:
QUERY_FIELD_MISSING_CONNECT: The field `Query.listing` has no `@connect` directive.

Exercise #2 Goal

🎯 Retrieve data for the Query.listing(id) .

Use this REST API endpoint:

https://airlock-listings.demo-api.apollo.dev/listings/:id

After successfully completing the exercise, you should get data back when running the GetListingDetails below:

GetListingDetails
query GetListingDetails($listingId: ID!) {
listing(id: $listingId) {
id
title
numOfBeds
costPerNight
closed
}
}

For the Variables section:

{
"listingId": "listing-9"
}

Recap: $args

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-9, which of the following statements are true?

💭 Hints

Solution

listings.graphql
listing(id: ID!): Listing
@connect(
source: "listings"
http: { GET: "listings/{$args.id}" }
selection: """
id
title
numOfBeds
costPerNight
closed: closedForBookings
"""
)
Previous