graphql_gen 0.1.0
graphql_gen: ^0.1.0 copied to clipboard
Type-safe GraphQL query building for Dart with generated field enums. Build selections in Dart instead of writing .graphql documents.
example/graphql_gen_example.dart
import 'package:graphql_gen/graphql_gen.dart';
/// Builds a query by hand. In a real project the field names come from the
/// enums generated by `graphql_gen_generator`, e.g. `BookFields.values`.
void main() {
final query = GraphQLQueryBuilder(name: 'Books')
.withOperation(
operationName: 'books',
arguments: GraphQLArgumentBuilder()
.withArgument('first', 10)
.withArgument('genre', const GraphQLEnumValue('FICTION')),
fields: GraphQLFieldBuilder()
.withFields(['id', 'title'])
.withField(
'author',
nestedField: GraphQLFieldBuilder().withFields(['id', 'name']),
),
)
.build();
print(query);
}