Skip to content
pubscout

normalize

0.10.0, released 2 years ago by gql-dart.dev

Normalizes and denormalizes GraphQL responses to a cache-friendly map structure.

WASM-readyQuiet but busy
$ flutter pub add normalize
Source repository

What it does

It traverses GraphQL AST and writes entities with __typename and IDs into a normalized map. It can also reconstruct the original response from that map.

AI-written summary of version 0.10.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need client‑side caching for GraphQL queries
  • You want to work with normalized data like Apollo cache
  • You need to convert GraphQL responses to a reference‑based structure for efficient updates

Skip it when

  • You are not using GraphQL
  • You require built‑in network transport (use a GraphQL client instead)

Strengths

  • Works with gql AST directly
  • Supports fragments, variables, interfaces, unions, and type policies
  • Lightweight and pure Dart

Weaknesses

  • Only handles normalization, not fetching or cache eviction
  • Limited support for custom key fields (no functions or nested lists)
  • No built‑in reactive or stream integration

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
2
import 'package:gql/language.dart';
import 'package:gql/ast.dart';
import 'package:normalize/normalize.dart';

final DocumentNode query = parseString('''
  query TestQuery {
    posts { id __typename author { id __typename name } title }
  }
''');

final data = {"posts":[{"id":"123","__typename":"Post","author":{"id":"1","__typename":"Author","name":"Paul"},"title":"My post"}]};

final normalized = {};
normalizeOperation(
  merge:(dataId,value)=> (normalized[dataId]??={}).addAll(value),
  document:query,
  data:data,
);
print(normalized);

Works with

Packages commonly used together with normalize: ones it builds on, ones built on it, and its own family.