Skip to content

Using GraphLink with AI Agents

AI coding assistants work best when they understand how your project is structured. Without instructions, an agent seeing a generated/ directory full of Dart or Java files will waste time reading, editing, or recreating code that GraphLink owns. The setups below cover Dart, Java, TypeScript, Kotlin, Swift, Python, Go, Spring Boot and Express.

This page provides ready-to-use instruction files for common setups. Copy the one that matches your project and paste it into your agent's instruction file.

Agent Instruction file
Claude Code CLAUDE.md at project root
Gemini CLI GEMINI.md or .gemini/instructions.md
GitHub Copilot .github/copilot-instructions.md
Cursor .cursor/rules
Any agent AGENTS.md at project root (read by most tools)

Dart / Flutter project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Dart/Flutter code from a GraphQL schema.

- **Schema**: `lib/**/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` (or `glink.yaml`) at the project root
- **Generated files**: `lib/generated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json
# or with watch mode:
glink -c glink.json -w

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside lib/generated/ — they will be overwritten.
  • The generated GraphLinkClient is the entry point for all queries, mutations, and subscriptions.
  • Input classes live in lib/generated/inputs/. Type classes live in lib/generated/types/.
  • Enums are in lib/generated/enums/ and are already serialized — use them directly.

Caching

Cache behaviour is declared in the schema via @glCache and @glCacheInvalidate directives. Do not implement caching in application code — add or modify the directive in the schema instead. ```


Java client project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Java client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` at the project root
- **Generated files**: `src/main/java/com/example/generated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside the generated/ package.
  • GraphLinkClient is the entry point. Queries are on client.queries, mutations on client.mutations.
  • Return types are fully resolved — no TypeReference, no casting needed at the call site.
  • Input classes use a builder pattern: AddVehicleInput.builder().brand("Toyota").build(). ```

TypeScript project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
TypeScript client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` at the project root
- **Generated files**: `src/generated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside src/generated/.
  • Import GraphLinkClient from src/generated/client/graph-link-client.
  • All queries and mutations are typed methods — no manual type assertions needed.
  • Subscriptions are on client.subscriptions: callback-based (onData/onError/onComplete) by default, or Observable<T> when observables: true is set in the TypeScript config. ```

Kotlin client project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Kotlin client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` (or `glink.yaml`) at the project root
- **Generated files**: `src/main/kotlin/com/example/generated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json
# or with watch mode:
glink -c glink.json -w

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside the generated/ package — they will be overwritten on next run.
  • GraphLinkClient is the entry point. Queries are on client.queries, mutations on client.mutations, subscriptions on client.subscriptions.
  • All query and mutation methods are suspend functions — call them from a coroutine or runBlocking.
  • Subscription methods return a Flow<T> — collect them inside a coroutine scope.
  • Generated types and inputs are data class by default — construct them directly, no builder needed.
  • Nullable input fields have = null defaults — only pass the fields you need.
  • Enums are in generated/enums/ with toJson() / fromJson() — use them directly, do not re-serialize.

Caching

Cache behaviour is declared in the schema via @glCache and @glCacheInvalidate directives. Do not implement caching in application code — add or modify the directive in the schema instead. ```


Swift client project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Swift client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` (or `glink.yaml`) at the project root
- **Generated files**: `Sources/GraphLinkGenerated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json
# or with watch mode:
glink -c glink.json -w

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside Sources/GraphLinkGenerated/ — they will be overwritten on next run.
  • GraphLinkClient is the entry point. Queries are on client.queries, mutations on client.mutations, subscriptions on client.subscriptions.
  • All query, mutation, and subscription methods are async throws — call them from an async context.
  • Subscription methods return an AsyncThrowingStream<T, Error> — iterate with for try await.
  • Generated types and inputs are Sendable structs with a memberwise init — construct them directly, no builder needed.
  • Nullable input fields default to nil in init — only pass the fields you need.
  • Enums and types are in Enums/ and Types/ with toJson() / fromJson() — use them directly, do not re-serialize.

Caching

Cache behaviour is declared in the schema via @glCache and @glCacheInvalidate directives. Do not implement caching in application code — add or modify the directive in the schema instead. ```


Python client project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Python client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` (or `glink.yaml`) at the project root
- **Generated files**: `myapp/graphql/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json
# or with watch mode:
glink -c glink.json -w

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside myapp/graphql/ — they will be overwritten on next run.
  • GraphLinkClient is the entry point. Queries are on client.queries, mutations on client.mutations, subscriptions on client.subscriptions.
  • All operation methods are async — call them with await from a coroutine.
  • Operation arguments are keyword-only and named in snake_case (client.queries.get_user(id="1")).
  • Subscriptions return an AsyncIterator — iterate with async for.
  • Generated types and inputs are pydantic v2 models with to_json() / from_json() — use them directly, do not re-serialize.

Caching

