platform/graphql_schema/example/todo.dart
2018-08-02 15:22:16 -04:00

41 lines
850 B
Dart

import 'package:graphql_schema/graphql_schema.dart';
final GraphQLSchema todoSchema = new GraphQLSchema(
query: objectType('Todo', fields: [
field(
'text',
type: graphQLString.nonNullable(),
resolve: resolveToNull,
),
field(
'created_at',
type: graphQLDate,
resolve: resolveToNull,
),
]),
);
main() {
// Validation
var validation = todoSchema.query.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.query.serialize({
'text': 'Clean your room!',
'created_at': new DateTime.now().subtract(new Duration(days: 10))
}));
}