graphql_fragment_builder 1.1.0 copy "graphql_fragment_builder: ^1.1.0" to clipboard
graphql_fragment_builder: ^1.1.0 copied to clipboard

A small Dart builder for GraphQL selection sets, variables, and operation documents.

example/example.dart

import 'package:graphql_fragment_builder/graphql_fragment_builder.dart';

const bookFields = GraphQLFragmentDefinition(
  name: 'BookFields',
  typeCondition: 'Book',
  fields: ['id', 'title', 'publicationYear', 'genre'],
);

void main() {
  const query = GraphQLQueryBuilder(
    name: 'booksByAuthor',
    operationName: 'BooksByAuthor',
    parameters: [
      QueryParameter(
        'authorName',
        'Jane Austen',
        type: 'String',
        isRequired: true,
      ),
      QueryParameter(
        'bookLimit',
        5,
        argumentName: 'limit',
        type: 'Int',
      ),
    ],
    fragments: [
      FragmentSpread('BookFields'),
      QuerySelection(
        name: 'reviews',
        parameters: [
          QueryParameter(
            'reviewLimit',
            3,
            argumentName: 'limit',
            type: 'Int',
          ),
        ],
        fields: ['rating', 'body'],
      ),
    ],
    fragmentDefinitions: [bookFields],
  );

  print('Document:');
  print(query.buildDocument());
  print('\nVariables:');
  print('${query.variables}');
}
3
likes
160
points
112
downloads

Documentation

API reference

Publisher

verified publishergabrimatic.info

Weekly Downloads

A small Dart builder for GraphQL selection sets, variables, and operation documents.

Repository (GitHub)
View/report issues
Contributing

Topics

#graphql #graphql-fragments #query-builder #dart

License

MIT (license)

More

Packages that depend on graphql_fragment_builder