5m
Exercise 1: Featured listings (⏳ 5 min)
Open up Sandbox at http://localhost:4000 where the local router is running.
When you run the operation below, you'll get an error!
GetFeaturedListings
query GetFeaturedListings {featuredListings {idtitlecostPerNightnumOfBedsclosed}}
Exercise #1 Goal
🎯 Retrieve data for all of the fields under the Listing type when querying for featuredListings.
Use this REST API endpoint:
https://airlock-listings.demo-api.apollo.dev/featured-listings
After successfully completing the exercise, you should get data back when running the GetFeaturedListings operation again.
Check your work
Answer the following questions after you've completed the exercise. Lost? Check out the hints and solution below.
Is the 'Cozy yurt in Mraza' closed?
What happens when you include a field in the
selection that is NOT defined in the schema? (For example, try adding latitude to the selection.)💭 Hints
Tips:
- Take it one step at a time! Comment out all fields under the
Listingtype except forid. Let's start with the bare minimum. - Use the Connectors Debugger panel to examine the response object that comes back.
- Use the
products.graphqlschema file as a reference.
✅ Solution
listings.graphql
extend schema@link(url: "https://specs.apollo.dev/federation/v2.11", import: ["@key"])@link(url: "https://specs.apollo.dev/connect/v0.2"import: ["@connect", "@source"])@source(name: "listings"http: { baseURL: "https://airlock-listings.demo-api.apollo.dev" })type Query {"A curated array of listings to feature on the homepage"featuredListings: [Listing!]!@connect(source: "listings"http: { GET: "/featured-listings" }selection: """idtitlenumOfBedscostPerNightclosed: closedForBookings""")}