Plan: Developer Foundations
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 50and150.
- In the GraphQL playground, begin writing the query with the
root, site, search field, and searchProducts field.
- Next, let’s add a filter to define the information we want. Add the
filters field and specify that we’re looking for the price with a minPrice of 50 and maxPrice of 150.
- Next, let’s add the product information that we want. Add the
products field and specify that we want the first 3 products plus their entityId, name, and price.
- 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, search field, and searchProducts field.
- Next, let’s add a filter to define the information we want. Add the
filters field and specify that we’re looking for the searchTerm: "shirt".
- Next, add another filter to sort the information we want. Add the
sort field and specify that we want to sort the products from A_TO_Z.
- Lastly, we need to define what product information we want from the products. Add the
products field_ and specify that we want the first 5, entityId, name, and price.
- 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, and content fields.
- Next, let’s specify the information we want. Add the
banners field and specify that we’re looking for the entityId, name, content, and location.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.