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

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

example/example.dart

import 'package:graphql_schema2/graphql_schema2.dart';

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

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

  if (validation.successful) {
    print('This is valid data!!!');
  } else {
    print('Invalid data.');
    validation.errors.forEach((s) => print('  * $s'));
  }

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

Publisher

verified publisherdukefirehawk.com

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

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection, meta, source_span

More

Packages that depend on graphql_schema2