On this page
Generated output
See how operation fields become Dart models, variables and documents.
Response models follow the selection
lib/graphql/viewer.graphql
query Viewer {
viewer {
login
}
}
This query generates Viewer$Query. Nested type names include the parent type path by default.
lib/main.dart
final data = Viewer$Query.fromJson(json);
print(data.viewer.login);
final roundTrip = data.toJson();
Response classes provide fromJson, toJson, and value equality through Equatable.
Nullability stays visible
- GraphQL non-null fields become required, non-null Dart fields.
- Nullable fields become nullable Dart fields.
- List nullability and item nullability are modeled independently.
- GraphQL non-null input values become required named constructor parameters.
schema.graphql
type Query {
names: [String!]!
nicknames: [String]
}
The generated shapes are equivalent to List<String> for names and List<String?>? for nicknames.
Aliases become Dart paths
The Pokémon big_query aliases a selected Pokémon as charmander:
big_query.query.graphql
charmander: pokemon(name: "Charmander") {
name
}
The response property follows the alias, so application code reads data.charmander. Aliases can also resolve generated-name collisions without changing the wire field selected from the server.
Arguments and constants
With generate_queries: true, the GitHub output includes:
SearchRepositoriesArgumentsfor variables;SEARCH_REPOSITORIES_QUERY_DOCUMENTfor the AST;SEARCH_REPOSITORIES_QUERY_DOCUMENT_OPERATION_NAMEfor operation selection.
lib/main.dart
final variables = SearchRepositoriesArguments(query: 'flutter');
final document = SEARCH_REPOSITORIES_QUERY_DOCUMENT;
The document is already a DocumentNode; do not wrap it with gql().
Optional wrappers
With helpers enabled, classes such as ViewerQuery extend GraphQLQuery. They bundle the document, operation name, variables and parser for the Dartpollo client.
lib/main.dart
final response = await client.execute(
SearchRepositoriesQuery(
variables: SearchRepositoriesArguments(query: 'flutter'),
),
);
Regenerate after changes
Edit your schema, operations or configuration, then rerun build_runner. It rewrites the .graphql.dart models and documents and the .graphql.g.dart serializers.
Continue with fragments and GraphQL features, or use the generated API reference for exact naming patterns.