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-02 19:22:16 +00:00
|
|
|
var todoType = objectType('todo',fields: [
|
2018-08-02 17:02:00 +00:00
|
|
|
field(
|
|
|
|
'text',
|
|
|
|
type: graphQLString,
|
|
|
|
resolve: (obj, args) => obj.text,
|
|
|
|
),
|
|
|
|
field(
|
|
|
|
'completed',
|
|
|
|
type: graphQLBoolean,
|
|
|
|
resolve: (obj, args) => obj.completed,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
2018-08-02 15:17:14 +00:00
|
|
|
var schema = graphQLSchema(
|
2018-08-02 19:22:16 +00:00
|
|
|
query: objectType('api', fields:[
|
2018-08-02 15:17:14 +00:00
|
|
|
field(
|
2018-08-02 17:02:00 +00:00
|
|
|
'todos',
|
|
|
|
type: listType(todoType),
|
|
|
|
resolve: (_, __) => [
|
|
|
|
new Todo(
|
|
|
|
text: 'Clean your room!',
|
|
|
|
completed: false,
|
|
|
|
)
|
|
|
|
],
|
2018-08-02 15:17:14 +00:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
var graphql = new 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});
|
|
|
|
}
|