Cache behaviour is declared in the schema via @glCache and @glCacheInvalidate directives. Do not implement caching in application code — add or modify the directive in the schema instead. ```


Go client project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Go client code from a GraphQL schema.

- **Schema**: `schema/*.graphql` (or wherever your .graphql files are)
- **Config**: `glink.json` (or `glink.yaml`) at the project root
- **Generated files**: `internal/graphql/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json
# or with watch mode:
glink -c glink.json -w

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside internal/graphql/ — they will be overwritten on next run.
  • Everything is one flat Go package. GraphLinkClient is the entry point: client.Queries, client.Mutations, client.Subscriptions.
  • Every operation takes a context.Context first and returns (value, error).
  • Required arguments are positional; optional and defaulted arguments go in the trailing <Operation>Options struct.
  • Subscriptions return channels of GraphLinkEvent[T].
  • Inputs with schema defaults have a New<Input>() constructor — use it instead of a zero-value literal.
  • Run gofmt -w on the output directory if you commit it; generated files are not formatted.

Caching

Cache behaviour is declared in the schema via @glCache and @glCacheInvalidate directives. Do not implement caching in application code — add or modify the directive in the schema instead. ```


Spring Boot server project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
Spring Boot server code from a GraphQL schema.

- **Schema**: `src/main/resources/graphql/*.graphqls`
- **Config**: `glink.json` at the project root
- **Generated files**: `src/main/java/com/example/generated/` — DO NOT edit these manually

To regenerate after any schema change:
```bash
glink -c glink.json

Rules

  • To add a field, type, query, or mutation: edit the .graphqls schema file, then run glink.
  • Never edit files inside the generated/ package — controllers, inputs, and types are all generated.
  • Implement the generated service interfaces (e.g. VehicleService) — do not modify the controllers.
  • Subscription resolvers must return reactor.core.publisher.Flux<T>.
  • Generated repositories are stubs — fill in the persistence logic, but do not change the interface signature. ```

Express / Apollo server project

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate
an Express + Apollo Server scaffold (TypeScript) from a GraphQL schema.

- **Schema**: `schema/*.graphql`
- **Config**: `glink.json` at the project root (`mode: server`, `serverConfig.expressApollo`)
- **Generated files**: `src/generated/` — DO NOT edit these manually
- **Your code**: `src/impl/` (service implementations) and `src/start.ts`

To regenerate after any schema change:
```bash
glink -c glink.json

Rules

  • To add a field, type, query, or mutation: edit the .graphql schema file, then run glink.
  • Never edit files inside src/generated/ — resolvers, types, inputs, and index.ts are all generated.
  • Implement the generated service interfaces (e.g. ArticleService) in src/impl/ — do not modify the resolvers.
  • Queries and mutations return Promise<T>; subscriptions return AsyncIterable<T>.
  • Start the server with the generated createServer({ ...services }); per-request context goes through contextFactory.
  • Batch-mapped fields (@glSkipOnServer(batch: true)) use generated DataLoaders — do not hand-roll N+1 lookups.
  • If the schema uses @glIntercept, pass an interceptor implementation in the services object. ```

REST operations and persisted queries (all clients)

### REST operations
Fields of `Query` and `Mutation` annotated with `@glRest(path: "...", method: ...)` are served over HTTP/JSON
by the same generated client, with the same call syntax as GraphQL operations. Do not hand-write HTTP calls for
them. Argument roles are declared in the schema (`@glRestPath`, `@glRestParam`, `@glRestHeader`, `@glRestBody`,
`@glRestField`, `@glRestPart`). To move a field to GraphQL, remove the directive.

### Directives
Every directive in the schema must be built in or declared with `directive @name ... on ...`.
Run `glink --print-directives` to print the declarations of GraphLink's own directives.

### Persisted queries
Enabled per client with `persistedQueries: "apq"` in the config; do not implement hashing in application code.

Full-stack project (Flutter + Spring Boot)

## Code generation — GraphLink

This project uses [GraphLink](https://graphlink.dev) (`glink`) to generate code
from a single GraphQL schema for both the Flutter client and the Spring Boot backend.

### Schema
One schema file drives both ends: `schema/schema.graphql`

### Client (Flutter)
- **Config**: `client/glink.json`
- **Generated files**: `client/lib/generated/` — DO NOT edit

### Server (Spring Boot)
- **Config**: `server/glink.json`
- **Generated files**: `server/src/main/java/com/example/generated/` — DO NOT edit

To regenerate both after a schema change:
```bash
glink -c client/glink.json
glink -c server/glink.json

Rules

  • All data model changes go in schema/schema.graphql first — then regenerate.
  • On the server, implement the generated service interfaces. Never edit generated controllers.
  • On the client, use GraphLinkClient — never write raw HTTP or WebSocket calls for GraphQL.
  • Cache behaviour is declared in the schema via @glCache / @glCacheInvalidate. Do not implement caching in application code. ```

Watch mode during development

Run glink -c glink.json -w in a terminal while your AI agent edits the schema. Every schema save triggers instant regeneration — the agent's next read of the generated files will already reflect the change.

The generated code is yours

GraphLink has zero runtime dependency. If you stop using it, every generated file continues to compile and work. Commit the generated files to version control — they are source of truth for what your schema produces.