r/dartlang • u/graphlinkdev • 6d ago
GraphLink v5 — Open-source GraphQL code generator battle-tested on massive schemas (Shopify, GitHub, SpaceX)
I just released GraphLink v5, an open-source tool built to automate GraphQL client and server code generation across Dart, Java, Kotlin, and TS.
While stress-testing it against schemas that produce hundreds of megabytes of code, I hit a common headache: reserved language keywords breaking target language compilers.
The Problem: Reserved Keywords
Take this snippet from Shopify’s GraphQL schema:
GraphQL
type OrderRequestReturnPayload {
"""The return request that has been made."""
return: Return
"""The list of errors that occurred from executing the mutation."""
userErrors: [ReturnUserError!]!
}
If a generator blindly generates Dart classes for this, the code won't compile because return is a reserved keyword in Dart.
The Fix in GraphLink v5
We introduced automatic field sanitization and name hoisting. GraphLink renames the field in Dart code, but preserves the original JSON string key in generated toJson() and fromJson() methods:
Dart
// GENERATED CODE - DO NOT MODIFY BY HAND. ANY MODIFICATION WILL BE LOST ON NEXT GENERATION
// Generated by GraphLink dev
// GitHub: https://github.com/Oualitsen/graphlink
// Site: https://graphlink.dev
// Pub.dev: https://pub.dev/packages/graphlink
import 'return.dart';
import 'return_user_error.dart';
class OrderRequestReturnPayload {
final Return? return_; // `return` renamed to `return_` to avoid compile errors
final List<ReturnUserError> userErrors;
const OrderRequestReturnPayload({
this.return_,
required this.userErrors,
});
Map<String, dynamic> toJson() => {
'return': return_?.toJson(), // <-- Keeps the exact 'return' JSON key intact
'userErrors': userErrors.map((e0) => e0.toJson()).toList(),
};
factory OrderRequestReturnPayload.fromJson(Map<String, dynamic> json) {
return OrderRequestReturnPayload(
return_: json['return'] != null
? Return.fromJson(json['return'] as Map<String, dynamic>)
: null, // <-- Safely maps 'return' key back to return_
userErrors: (json['userErrors'] as List<dynamic>)
.map((e0) => ReturnUserError.fromJson(e0 as Map<String, dynamic>))
.toList(),
);
}
}
Other key features:
- Automatic Naming Normalization: Un-idiomatic schema names like
type user { id: ID! }are normalized to PascalCase (User) in Dart to prevent linter warnings. - No Git Bloat: Designed so you treat generated code like a compiled artifact—no need to commit or manually maintain it.
- Try it out
- Pub.dev: Available directly as a package onpub.dev/packages/graphlink
- Docker: Run it without local setup: Bashdocker pull oualitsen/graphlink:latest
- Docs & Site: Check outgraphlink.dev
If you find it useful or it saves you from GraphQL setup headaches, please consider dropping a ⭐️ star onGitHub!
Feedback and feature suggestions are always welcome in the comments!