possibleTypesMap method
Implementation
Map<String, Set<String>> possibleTypesMap() {
// TODO handle interfaces that extend other interfaces?
// https://github.com/graphql/graphql-spec/pull/373
final possibleTypes = <String, Set<String>>{};
for (final definition in definitions) {
if (definition is UnionTypeDefinitionNode) {
final types = possibleTypes[definition.name.value] ?? {};
for (final tpe in definition.types) {
types.add(tpe.name.value);
}
possibleTypes[definition.name.value] = types;
} else if (definition is ObjectTypeDefinitionNode) {
for (final tpe in definition.interfaces) {
final types = possibleTypes[tpe.name.value] ?? {};
types.add(definition.name.value);
possibleTypes[tpe.name.value] = types;
}
}
}
return possibleTypes.map((key, value) => MapEntry<String, Set<String>>(
key,
value
.expand<ObjectTypeDefinitionNode>(_lookupConcreteTypes)
.map((e) => e.name.value)
.toSet()));
}