leto_schema 0.0.1-dev.6 copy "leto_schema: ^0.0.1-dev.6" to clipboard
leto_schema: ^0.0.1-dev.6 copied to clipboard

An implementation of GraphQL's type system in Dart. Basis of leto.

example/example.dart

// ignore_for_file: avoid_print

import 'package:leto_schema/leto_schema.dart';

final GraphQLSchema todoSchema = GraphQLSchema(
  queryType: objectType('Todo', fields: [
    field(
      'text',
      graphQLString.nonNull(),
      resolve: resolveToNull,
    ),
    field(
      'created_at',
      graphQLDate,
      resolve: resolveToNull,
    ),
  ]),
);

/// A default resolver that always returns `null`.
Object? resolveToNull(Object? _, Object? __) => null;

void main() {
  // Validation
  final validation = todoSchema.queryType!.validate(
    '@root',
    {
      'foo': 'bar',
      'text': null,
      'created_at': 24,
    },
  );

  if (validation.successful) {
    print('This is valid data!!!');
  } else {
    print('Invalid data.');
    for (final s in validation.errors) {
      print('  * $s');
    }
  }

  // Serialization
  print(todoSchema.queryType!.serialize({
    'text': 'Clean your room!',
    'created_at': DateTime.now().subtract(const Duration(days: 10))
  }));
}
0
likes
140
pub points
46%
popularity

Publisher

unverified uploader

An implementation of GraphQL's type system in Dart. Basis of leto.

Repository (GitHub)
View/report issues

Topics

#graphql #protocol #schema #language #specification

Documentation

API reference

License

MIT (license)

Dependencies

collection, gql, meta, source_span

More

Packages that depend on leto_schema