| title | Tutorial: Query the graph with GQL |
|---|---|
| description | Learn how to query your graph using GQL (Graph Query Language) in the code editor, including pattern matching and filtering examples. |
| ms.topic | tutorial |
| ms.date | 03/24/2026 |
| ms.reviewer | wangwilliam |
| ms.search.form | Tutorial - Query the graph with GQL |
| ai-usage | ai-assisted |
[!INCLUDE feature-preview]
In this tutorial step, you query your graph by using GQL (Graph Query Language) in the code editor. GQL provides powerful querying capabilities for complex graph patterns and analysis.
Follow these steps to switch to the code editor and start querying your graph by using GQL:
-
Go to your graph's home page.
-
Select Code editor from the top menu.
:::image type="content" source="./media/tutorial/select-code-editor.png" alt-text="Screenshot showing result of selecting Code editor." lightbox="./media/tutorial/select-code-editor.png":::
-
Enter a GQL query into the input field. For example, count all orders:
MATCH (n:`Order`) RETURN count(n) AS num_orders
-
Select Run query to execute the query.
This query finds all nodes with the Order label, counts them, and returns the total as num_orders. It's a simple way to confirm your graph has data and that the count matches the number of order rows you loaded. The following image shows the result of the query:
:::image type="content" source="./media/tutorial/code-editor-query-results-1.png" alt-text="Screenshot showing the result of running a GQL query to count all orders." lightbox="./media/tutorial/code-editor-query-results-1.png":::
In the previous tutorial step, you used the query builder to find what products a specific customer purchased. Here's the same query written in GQL:
MATCH (c:Customer)-[:purchases]->(o:`Order`)-[:`contains`]->(p:`Product`)
FILTER c.fullName = 'Carla Adams'
RETURN c.fullName, o, p.productNameThis query:
- Matches the pattern
Customer→purchases→Order→contains→Product - Filters for the customer named "Carla Adams"
- Returns the customer's full name, order details, and product names
The following image shows the result of the query (only a portion of the returned data is shown).
:::image type="content" source="./media/tutorial/code-editor-query-results-2.png" alt-text="Screenshot showing the result of running a GQL query to find products purchased by Carla Adams." lightbox="./media/tutorial/code-editor-query-results-2.png":::
You can run more complex queries that combine matching graph patterns, filtering, aggregation, sorting, and limiting:
MATCH (v:Vendor)-[:produces]->(p:`Product`)->(sc:`ProductSubcategory`)->(c:`ProductCategory`),
(o:`Order`)-[:`contains`]->(p)
FILTER c.categoryName = 'Clothing'
LET vendorName = v.vendorName, subCategoryName = sc.subCategoryName
RETURN vendorName, subCategoryName, count(DISTINCT p) AS num_products, count(o) AS num_orders
GROUP BY vendorName, subCategoryName
ORDER BY num_orders DESC
LIMIT 5This query:
- Matches a pattern that connects vendors to products through the supply chain, and orders to products.
- Filters for products in the
Clothingcategory. - Defines variables for vendor and subcategory names.
- Returns the vendor name, subcategory name, distinct product count, and order count.
- Groups results by vendor and subcategory.
- Orders results by order count in descending order.
- Limits results to the top 5.
In summary, it shows the top five vendors supplying products in the Clothing category, along with how many products they supply and how many orders those products have.
:::image type="content" source="./media/tutorial/code-editor-query-results-3.png" alt-text="Screenshot showing the result of running a GQL query to find the top five vendors supplying products in the Clothing category." lightbox="./media/tutorial/code-editor-query-results-3.png":::
For more information about GQL language support, see:
[!div class="nextstepaction"] Clean up tutorial resources