Overview
Queries allow you to retrieve data from your GraphQL API. Type GraphQL Query automatically generates powerful query endpoints with filtering, sorting, paging, and search capabilities.
What You’ll Learn
Section intitulée « What You’ll Learn »This documentation will help you understand:
- ✅ How queries are automatically generated
- ✅ Available query endpoints
- ✅ How to use filtering, sorting, and paging
- ✅ How to query relations
- ✅ How to use search functionality
Overview
Section intitulée « Overview »Queries are read-only operations that return data. Type GraphQL Query automatically generates queries for all DTOs, providing powerful capabilities out of the box.
Automatic Query Generation
Section intitulée « Automatic Query Generation »When you define a DTO and register it in a module, Type GraphQL Query automatically creates:
| Query | Description | Example |
|---|---|---|
findOne{Type} |
Find a single record by ID | findOneProduct(id: "123") |
{types} |
Query multiple records with filtering, sorting, paging | products(filter: {...}, paging: {...}) |
Custom Queries
Section intitulée « Custom Queries »You can also define custom queries using the @Query() decorator:
import { Query, Resolver } from '@lib/type-graphql';import { Product } from './product';
@Resolver()export class ProductResolver { @Query(() => [Product]) async products(): Promise<Product[]> { // Custom logic return []; }}Query Features
Section intitulée « Query Features »Type GraphQL Query provides comprehensive query capabilities:
| Feature | Description | Documentation |
|---|---|---|
| 🔍 Filtering | Filter results by complex criteria | Filtering Guide |
| 📊 Sorting | Sort results by one or more fields | Sorting Guide |
| 📄 Paging | Paginate large result sets | Paging Guide |
| 🔗 Relations | Include related data | Relations Guide |
| 🔎 Search | Full-text search across searchable fields | Search Guide |
| 🎯 ContextFilter | Automatically apply filters based on context | ContextFilter Guide |
Quick Examples
Section intitulée « Quick Examples »Basic Query
Section intitulée « Basic Query »query { products { nodes { id name price } totalCount }}Filtered Query
Section intitulée « Filtered Query »query { products(filter: { price: { gte: 100, lte: 1000 }, status: { eq: "ACTIVE" } }) { nodes { id name price } }}Sorted and Paginated
Section intitulée « Sorted and Paginated »query { products(sorting: [{ field: price, direction: DESC }], paging: { limit: 20, offset: 0 }) { nodes { id name price } totalCount }}Quick Reference
Section intitulée « Quick Reference »| Topic | Documentation |
|---|---|
| 📍 Endpoints | Query Endpoints |
| 🔍 Filtering | Filtering Guide |
| 📄 Paging | Paging Guide |
| 📊 Sorting | Sorting Guide |
| 🔗 Relations | Relations Guide |
Next Steps
Section intitulée « Next Steps »Continue learning about queries:
- 📍 Endpoints - Available query endpoints
- 🔍 Filtering - Filter query results
- 📄 Paging - Paginate results
- 📊 Sorting - Sort query results
Related Topics
Section intitulée « Related Topics »- Type GraphQL Query Overview - Complete overview
- DTOs - Learn about DTO definitions
- Mutations - Data modification operations
- ContextFilter - Context-aware filtering