Move introspection to graphql_server
This commit is contained in:
parent
89b9a3ea60
commit
01ad2d26bf
3 changed files with 23 additions and 3 deletions
|
@ -36,6 +36,8 @@ main() async {
|
|||
app.get('/graphiql', graphiql());
|
||||
|
||||
await todoService.create({'text': 'Clean your room!', 'completed': true});
|
||||
await todoService.create({'text': 'Take out the trash', 'completed': false});
|
||||
await todoService.create({'text': 'Become a billionaire at the age of 5', 'completed': false});
|
||||
|
||||
var server = await http.startServer('127.0.0.1', 3000);
|
||||
var uri =
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:graphql_parser/graphql_parser.dart';
|
||||
import 'package:graphql_schema/graphql_schema.dart';
|
||||
import 'package:graphql_schema/introspection.dart';
|
||||
import 'introspection.dart';
|
||||
|
||||
class GraphQL {
|
||||
final Map<String, GraphQLType> customTypes = {};
|
||||
|
@ -290,7 +290,7 @@ class GraphQL {
|
|||
if (fieldType is GraphQLListType) {
|
||||
if (result is! Iterable) {
|
||||
throw new GraphQLException(
|
||||
'Value of field "$fieldName" must be a list or iterable.');
|
||||
'Value of field "$fieldName" must be a list or iterable, got $result instead.');
|
||||
}
|
||||
|
||||
var innerType = fieldType.innerType;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import 'package:graphql_parser/graphql_parser.dart';
|
||||
import 'package:graphql_schema/graphql_schema.dart';
|
||||
|
||||
// TODO: How to handle custom types???
|
||||
GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
||||
var objectTypes = fetchAllTypes(schema);
|
||||
allTypes.addAll(objectTypes);
|
||||
var typeType = _reflectSchemaTypes();
|
||||
var directiveType = _reflectDirectiveType();
|
||||
allTypes.addAll(objectTypes);
|
||||
|
||||
var schemaType = objectType('__Schema', fields: [
|
||||
field(
|
||||
|
@ -22,9 +24,15 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
|||
type: typeType,
|
||||
resolve: (_, __) => schema.mutation,
|
||||
),
|
||||
field(
|
||||
'directives',
|
||||
type: listType(directiveType).nonNullable(),
|
||||
resolve: (_, __) => [], // TODO: Actually fetch directives
|
||||
),
|
||||
]);
|
||||
|
||||
allTypes.addAll([
|
||||
directiveType,
|
||||
typeType,
|
||||
schemaType,
|
||||
_reflectFields(),
|
||||
|
@ -156,6 +164,16 @@ GraphQLObjectType _createFieldType() {
|
|||
]);
|
||||
}
|
||||
|
||||
GraphQLObjectType _reflectDirectiveType() {
|
||||
return objectType('__Directive', fields: [
|
||||
field(
|
||||
'name',
|
||||
type: graphQLString,
|
||||
resolve: (obj, _) => (obj as DirectiveContext).NAME.span.text,
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
List<GraphQLObjectType> fetchAllTypes(GraphQLSchema schema) {
|
||||
var typess = <GraphQLType>[];
|
||||
typess.addAll(_fetchAllTypesFromObject(schema.query));
|
Loading…
Reference in a new issue