graphlink 5.0.0 copy "graphlink: ^5.0.0" to clipboard
graphlink: ^5.0.0 copied to clipboard

GraphLink is a powerful code generation tool that generates type-safe client and server code from GraphQL schemas for Dart, Java, Spring Boot and more.

GraphLink

GraphLink #

Write your GraphQL schema once. Get fully typed Dart/Flutter code — queries, mutations, subscriptions, UI input widgets — generated in milliseconds. No boilerplate. No drift.

pub.dev License: MIT GitHub Releases


What you get #

Define a GraphQL schema and GraphLink generates:

  • Fully typed query, mutation, and subscription methods — no casting, no generics
  • JSON serialization — ready to use, nothing to wire up
  • Schema-driven cache control — declare TTL and invalidation in the schema, the generated client handles the rest
  • Flutter UI input widgets — generated directly from your input types
  • Zero runtime dependency — delete GraphLink tomorrow, everything still compiles

Installation #

The CLI compiles to a native binary. No Dart VM overhead — regenerates in milliseconds even on large schemas.

# macOS (ARM)
curl -fsSL https://github.com/Oualitsen/graphlink/releases/latest/download/glink-macos-arm64 -o glink
chmod +x glink && sudo mv glink /usr/local/bin/glink

# macOS (x64)
curl -fsSL https://github.com/Oualitsen/graphlink/releases/latest/download/glink-macos-x64 -o glink
chmod +x glink && sudo mv glink /usr/local/bin/glink

# Linux (x64)
curl -fsSL https://github.com/Oualitsen/graphlink/releases/latest/download/glink-linux-x64 -o glink
chmod +x glink && sudo mv glink /usr/local/bin/glink

All releases — also glink-linux-arm64, glink-windows-x64.exe

Alternative — Dart / Flutter package #

flutter pub add --dev graphlink
# or
dart pub add --dev graphlink

Quick Start #

1. Write your schema #

type Vehicle {
  id: ID!
  brand: String!
  model: String!
  year: Int!
  fuelType: FuelType!
}

enum FuelType { GASOLINE DIESEL ELECTRIC HYBRID }

input AddVehicleInput {
  brand: String!
  model: String!
  year: Int!
  fuelType: FuelType!
}

type Query {
  getVehicle(id: ID!): Vehicle!
  listVehicles: [Vehicle!]!
}

type Mutation {
  addVehicle(input: AddVehicleInput!): Vehicle!
}

2. Configure #

glink.json in your project root:

{
  "schemaPaths": ["schema/*.graphql"],
  "mode": "client",
  "typeMappings": { "ID": "String", "Float": "double", "Int": "int", "Boolean": "bool" },
  "outputDir": "lib/generated",
  "clientConfig": {
    "dart": {
      "packageName": "my_app"
    }
  }
}

3. Generate #

glink              # auto-discovers glink.json / glink.yaml / glink.yml
glink -w           # watch mode — regenerate on every save

4. Use it #

final client = GraphLinkClient.withHttp(
  url: 'http://localhost:8080/graphql',
  wsUrl: 'ws://localhost:8080/graphql',
  tokenProvider: () async => await getAuthToken(),
);

// Query — fully typed, no casting
final res = await client.queries.getVehicle(id: '42');
print(res.getVehicle.brand);    // Toyota
print(res.getVehicle.fuelType); // FuelType.GASOLINE

// Mutation
await client.mutations.addVehicle(
  input: AddVehicleInput(brand: 'Toyota', model: 'Camry', year: 2023, fuelType: FuelType.GASOLINE),
);

// Subscription
client.subscriptions.vehicleAdded().listen((e) => print(e.vehicleAdded.brand));

Schema-driven caching #

Cache control lives in your schema — not scattered through your application code. Declare it once, the generated client handles TTL, tag-based invalidation, and offline fallback automatically.

type Query {
  # Cache for 2 minutes, tagged "vehicles"
  getVehicle(id: ID!): Vehicle!      @glCache(ttl: "2m", tags: ["vehicles"])

  # Serve stale data when offline instead of throwing
  getUserProfile(id: ID!): UserProfile  @glCache(ttl: "1m", staleIfOffline: true)
}

type Mutation {
  # Automatically evicts all "vehicles" cache entries on success
  addVehicle(input: AddVehicleInput!): Vehicle!  @glCacheInvalidate(tags: ["vehicles"])

  # Wipe everything
  resetData: Boolean!  @glCacheInvalidate(all: true)
}

No cache code to write. Cache entries are keyed by operation name + variables — each unique argument combination is cached independently. Bring your own persistent store by implementing GraphLinkCacheStore.


Flutter UI widgets #

GraphLink generates ready-to-use InputFormWidget classes directly from your input types. Drop them into any Flutter form — validation, state management, and serialization included.

AddVehicleInputFormWidget(
  onChanged: (value) => setState(() => _input = value),
)

Subscriptions #

client.subscriptions.vehicleAdded().listen((event) {
  print(event.vehicleAdded.brand);
});

Reconnection, error handling, and typed payloads are all generated.


Multi-language support #

GraphLink also generates Java, Kotlin, and TypeScript clients, plus Spring Boot and Express/Apollo server code, from the same schema. See the full documentation on GitHub for setup and examples.


Documentation #

Full documentation at graphlink.dev


License #

MIT — see LICENSE.

Issues and contributions welcome at github.com/Oualitsen/graphlink.

1
likes
140
points
155
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

GraphLink is a powerful code generation tool that generates type-safe client and server code from GraphQL schemas for Dart, Java, Spring Boot and more.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

args, build, glob, logger, source_gen, yaml

More

Packages that depend on graphlink