Skip to main content

graphql_gen 0.1.1 copy "graphql_gen: ^0.1.1" to clipboard
graphql_gen: ^0.1.1 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);
}
1
likes
160
points
1.07k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Type-safe GraphQL query building for Dart with generated field enums. Build selections in Dart instead of writing .graphql documents.

Repository (GitHub)
View/report issues

Topics

#graphql #codegen #freezed #query-builder

License

MIT (license)

More

Packages that depend on graphql_gen