GraphQL constructor
GraphQL(})
Binds a schema to an executor.
Pass introspect: false to leave __schema and __type out of the
schema; every type is still registered, so a fragment on a named type
keeps resolving. defaultFieldResolver is consulted for a field that has
no resolver of its own on an object that is not a Map. customTypes
adds types that no field mentions, which introspection would otherwise
never reach. Pass validate: true to check a document against the schema
before executing it.
Implementation
GraphQL(
GraphQLSchema schema, {
bool introspect = true,
this.validate = false,
this.defaultFieldResolver,
List<GraphQLType> customTypes = const <GraphQLType>[],
}) : _schema = schema {
if (customTypes.isNotEmpty == true) {
this.customTypes.addAll(customTypes);
}
var allTypes = fetchAllTypes(schema, [...this.customTypes]);
if (introspect) {
_schema = reflectSchema(_schema, allTypes);
}
for (var type in allTypes.toSet()) {
if (!this.customTypes.contains(type)) {
if (type != null) {
this.customTypes.add(type);
}
}
}
if (_schema.queryType != null) {
this.customTypes.add(_schema.queryType!);
}
if (_schema.mutationType != null) {
this.customTypes.add(_schema.mutationType!);
}
if (_schema.subscriptionType != null) {
this.customTypes.add(_schema.subscriptionType!);
}
}