convertType method
GraphQLType
convertType(
- TypeContext ctx, {
- bool usePolymorphicName = false,
- GraphQLObjectType? parent,
Implementation
GraphQLType convertType(TypeContext ctx,
{bool usePolymorphicName = false, GraphQLObjectType? parent}) {
var listType = ctx.listType;
var typeName = ctx.typeName;
if (listType != null) {
var convert = convertType(listType.innerType);
return GraphQLListType(convert);
} else if (typeName != null) {
final name = typeName.name;
switch (name) {
case 'Int':
return graphQLInt;
case 'Float':
return graphQLFloat;
case 'String':
return graphQLString;
case 'Boolean':
return graphQLBoolean;
case 'ID':
return graphQLId;
case 'Date':
case 'DateTime':
return graphQLDate;
default:
usePolymorphicName = usePolymorphicName && parent != null;
if (usePolymorphicName) {
final ret = customTypes.firstWhereOrNull((t) {
return t is GraphQLObjectType &&
t.polymorphicName == name &&
parent.possibleTypes.contains(t);
});
if (ret != null) {
return ret;
}
}
return customTypes.firstWhere((t) {
return t.name == name;
},
orElse: () =>
throw ArgumentError('Unknown GraphQL type: "$name"'));
}
} else {
throw ArgumentError('Invalid GraphQL type: "${ctx.span.text}"');
}
}