Lab - Query Practice
Lesson 19 of 28 · 30 min
In this lab, you will:
- Query for products within a specific price range
- Query for products with a specific search term and sort them
- Query for banner content
Query for Products Within a Specific Price Range
In this query, we will use a filter to search for the first three products within a price range of 150.
- In the GraphQL playground, begin writing the query with the
root,site,searchfield, andsearchProductsfield.
- Next, let’s add a filter to define the information we want. Add the
filtersfield and specify that we’re looking for thepricewith aminPriceof 50 andmaxPriceof 150.
- Next, let’s add the product information that we want. Add the
productsfield and specify that we want the first 3 products plus theirentityId,name, andprice.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.
Query for Products with a Specific Search Term and Sort Them
In this query, we will ask for the first five products with the word “Shirt” as a search term and then sort them alphabetically.
- In the GraphQL playground, begin writing the query with the
root,site,searchfield, andsearchProductsfield.
- Next, let’s add a filter to define the information we want. Add the
filtersfield and specify that we’re looking for thesearchTerm: "shirt".
- Next, add another filter to sort the information we want. Add the
sortfield and specify that we want to sort the products fromA_TO_Z.
- Lastly, we need to define what product information we want from the products. Add the
productsfield_ and specify that we want the first 5,entityId,name, andprice.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.
Query for Banner Content
In this query, we will ask to see the entityId, name, content, and location of a banner on the Home Page.
- In the GraphQL playground, begin writing the query with the
root,site, andcontentfields.
- Next, let’s specify the information we want. Add the
bannersfield and specify that we’re looking for theentityId,name,content, andlocation.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.