data_loader 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 66

data_loader #

Pub build status

Batch and cache database lookups. Works well with GraphQL. Ported from the original JS version:

Installation #

In your pubspec.yaml:

  data_loader: ^1.0.0

Usage #

Complete example:

var userLoader = new DataLoader((key) => myBatchGetUsers(keys));
var invitedBy = await userLoader.load(1)then(user => userLoader.load(user.invitedByID))
print('User 1 was invited by $invitedBy'));

1.0.0 #

  • Initial version.


import 'dart:async';
import 'package:data_loader/data_loader.dart';
import 'package:graphql_schema/graphql_schema.dart';

external Future<List<Todo>> fetchTodos(Iterable<int> ids);

main() async {
  // Create a DataLoader. By default, it caches lookups.
  var todoLoader = DataLoader(fetchTodos); // DataLoader<int, Todo>

  // type Todo { id: Int, text: String, is_complete: Boolean }
  var todoType = objectType(
    fields: [
      field('id', graphQLInt),
      field('text', graphQLString),
      field('is_complete', graphQLBoolean),

  // type Query { todo($id: Int!) Todo }
  // ignore: unused_local_variable
  var schema = graphQLSchema(
    queryType: objectType(
      fields: [
          inputs: [GraphQLFieldInput('id', graphQLInt.nonNullable())],
          resolve: (_, args) => todoLoader.load(args['id'] as int),

  // Do something with your schema...

abstract class Todo {
  int get id;
  String get text;
  bool get isComplete;

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  data_loader: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:data_loader/data_loader.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.4


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
Dev dependencies
graphql_schema ^1.0.0
pedantic ^1.0.0
test >=0.12.0 <2.0.0