Skip to main content
This document compares stash-graphql-client to alternative approaches and libraries to help you understand when and why to use it.

vs Raw GraphQL with gql

Side-by-Side Example

Raw gql approach:
stash-graphql-client approach:

Feature Comparison

When to Use Raw gql

✅ Use raw gql when:
  • Making a few simple queries
  • Need maximum control over GraphQL
  • Working with non-Stash GraphQL APIs
  • Building a custom abstraction layer
❌ Avoid raw gql when:
  • Building tools with complex entity relationships
  • Need type safety and validation
  • Making many queries for same entities
  • Want ORM-like convenience

vs Apollo Client (JavaScript)

Apollo Client is the most popular GraphQL client for JavaScript/TypeScript. Here’s how stash-graphql-client compares:

Architecture Comparison

Cache Implementation

Apollo Client:
stash-graphql-client:

Type Safety

Apollo with TypeScript:
stash-graphql-client:

When to Use Apollo vs stash-graphql-client

Use Apollo when:
  • Building web applications in JavaScript/TypeScript
  • Need React integration (React Query, hooks)
  • Working with any GraphQL API
  • Need optimistic UI updates
  • Want community plugins/extensions
Use stash-graphql-client when:
  • Building Python tools/scripts
  • Working specifically with Stash
  • Need runtime type validation
  • Want ORM-like entity management
  • Prefer identity map over normalized cache

vs SQLAlchemy

SQLAlchemy is Python’s most popular ORM for SQL databases. stash-graphql-client borrows patterns from SQLAlchemy but applies them to GraphQL.

Conceptual Mapping

Side-by-Side Example

SQLAlchemy:
stash-graphql-client:

Key Differences

Advantages of stash-graphql-client

Runtime type validation - Pydantic catches errors immediately ✅ UNSET pattern - Distinguish unqueried from null (SQL can’t do this) ✅ Async-first - Not retrofitted like SQLAlchemy’s async support ✅ No ORM impedance mismatch - GraphQL already returns objects

Advantages of SQLAlchemy

Transactions - ACID guarantees, rollback support ✅ Complex queries - Joins, subqueries, window functions ✅ Database portability - Works with any SQL database ✅ Mature ecosystem - 15+ years of development

vs Django ORM

Django ORM is built into the Django web framework but can be used standalone.

Filter Syntax Comparison

Django ORM:
stash-graphql-client:

Key Differences

When to Use Django ORM vs stash-graphql-client

Use Django ORM when:
  • Building Django web applications
  • Working with SQL databases
  • Need transactions and complex joins
  • Want admin interface for free
Use stash-graphql-client when:
  • Working specifically with Stash
  • Building Python tools/scripts (not web apps)
  • Want GraphQL flexibility
  • Need UNSET pattern for sparse updates

When to Use This Library

✅ Use stash-graphql-client when:

  1. Building tools that interact with Stash
    • Media organization scripts
    • Batch processing tools
    • Data migration utilities
    • Custom integrations
  2. You need type safety and validation
    • Catch errors at development time
    • IDE autocomplete for all fields
    • Runtime validation of server responses
  3. You want ORM-like convenience
    • .save() / .delete() methods
    • Relationship helpers
    • Change tracking for partial updates
  4. Working with complex entity relationships
    • Scenes with performers, studios, tags
    • Need bidirectional relationship sync
    • Want object identity across queries
  5. Making many queries for same entities
    • Identity map prevents duplicate objects
    • Read-through caching reduces network requests
    • Field-aware population loads only what’s needed

❌ Don’t use stash-graphql-client when:

  1. Just need a few simple queries
    • Use raw gql library directly
    • Simpler for one-off operations
  2. Not using Python
    • Use GraphQL client for your language
    • Apollo (JS), graphql-ruby (Ruby), etc.
  3. Need to work with multiple GraphQL APIs
    • This is specialized for Stash’s schema
    • Use general-purpose GraphQL client
  4. Memory constrained environment
    • Identity map keeps objects in memory
    • May not be suitable for very large datasets
  5. Need optimistic updates / offline support
    • Not built-in (would need manual implementation)
    • Apollo Client better for this use case

Migration Guide

From Raw gql

Before:
After:
Effort: Low - mostly replacing string queries with method calls

From Apollo Client (JS → Python)

Before (JavaScript):
After (Python):
Effort: Medium - language switch + learning Pydantic patterns

From SQLAlchemy

Before:
After:
Effort: Low - very similar patterns, main change is async

From Django ORM

Before:
After:
Effort: Low - filter syntax nearly identical

Summary

stash-graphql-client combines the best patterns from:
  • Apollo Client - GraphQL caching and query management
  • SQLAlchemy - Identity map and session pattern
  • Django ORM - Filter syntax and query building
  • Pydantic - Runtime type validation and models
It’s specifically designed for:
  • Python developers
  • Building tools that interact with Stash
  • Need type safety + ORM convenience + GraphQL flexibility
It’s NOT designed for:
  • General-purpose GraphQL APIs
  • Web applications (use Apollo + React)
  • Maximum control over every GraphQL query

Next Steps