platform/packages/graphql/graphql_server/test/query_test.dart
Tobe O 4e69153e3e Add 'packages/graphql/' from commit '33e2f86ba73d559197b6270df036256104726aca'
git-subtree-dir: packages/graphql
git-subtree-mainline: ac29392d7f
git-subtree-split: 33e2f86ba7
2020-02-15 18:22:07 -05:00

52 lines
1.1 KiB
Dart

import 'package:graphql_schema/graphql_schema.dart';
import 'package:graphql_server/graphql_server.dart';
import 'package:test/test.dart';
void main() {
test('single element', () async {
var todoType = objectType('todo', fields: [
field(
'text',
graphQLString,
resolve: (obj, args) => obj.text,
),
field(
'completed',
graphQLBoolean,
resolve: (obj, args) => obj.completed,
),
]);
var schema = graphQLSchema(
queryType: objectType('api', fields: [
field(
'todos',
listOf(todoType),
resolve: (_, __) => [
Todo(
text: 'Clean your room!',
completed: false,
)
],
),
]),
);
var graphql = GraphQL(schema);
var result = await graphql.parseAndExecute('{ todos { text } }');
print(result);
expect(result, {
'todos': [
{'text': 'Clean your room!'}
]
});
});
}
class Todo {
final String text;
final bool completed;
Todo({this.text, this.completed});
}