Introspection finally works
This commit is contained in:
parent
b0116ed8c6
commit
a4fa5b70fb
2 changed files with 23 additions and 8 deletions
|
@ -13,13 +13,14 @@ part 'validation_result.dart';
|
||||||
class GraphQLSchema {
|
class GraphQLSchema {
|
||||||
final GraphQLObjectType query;
|
final GraphQLObjectType query;
|
||||||
final GraphQLObjectType mutation;
|
final GraphQLObjectType mutation;
|
||||||
|
final GraphQLObjectType subscription;
|
||||||
|
|
||||||
GraphQLSchema({this.query, this.mutation});
|
GraphQLSchema({this.query, this.mutation, this.subscription});
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphQLSchema graphQLSchema(
|
GraphQLSchema graphQLSchema(
|
||||||
{@required GraphQLObjectType query, GraphQLObjectType mutation}) =>
|
{@required GraphQLObjectType query, GraphQLObjectType mutation, GraphQLObjectType subscription}) =>
|
||||||
new GraphQLSchema(query: query, mutation: mutation);
|
new GraphQLSchema(query: query, mutation: mutation, subscription: subscription);
|
||||||
|
|
||||||
/// A default resolver that always returns `null`.
|
/// A default resolver that always returns `null`.
|
||||||
resolveToNull(_, __) => null;
|
resolveToNull(_, __) => null;
|
||||||
|
|
|
@ -12,7 +12,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
||||||
field(
|
field(
|
||||||
'types',
|
'types',
|
||||||
type: listType(typeType),
|
type: listType(typeType),
|
||||||
resolve: (_, __) => objectTypes,
|
resolve: (_, __) => allTypes,
|
||||||
),
|
),
|
||||||
field(
|
field(
|
||||||
'queryType',
|
'queryType',
|
||||||
|
@ -24,6 +24,11 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
||||||
type: typeType,
|
type: typeType,
|
||||||
resolve: (_, __) => schema.mutation,
|
resolve: (_, __) => schema.mutation,
|
||||||
),
|
),
|
||||||
|
field(
|
||||||
|
'subscriptionType',
|
||||||
|
type: typeType,
|
||||||
|
resolve: (_, __) => schema.subscription,
|
||||||
|
),
|
||||||
field(
|
field(
|
||||||
'directives',
|
'directives',
|
||||||
type: listType(directiveType).nonNullable(),
|
type: listType(directiveType).nonNullable(),
|
||||||
|
@ -32,6 +37,12 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
allTypes.addAll([
|
allTypes.addAll([
|
||||||
|
graphQLBoolean,
|
||||||
|
graphQLString,
|
||||||
|
graphQLId,
|
||||||
|
graphQLDate,
|
||||||
|
graphQLFloat,
|
||||||
|
graphQLInt,
|
||||||
directiveType,
|
directiveType,
|
||||||
typeType,
|
typeType,
|
||||||
schemaType,
|
schemaType,
|
||||||
|
@ -128,7 +139,7 @@ GraphQLObjectType _reflectSchemaTypes() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
typeField = fieldType.fields
|
typeField = inputValueType.fields
|
||||||
.firstWhere((f) => f.name == 'type', orElse: () => null);
|
.firstWhere((f) => f.name == 'type', orElse: () => null);
|
||||||
|
|
||||||
if (typeField == null) {
|
if (typeField == null) {
|
||||||
|
@ -262,7 +273,7 @@ GraphQLObjectType _reflectInputValueType() {
|
||||||
return _inputValueType ??= objectType('__InputValue', fields: [
|
return _inputValueType ??= objectType('__InputValue', fields: [
|
||||||
field(
|
field(
|
||||||
'name',
|
'name',
|
||||||
type: graphQLString,
|
type: graphQLString.nonNullable(),
|
||||||
resolve: (obj, _) => (obj as GraphQLFieldArgument).name,
|
resolve: (obj, _) => (obj as GraphQLFieldArgument).name,
|
||||||
),
|
),
|
||||||
field(
|
field(
|
||||||
|
@ -279,11 +290,13 @@ GraphQLObjectType _reflectInputValueType() {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GraphQLObjectType _directiveType;
|
||||||
|
|
||||||
GraphQLObjectType _reflectDirectiveType() {
|
GraphQLObjectType _reflectDirectiveType() {
|
||||||
var inputValueType = _reflectInputValueType();
|
var inputValueType = _reflectInputValueType();
|
||||||
|
|
||||||
// TODO: What actually is this???
|
// TODO: What actually is this???
|
||||||
return objectType('__Directive', fields: [
|
return _directiveType ??= objectType('__Directive', fields: [
|
||||||
field(
|
field(
|
||||||
'name',
|
'name',
|
||||||
type: graphQLString.nonNullable(),
|
type: graphQLString.nonNullable(),
|
||||||
|
@ -298,7 +311,7 @@ GraphQLObjectType _reflectDirectiveType() {
|
||||||
'locations',
|
'locations',
|
||||||
type: listType(graphQLString.nonNullable()).nonNullable(),
|
type: listType(graphQLString.nonNullable()).nonNullable(),
|
||||||
// TODO: Enum directiveLocation
|
// TODO: Enum directiveLocation
|
||||||
resolve: (obj, _) => [],
|
resolve: (obj, _) => <String>[],
|
||||||
),
|
),
|
||||||
field(
|
field(
|
||||||
'args',
|
'args',
|
||||||
|
@ -311,6 +324,7 @@ GraphQLObjectType _reflectDirectiveType() {
|
||||||
GraphQLObjectType _enumValueType;
|
GraphQLObjectType _enumValueType;
|
||||||
|
|
||||||
GraphQLObjectType _reflectEnumValueType() {
|
GraphQLObjectType _reflectEnumValueType() {
|
||||||
|
// TODO: Enum values
|
||||||
return _enumValueType ?? objectType('__EnumValue', fields: []);
|
return _enumValueType ?? objectType('__EnumValue', fields: []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue