platform/packages/graphql/graphql_schema/test/inheritance_test.dart

68 lines
1.6 KiB
Dart
Raw Permalink Normal View History

2018-08-05 01:32:20 +00:00
import 'package:graphql_schema/graphql_schema.dart';
import 'package:test/test.dart';
void main() {
group('interface', () {
var a = objectType(
'A',
isInterface: true,
fields: [
field('text', graphQLString.nonNullable()),
],
);
var b = objectType(
'B',
isInterface: true,
interfaces: [a],
fields: [
field('text', graphQLString.nonNullable()),
],
);
var c = objectType(
'C',
isInterface: true,
interfaces: [b],
fields: [
field('text', graphQLString.nonNullable()),
],
);
test('child implements parent', () {
expect(b.isImplementationOf(a), true);
expect(c.isImplementationOf(b), true);
});
test('parent does not implement child', () {
expect(a.isImplementationOf(b), false);
});
test('child interfaces contains parent', () {
expect(b.interfaces, contains(a));
expect(c.interfaces, contains(b));
});
test('parent possibleTypes contains child', () {
expect(a.possibleTypes, contains(b));
expect(b.possibleTypes, contains(c));
});
test('grandchild implements grandparent', () {
expect(c.isImplementationOf(a), true);
});
test('grandparent does not implement grandchild', () {
expect(a.isImplementationOf(c), false);
});
test('grandchild interfaces contains grandparent', () {
expect(c.interfaces, contains(a));
});
test('grandparent possibleTypes contains grandchild', () {
expect(a.possibleTypes, contains(c));
});
});
2019-03-29 18:45:02 +00:00
}