diff --git a/graphql_schema/lib/src/gen.dart b/graphql_schema/lib/src/gen.dart index 31d6a5c3..792b859d 100644 --- a/graphql_schema/lib/src/gen.dart +++ b/graphql_schema/lib/src/gen.dart @@ -1,8 +1,12 @@ part of graphql_schema.src.schema; GraphQLObjectType objectType(String name, - {String description, Iterable fields = const []}) => - new GraphQLObjectType(name, description)..fields.addAll(fields ?? []); + {String description, + Iterable fields = const [], + Iterable interfaces = const []}) => + new GraphQLObjectType(name, description) + ..fields.addAll(fields ?? []) + ..interfaces.addAll(interfaces ?? []); GraphQLField field(String name, {Iterable> arguments: const [], diff --git a/graphql_schema/lib/src/object_type.dart b/graphql_schema/lib/src/object_type.dart index 264f5521..705c322c 100644 --- a/graphql_schema/lib/src/object_type.dart +++ b/graphql_schema/lib/src/object_type.dart @@ -7,6 +7,9 @@ class GraphQLObjectType final String description; final List fields = []; + /// A list of other types that this object type is known to implement. + final List interfaces = []; + GraphQLObjectType(this.name, this.description); @override diff --git a/graphql_server/lib/introspection.dart b/graphql_server/lib/introspection.dart index 9901905e..a1254825 100644 --- a/graphql_server/lib/introspection.dart +++ b/graphql_server/lib/introspection.dart @@ -38,6 +38,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List allTypes) { _reflectFields(), _reflectDirectiveType(), _reflectInputValueType(), + _reflectEnumValueType(), ]); var fields = [ @@ -87,6 +88,31 @@ GraphQLObjectType _reflectSchemaTypes() { ), ); + _typeType.fields.add( + field( + 'interfaces', + type: listType(_reflectSchemaTypes().nonNullable()), + resolve: (type, _) { + if (type is GraphQLObjectType) { + return type.interfaces; + } else { + return []; + } + }, + ), + ); + + _typeType.fields.add( + field( + 'possibleTypes', + type: listType(_reflectSchemaTypes().nonNullable()), + resolve: (type, _) { + // TODO: Interface and union types + return []; + }, + ), + ); + var fieldType = _reflectFields(); var inputValueType = _reflectInputValueType(); var typeField = fieldType.fields @@ -120,7 +146,9 @@ GraphQLObjectType _reflectSchemaTypes() { } GraphQLObjectType _createTypeType() { + var enumValueType = _reflectEnumValueType(); var fieldType = _reflectFields(); + var inputValueType = _reflectInputValueType(); return objectType('__Type', fields: [ field( @@ -169,6 +197,25 @@ GraphQLObjectType _createTypeType() { .toList() : [], ), + field( + 'enumValues', + type: listType(enumValueType.nonNullable()), + arguments: [ + new GraphQLFieldArgument( + 'includeDeprecated', + graphQLBoolean, + defaultValue: false, + ), + ], + ), + field( + 'inputFields', + type: listType(inputValueType.nonNullable()), + resolve: (obj, _) { + // TODO: INPUT_OBJECT type + return []; + }, + ), ]); } @@ -261,6 +308,12 @@ GraphQLObjectType _reflectDirectiveType() { ]); } +GraphQLObjectType _enumValueType; + +GraphQLObjectType _reflectEnumValueType() { + return _enumValueType ?? objectType('__EnumValue', fields: []); +} + List fetchAllTypes(GraphQLSchema schema) { var typess = []; typess.addAll(_fetchAllTypesFromObject(schema.query));