diff --git a/graphql_schema/lib/src/schema.dart b/graphql_schema/lib/src/schema.dart index ff9bed3f..98bf6a92 100644 --- a/graphql_schema/lib/src/schema.dart +++ b/graphql_schema/lib/src/schema.dart @@ -13,13 +13,14 @@ part 'validation_result.dart'; class GraphQLSchema { final GraphQLObjectType query; final GraphQLObjectType mutation; + final GraphQLObjectType subscription; - GraphQLSchema({this.query, this.mutation}); + GraphQLSchema({this.query, this.mutation, this.subscription}); } GraphQLSchema graphQLSchema( - {@required GraphQLObjectType query, GraphQLObjectType mutation}) => - new GraphQLSchema(query: query, mutation: mutation); + {@required GraphQLObjectType query, GraphQLObjectType mutation, GraphQLObjectType subscription}) => + new GraphQLSchema(query: query, mutation: mutation, subscription: subscription); /// A default resolver that always returns `null`. resolveToNull(_, __) => null; diff --git a/graphql_server/lib/introspection.dart b/graphql_server/lib/introspection.dart index a1254825..d835cc3e 100644 --- a/graphql_server/lib/introspection.dart +++ b/graphql_server/lib/introspection.dart @@ -12,7 +12,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List allTypes) { field( 'types', type: listType(typeType), - resolve: (_, __) => objectTypes, + resolve: (_, __) => allTypes, ), field( 'queryType', @@ -24,6 +24,11 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List allTypes) { type: typeType, resolve: (_, __) => schema.mutation, ), + field( + 'subscriptionType', + type: typeType, + resolve: (_, __) => schema.subscription, + ), field( 'directives', type: listType(directiveType).nonNullable(), @@ -32,6 +37,12 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List allTypes) { ]); allTypes.addAll([ + graphQLBoolean, + graphQLString, + graphQLId, + graphQLDate, + graphQLFloat, + graphQLInt, directiveType, typeType, schemaType, @@ -128,7 +139,7 @@ GraphQLObjectType _reflectSchemaTypes() { ); } - typeField = fieldType.fields + typeField = inputValueType.fields .firstWhere((f) => f.name == 'type', orElse: () => null); if (typeField == null) { @@ -262,7 +273,7 @@ GraphQLObjectType _reflectInputValueType() { return _inputValueType ??= objectType('__InputValue', fields: [ field( 'name', - type: graphQLString, + type: graphQLString.nonNullable(), resolve: (obj, _) => (obj as GraphQLFieldArgument).name, ), field( @@ -279,11 +290,13 @@ GraphQLObjectType _reflectInputValueType() { ]); } +GraphQLObjectType _directiveType; + GraphQLObjectType _reflectDirectiveType() { var inputValueType = _reflectInputValueType(); // TODO: What actually is this??? - return objectType('__Directive', fields: [ + return _directiveType ??= objectType('__Directive', fields: [ field( 'name', type: graphQLString.nonNullable(), @@ -298,7 +311,7 @@ GraphQLObjectType _reflectDirectiveType() { 'locations', type: listType(graphQLString.nonNullable()).nonNullable(), // TODO: Enum directiveLocation - resolve: (obj, _) => [], + resolve: (obj, _) => [], ), field( 'args', @@ -311,6 +324,7 @@ GraphQLObjectType _reflectDirectiveType() { GraphQLObjectType _enumValueType; GraphQLObjectType _reflectEnumValueType() { + // TODO: Enum values return _enumValueType ?? objectType('__EnumValue', fields: []); }