gqlify_runtime 0.1.0
gqlify_runtime: ^0.1.0 copied to clipboard
Lightweight, pure-Dart runtime for code generated by gqlify: injectable transports, typed operation results and explicit GraphQL error semantics.
example/gqlify_runtime_example.dart
// The runtime is used by code generated by gqlify; this example shows the
// pieces applications touch directly: transports and responses.
import 'package:gqlify_runtime/gqlify_runtime.dart';
import 'package:gqlify_runtime/testing.dart';
/// A hand-written operation, equivalent to what gqlify generates.
final class HelloQuery extends GqlifyOperation<String> {
const HelloQuery();
@override
String get operationName => 'Hello';
@override
GqlifyOperationType get operationType => GqlifyOperationType.query;
@override
String get document => 'query Hello { hello }';
@override
Map<String, Object?> get variables => const {};
@override
String parseData(Map<String, Object?> data) => data['hello']! as String;
}
final class Client extends GqlifyClientBase {
Client({required super.transport});
}
Future<void> main() async {
// Swap MockTransport for HttpTransport(Uri.parse('https://...')) in apps.
final client = Client(
transport: MockTransport.fixed({
'data': {'hello': 'world'},
}),
);
final response = await client.execute(const HelloQuery());
print(response.dataOrThrow);
await client.close();
}