Dartpollo0.1.0-alpha.6
Documentation

Prerelease · 0.1.0-alpha.6 · Dart ^3.10.0

Generate the types.
Choose the client.

dartpollo_generator turns local schema and operation files into typed Dart models and GraphQL documents. Use the generated code with your GraphQL client or the optional dartpollo runtime.

Packages

dartpollo_generator generates models and documents through build_runner. json_serializable adds their JSON serializers.

dartpollo provides an optional HTTP client and cache. Both packages use the shared types in dartpollo_annotation.

Trace one operation

  1. Map local files. build.yaml associates an SDL schema with lib/graphql/viewer.graphql.
  2. Run the build. dart run build_runner build invokes Dartpollo Generator and json_serializable.
  3. Inspect the output. lib/__generated__/viewer.graphql.dart contains Viewer$Query and VIEWER_QUERY_DOCUMENT; the paired .g.dart contains serializers.
  4. Execute through your client. Pass the document to package:graphql, or execute the generated ViewerQuery with the optional Dartpollo client.
lib/graphql/viewer.graphql
query Viewer {
  viewer {
    login
  }
}
lib/main.dart
final data = Viewer$Query.fromJson(result.data!);
print(data.viewer.login);

Read response fields through typed Dart properties such as data.viewer.login.

Choose what to generate

Models only

helpers: false · queries: false

Generate response and input types while another tool owns the request document.

Models and documents

helpers: false · queries: true

Use the generated AST, operation name, variables, and parser with package:graphql or another compatible client.

Dartpollo helpers

helpers: true

Generate a GraphQLQuery wrapper for DartpolloClient and DartpolloCachedClient.

Continue from here

Getting startedGenerate models and run your first example.Mental modelSee how schemas and operations become typed Dart code.package:graphqlExecute generated documents with typed QueryOptions.Generator referenceLook up configuration options and defaults.