Aller au contenu

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.

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

Queries are read-only operations that return data. Type GraphQL Query automatically generates queries for all DTOs, providing powerful capabilities out of the box.

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: {...})

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 [];
}
}

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
query {
products {
nodes {
id
name
price
}
totalCount
}
}
query {
products(filter: { price: { gte: 100, lte: 1000 }, status: { eq: "ACTIVE" } }) {
nodes {
id
name
price
}
}
}
query {
products(sorting: [{ field: price, direction: DESC }], paging: { limit: 20, offset: 0 }) {
nodes {
id
name
price
}
totalCount
}
}
Topic Documentation
📍 Endpoints Query Endpoints
🔍 Filtering Filtering Guide
📄 Paging Paging Guide
📊 Sorting Sorting Guide
🔗 Relations Relations Guide

Continue learning about queries:

  1. 📍 Endpoints - Available query endpoints
  2. 🔍 Filtering - Filter query results
  3. 📄 Paging - Paginate results
  4. 📊 Sorting - Sort query results