Lab - Building Queries
Lab - Building Queries
Lab - Building Queries
query) and the first field under the root (customer).customer. We will query for firstName, lastName, and email.If you successfully used the login mutation in the previous labs, you should see customer-specific information returned. If you are not currently in a registered customer section or are querying anonymously, you will get a response of null.
In this next query, we will create an alias in a query for product details.
query) and the first field under the root (site).site. We will query for products and include edges and nodes so that we can continue to define the product information we want to query in the next step.products. We will query for entityId, name, and description.title: before “name” in the query to create an alias.In this query, we will ask for the price and salesPrice for a specific product. To avoid repetitive text in the query, let’s create two fragments called PriceFields and MoneyFields.
query) and the first field under the root (site).product. We want to query for a specific product, so type the product ID next to the product field.The examples below use a product ID of “81.” Insert the product ID for a product on your store in place of “81”.
product. We will query for prices.prices. You will see that both price and salesPrice are possible fields. This is where the fragment name will belong. Type ...PriceFields under prices....PriceFields means. At the end of the query, start a new line and create a fragment with the name PriceFields and the type Prices. Then type the fields for which the fragment applies (price and salePrice). In this example, we are creating another fragment called MoneyFields which will be defined in the next step.PriceFields fragment, start a new line and create a fragment with the name MoneyFields and the type Money. The fields for MoneyFields will include value and currencyCode.In this query, we will query for the first 2 products, plus their IDs, and names. Then we will use pagination to view the next 2 products in the catalog after the previous results.
query), query name (paginateProducts), and the first field under the root (site).products in the next field and include how many products we want to see in the response. Then include the page information, cusors, edges, and nodes (entityId and name).cursor value from the previous step next to first:2.