Lab - Query Practice
In this lab, you will:
- Query for product images at specific resolutions
- Query for customer specific pricing information
- Query for product custom fields
- Query for variant and option information
Query for Product Images at Specific Resolutions
In this query, we will ask for the first 2 products, their IDs, name, and default image URL at resolutions of 200px, 400px, and 600px. We will also use aliases to be able to tell the difference between image resolutions in the response.
- In the GraphQL playground, begin writing the query with the
root,sitefield, andproductsfield. Specify next to the products field that we only want 2 products in the response.
- Type the information we want in the response under
node:entityId,name, and default image.
- Specify the resolutions by typing
width:200,width:400, andwidth:600next to separateurlrequests.
- Create an alias for each image resolution that will specify what each result is in the response.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.
Query for Customer-Specific Pricing Information
In this query, we will ask to see pricing information based on the customer’s set price list. Before you begin this exercise, make sure you have a price list set up and assigned to a customer group. Read the article below for more information about Price Lists.
Before you begin this exercise, make sure you have a price list set up and assigned to a customer group. Also, make sure you have a registered customer assigned to the same customer group.
- First, let’s see what the price of a product is without a logged-in customer. In the GraphQL playground, begin writing the query with the
root,sitefield, andproductsfield. Specify that we only want to view the first 3 products in this query, as well as theentityId,name, andprice value.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response. Take note of the price of the product without an associated customer.
- Use the
loginmutation to log in as a customer who is in a customer group associated with a price list.
If you are already logged in as a customer make sure that the customer is in the correct group to receive your specialty price list prices.
5. In the GraphQL Playground, open a new tab and begin writing the query with the root, and customer field. Specify that we want the customer’s firstName and lastName.
- Add the same
siterequest information from the previous steps to this query.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response. See that the price is different than the first query because the customer is assigned to a specific price list.
Query for Product Custom Fields
In this query, we will ask for the name and value of a product’s custom fields. To successfully complete this step, you will need to have a product with at least one custom field. Read the article below for more information about custom fields.
- In the GraphQL playground, begin writing the query with the
root,sitefield, andproductfield. Specify the product ID next to the product field and that we want to query for the product’snameand custom fields.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.
Query for Variant and Option Information
In this query, we will ask for a product’s options and variant information.
- First, let’s ask for a product’s available options. In the GraphQL playground, begin writing the query with the
root,sitefield, andproductfield. Specify the product ID next to the product field and that we want to query for theproductOptions,entityId, anddisplayName. Be sure to select the ID of a product in your store that has some variants and options built into it.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.
- Next, let’s add variant details to this query. Add the
variantsfield and specify that we want to see the variantentityId,sku, andprice.
- Click the Play button in the middle of the GraphQL Playground to run the query.
- Observe the response.