Added introspection fields for each field on __Type
This commit is contained in:
parent
054b96d4f4
commit
b0116ed8c6
3 changed files with 62 additions and 2 deletions
|
@ -1,8 +1,12 @@
|
||||||
part of graphql_schema.src.schema;
|
part of graphql_schema.src.schema;
|
||||||
|
|
||||||
GraphQLObjectType objectType(String name,
|
GraphQLObjectType objectType(String name,
|
||||||
{String description, Iterable<GraphQLField> fields = const []}) =>
|
{String description,
|
||||||
new GraphQLObjectType(name, description)..fields.addAll(fields ?? []);
|
Iterable<GraphQLField> fields = const [],
|
||||||
|
Iterable<GraphQLObjectType> interfaces = const []}) =>
|
||||||
|
new GraphQLObjectType(name, description)
|
||||||
|
..fields.addAll(fields ?? [])
|
||||||
|
..interfaces.addAll(interfaces ?? []);
|
||||||
|
|
||||||
GraphQLField<T, Serialized> field<T, Serialized>(String name,
|
GraphQLField<T, Serialized> field<T, Serialized>(String name,
|
||||||
{Iterable<GraphQLFieldArgument<T, Serialized>> arguments: const [],
|
{Iterable<GraphQLFieldArgument<T, Serialized>> arguments: const [],
|
||||||
|
|
|
@ -7,6 +7,9 @@ class GraphQLObjectType
|
||||||
final String description;
|
final String description;
|
||||||
final List<GraphQLField> fields = [];
|
final List<GraphQLField> fields = [];
|
||||||
|
|
||||||
|
/// A list of other types that this object type is known to implement.
|
||||||
|
final List<GraphQLObjectType> interfaces = [];
|
||||||
|
|
||||||
GraphQLObjectType(this.name, this.description);
|
GraphQLObjectType(this.name, this.description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -38,6 +38,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
||||||
_reflectFields(),
|
_reflectFields(),
|
||||||
_reflectDirectiveType(),
|
_reflectDirectiveType(),
|
||||||
_reflectInputValueType(),
|
_reflectInputValueType(),
|
||||||
|
_reflectEnumValueType(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var fields = <GraphQLField>[
|
var fields = <GraphQLField>[
|
||||||
|
@ -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 <GraphQLType>[];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
_typeType.fields.add(
|
||||||
|
field(
|
||||||
|
'possibleTypes',
|
||||||
|
type: listType(_reflectSchemaTypes().nonNullable()),
|
||||||
|
resolve: (type, _) {
|
||||||
|
// TODO: Interface and union types
|
||||||
|
return <GraphQLType>[];
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
var fieldType = _reflectFields();
|
var fieldType = _reflectFields();
|
||||||
var inputValueType = _reflectInputValueType();
|
var inputValueType = _reflectInputValueType();
|
||||||
var typeField = fieldType.fields
|
var typeField = fieldType.fields
|
||||||
|
@ -120,7 +146,9 @@ GraphQLObjectType _reflectSchemaTypes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphQLObjectType _createTypeType() {
|
GraphQLObjectType _createTypeType() {
|
||||||
|
var enumValueType = _reflectEnumValueType();
|
||||||
var fieldType = _reflectFields();
|
var fieldType = _reflectFields();
|
||||||
|
var inputValueType = _reflectInputValueType();
|
||||||
|
|
||||||
return objectType('__Type', fields: [
|
return objectType('__Type', fields: [
|
||||||
field(
|
field(
|
||||||
|
@ -169,6 +197,25 @@ GraphQLObjectType _createTypeType() {
|
||||||
.toList()
|
.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 <GraphQLFieldArgument>[];
|
||||||
|
},
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,6 +308,12 @@ GraphQLObjectType _reflectDirectiveType() {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GraphQLObjectType _enumValueType;
|
||||||
|
|
||||||
|
GraphQLObjectType _reflectEnumValueType() {
|
||||||
|
return _enumValueType ?? objectType('__EnumValue', fields: []);
|
||||||
|
}
|
||||||
|
|
||||||
List<GraphQLObjectType> fetchAllTypes(GraphQLSchema schema) {
|
List<GraphQLObjectType> fetchAllTypes(GraphQLSchema schema) {
|
||||||
var typess = <GraphQLType>[];
|
var typess = <GraphQLType>[];
|
||||||
typess.addAll(_fetchAllTypesFromObject(schema.query));
|
typess.addAll(_fetchAllTypesFromObject(schema.query));
|
||||||
|
|
Loading…
Reference in a new issue