2018-08-02 13:31:54 +00:00
|
|
|
import 'package:graphql_schema/graphql_schema.dart';
|
|
|
|
|
|
|
|
final GraphQLSchema todoSchema = new GraphQLSchema(
|
2018-08-02 14:16:46 +00:00
|
|
|
query: objectType('Todo', [
|
|
|
|
field(
|
|
|
|
'text',
|
|
|
|
innerType: graphQLString.nonNullable(),
|
|
|
|
),
|
|
|
|
field('created_at', innerType: graphQLDate),
|
|
|
|
]),
|
|
|
|
);
|
2018-08-02 13:31:54 +00:00
|
|
|
|
|
|
|
main() {
|
|
|
|
// Validation
|
2018-08-02 14:16:46 +00:00
|
|
|
var validation = todoSchema.query.validate(
|
|
|
|
'@root',
|
|
|
|
{'foo': 'bar', 'text': null, 'created_at': 24,},
|
|
|
|
);
|
2018-08-02 13:31:54 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}));
|
|
|
|
}
|