when<O> method

O when<O>({
  1. required O enum_(
    1. GraphQLEnumType<Json>
    ),
  2. required O scalar(
    1. GraphQLScalarType<Json, Object?>
    ),
  3. required O object(
    1. GraphQLObjectType<Json>
    ),
  4. required O input(
    1. GraphQLInputObjectType<Json>
    ),
  5. required O union(
    1. GraphQLUnionType<Json>
    ),
  6. required O list(
    1. GraphQLListType
    ),
  7. required O nonNullable(
    1. GraphQLNonNullType<Json, Object?>
    ),
})
inherited

Executes any of the provided function with this as argument. The function executed depends on the type of this

Implementation

O when<O>({
  required O Function(GraphQLEnumType<Value>) enum_,
  required O Function(GraphQLScalarType<Value, Serialized>) scalar,
  required O Function(GraphQLObjectType<Value>) object,
  required O Function(GraphQLInputObjectType<Value>) input,
  required O Function(GraphQLUnionType<Value>) union,
  required O Function(GraphQLListType) list,
  required O Function(GraphQLNonNullType<Value, Serialized>) nonNullable,
}) {
  final GraphQLType type = this;

  if (type is GraphQLEnumType<Value>) {
    return enum_(type);
  } else if (type is GraphQLScalarType<Value, Serialized>) {
    return scalar(type);
  } else if (type is GraphQLObjectType<Value>) {
    return object(type);
  } else if (type is GraphQLInputObjectType<Value>) {
    return input(type);
  } else if (type is GraphQLUnionType<Value>) {
    return union(type);
  } else if (type is GraphQLListType) {
    return list(type);
  } else if (type is GraphQLNonNullType<Value, Serialized>) {
    return nonNullable(type);
  } else {
    throw Exception(
      'Could not cast $this ($runtimeType) as a typical GraphQLType.',
    );
  }
}