DatasourceGenerator class

Generates fully implemented remote datasource classes.

Creates a datasource with query, mutation, and subscription methods using package:graphql client. Union-returning operations are handled through UnionResultHandler when an errorConfig is provided.

final gen = DatasourceGenerator(typeMapper: mapper);
final code = gen.generate(
  name: 'Product',
  queries: [QueryConfig(fieldName: 'product', ...)],
  mutations: [],
);

Constructors

DatasourceGenerator({required TypeMapper typeMapper, bool enableSubscriptions = false, ErrorMappingConfig? errorConfig, String documentsImportPath = 'graphql/documents.dart'})

Properties

documentsImportPath String
Path to the generated documents.dart file holding parsed DocumentNode constants. Generated datasources import this instead of inlining gql(r'''...''') strings.
final
enableSubscriptions bool
Whether to generate subscription/watch methods backed by the GraphQLClientSubscription runtime (requires subscriptions: true and a wsEndpoint in .zfa.json). When false, watch methods are generated as stubs that report subscriptions are disabled.
final
errorConfig ErrorMappingConfig?
Optional error mapping table for union-returning operations. When set, union results are dispatched on __typename and error variants are mapped to AppFailure via the generated _mapError helper.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
typeMapper TypeMapper
final

Methods

generate({required String name, required List<QueryConfig> queries, required List<MutationConfig> mutations, List<SubscriptionConfig> subscriptions = const [], List<SubscriptionConfig> watches = const []}) String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited