platform/graphql_server/example/main.dart

53 lines
1.1 KiB
Dart
Raw Normal View History

2018-10-23 16:07:49 +00:00
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: (_, __) => [
2019-08-14 04:44:22 +00:00
Todo(
2018-10-23 16:07:49 +00:00
text: 'Clean your room!',
completed: false,
)
],
),
]),
);
2019-08-14 04:44:22 +00:00
var graphql = GraphQL(schema);
2018-10-23 16:07:49 +00:00
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});
}