galileo_data_loader 3.0.0 copy "galileo_data_loader: ^3.0.0" to clipboard
galileo_data_loader: ^3.0.0 copied to clipboard

Batch and cache database lookups. Works well with GraphQL. Ported from JS.

example/main.dart

import 'dart:async';
import 'package:galileo_data_loader/galileo_data_loader.dart';
import 'package:galileo_graphql_schema/galileo_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(
    'Todo',
    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(
      'Query',
      fields: [
        field(
          'todo',
          listOf(todoType),
          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;
}
1
likes
40
points
18
downloads

Publisher

verified publishergalileodart.com

Weekly Downloads

Batch and cache database lookups. Works well with GraphQL. Ported from JS.

Repository (GitHub)

License

MIT (license)

More

Packages that depend on galileo_data_loader