when<T> method

T when<T>({
  1. required T field(
    1. FieldNode
    ),
  2. required T fragmentSpread(
    1. FragmentSpreadNode
    ),
  3. required T inlineFragment(
    1. InlineFragmentNode
    ),
})

Implementation

T when<T>({
  required T Function(FieldNode) field,
  required T Function(FragmentSpreadNode) fragmentSpread,
  required T Function(InlineFragmentNode) inlineFragment,
}) {
  final selection = this;
  if (selection is FieldNode) return field(selection);
  if (selection is FragmentSpreadNode) return fragmentSpread(selection);
  if (selection is InlineFragmentNode) return inlineFragment(selection);
  throw Error();
}