graphql-hive / graphql-hive/router

Use normalized representation for response data

Open
#200 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
103
Forks
23
Avg merge
1d 4h
Merged PRs (30d)
103

Description

Right now, our response handling logic relies on nested JSON-like structures (`serde_json::Value`) to represent data fetched from subgraphs. This approach is simple but becomes inefficient as query complexity and merging steps increase — especially with large arrays, deep nesting, and multiple subgraph fetches targeting the same entities. The `project_*` functions become slow and rely on `deep_merge` that is quite heavy.

I propose we introduce a normalized representation for response data - similar to Grafbase.

- Objects could be stored flat - `HashMap`
- Nested references are replaced with IDs

Each nested object will be stored once and referred to by ID. Lists are also flattened and stored by ID, so any part of the response tree can be patched in constant time.

Merging becomes shallow and index-based instead of recursive.

The assembling process of the `$representations` data will be cheaper (we avoid extracting data from a deeply nested structure).

The final response (sent to the gateway consumer) could rely on `Serialize` trait from `serde`, where we would assemble the full response from data pieces.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the project_* functions and deep_merge used by response handling, then trace how subgraph data and $representations are assembled. Review the existing serde_json::Value flow and response serialization boundaries. Done would require an agreed normalized representation, shallow merging, cheaper representation assembly, and final response reconstruction, but the issue does not identify files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, rust
Domain
api, backend-api-design, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.