graphql_schema2 6.1.0 copy "graphql_schema2: ^6.1.0" to clipboard
graphql_schema2: ^6.1.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.');
    for (var s in validation.errors) {
      print('  * $s');
    }
  }

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

Publisher

verified publisherdukefirehawk.com

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

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection, meta, quiver, source_span

More

Packages that depend on graphql_schema2