1m
Follow-along: Add the listings subgraph
Create a new file called
listings.graphqland paste the following schema:listings.graphqlextend schema@link(url: "https://specs.apollo.dev/federation/v2.11", import: ["@key"])type Query {"A curated array of listings to feature on the homepage"featuredListings: [Listing!]!# # EXERCISE: LISTING DETAILS# "A specific listing"# listing(id: ID!): Listing}"A particular intergalactic location available for booking"type Listing {id: ID!"The listing's title"title: String!"The number of beds available"numOfBeds: Int"The cost per night"costPerNight: Float"Indicates whether listing is closed for bookings (on hiatus)"closed: Boolean# # EXERCISE: LISTING ACTIVITIES# "The activities available for this listing"# activities: [Activity!]!}# # EXERCISE: LISTING ACTIVITIES# type Activity {# id: ID!# name: String!# description: String# terrain: String# groupSize: Int# }Open up the
supergraph.yamlfile.Update the configuration to include the
listingssubgraph under thesubgraphsproperty. (It should be at the same level asproducts).supergraph.yamlsubgraphs:products:routing_url: http://ignoredschema:file: products.graphqllistings:routing_url: http://ignored # this value is ignoredschema:file: listings.graphqlfederation_version: =2.11.0Save your changes and
rover devwill restart, composing thelistingssubgraph schema.Go to http://localhost:4000. We'll add the new entry point to our operation for
featuredListings.GraphQL operationquery GetProductsAndListings {products {idnamedescriptioncategory}featuredListings {idtitle}}We'll get an error because our
listingssubgraph is not set up to return anything yet!Response errors{"data": null,"errors": [{"message": "HTTP fetch failed from 'listings': HTTP fetch failed from 'listings': error trying to connect: dns error: no record found for Query { name: Name(\"ignored.\"), query_type: AAAA, query_class: IN }","path": [],"extensions": {"code": "SUBREQUEST_HTTP_ERROR","service": "listings","reason": "HTTP fetch failed from 'listings': error trying to connect: dns error: no record found for Query { name: Name(\"ignored.\"), query_type: AAAA, query_class: IN }"}}],"extensions": {"valueCompletion": [{"message": "Cannot return null for non-nullable field Query.featuredListings","path": []}]}}
In the next exercise, you'll fix those errors!
Task!