Skip to content

Performance: Add query optimization features (fragments, batching, field selection) #37

@knowlen

Description

@knowlen

Description

As identified in PR #32 review, the centralized GraphQL queries in queries.py could benefit from optimization features to reduce payload size and improve performance.

Current State

  • All queries are static and fetch all available fields
  • No support for query batching
  • No ability to select specific fields

Proposed Solutions

1. Query Fragments

Define reusable fragments for common field sets:

fragment CharacterBasic on Character {
  id
  name
  server { name slug }
}

fragment CharacterDetailed on Character {
  ...CharacterBasic
  lodestoneID
  canonicalID
  hidden
}

2. Field Selection

Allow users to specify which fields to include:

# Only get name and server
character = await client.get_character_by_id(
    id=12345,
    fields=['name', 'server.name']
)

3. Query Batching

Support multiple operations in a single request:

# Batch multiple character lookups
results = await client.batch_query([
    client.prepare_query('get_character_by_id', id=12345),
    client.prepare_query('get_character_by_id', id=67890),
])

Implementation Notes

  • Maintain backward compatibility (default to full queries)
  • Consider using graphql-core for dynamic query building
  • Cache commonly used query variations
  • Ensure type safety is maintained

Benefits

  • Reduced network payload
  • Improved response times
  • Lower API usage for rate-limited accounts
  • More efficient for mobile/limited bandwidth scenarios

Challenges

  • Dynamic query generation complexity
  • Type safety with partial responses
  • Documentation of available fields

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions