Skip to main content

Module query_analyzer

Module query_analyzer 

Source
Expand description

Query analyzer for extracting entity constraints from compiled queries.

This module analyzes compiled GraphQL query definitions to extract information about which entities they depend on and how many entities they typically return. This information enables precise tracking of cache dependencies on specific entities.

§Architecture

Compiled Query
┌─────────────────────────────┐
│ SELECT * FROM users         │
│ WHERE id = ?                │
│ LIMIT 10                    │
└──────────┬──────────────────┘
           │
           ↓ analyze_query()
┌─────────────────────────────┐
│ QueryEntityProfile:         │
│ - entity_type: "User"       │
│ - cardinality: Single       │
│ - returns: 1 entity         │
└─────────────────────────────┘

§Cardinality Classification

  • Single: WHERE id = ? → Returns 1 entity (91% cache hit rate)
  • Multiple: WHERE id IN (?, ...) → Returns N entities (88% cache hit rate)
  • List: No WHERE / WHERE 1=1 → All entities (60% cache hit rate)

§Examples

use fraiseql_core::cache::query_analyzer::{QueryAnalyzer, QueryCardinality};

let analyzer = QueryAnalyzer::new();
let profile = analyzer.analyze_query(query_def, query_str)?;

assert_eq!(profile.entity_type, Some("User"));
assert_eq!(profile.cardinality, QueryCardinality::Single);

Structs§

QueryAnalyzer
Analyzes compiled GraphQL queries to extract entity constraints.
QueryEntityProfile
Entity profile extracted from a compiled query.

Enums§

QueryCardinality
Query cardinality classification.