platform/graphql_server/test/query_test.dart

53 lines
1.1 KiB
Dart
Raw Normal View History

2018-08-02 15:17:14 +00:00
import 'package:graphql_schema/graphql_schema.dart';
import 'package:graphql_server/graphql_server.dart';
import 'package:test/test.dart';
void main() {
2018-08-02 17:02:00 +00:00
test('single element', () async {
2018-08-04 19:18:53 +00:00
var todoType = objectType('todo', fields: [
2018-08-02 17:02:00 +00:00
field(
'text',
2018-08-04 19:18:53 +00:00
graphQLString,
2018-08-02 17:02:00 +00:00
resolve: (obj, args) => obj.text,
),
field(
'completed',
2018-08-04 19:18:53 +00:00
graphQLBoolean,
2018-08-02 17:02:00 +00:00
resolve: (obj, args) => obj.completed,
),
]);
2018-08-02 15:17:14 +00:00
var schema = graphQLSchema(
2018-08-04 19:18:53 +00:00
queryType: objectType('api', fields: [
2018-08-02 15:17:14 +00:00
field(
2018-08-02 17:02:00 +00:00
'todos',
2018-08-05 01:49:13 +00:00
listOf(todoType),
2018-08-02 17:02:00 +00:00
resolve: (_, __) => [
2019-08-14 04:48:18 +00:00
Todo(
text: 'Clean your room!',
completed: false,
)
],
2018-08-02 15:17:14 +00:00
),
]),
);
2019-08-14 04:44:22 +00:00
var graphql = GraphQL(schema);
2018-08-02 17:02:00 +00:00
var result = await graphql.parseAndExecute('{ todos { text } }');
2018-08-02 15:17:14 +00:00
print(result);
2018-08-02 17:02:00 +00:00
expect(result, {
'todos': [
{'text': 'Clean your room!'}
]
});
2018-08-02 15:17:14 +00:00
});
}
class Todo {
final String text;
final bool completed;
Todo({this.text, this.completed});
}