function aliasFieldsInSelection(prefix, selections, document) {
  return _.flatMap(selections, selection => {
    switch (selection.kind) {
      case Kind.INLINE_FRAGMENT:
        return [aliasFieldsInInlineFragment(prefix, selection, document)]
      case Kind.FRAGMENT_SPREAD: {
        const inlineFragment = inlineFragmentSpread(selection, document)
        return [
          addSkipDirective(selection),
          aliasFieldsInInlineFragment(prefix, inlineFragment, document),
        ]
      }
      case Kind.FIELD:
      default:
        return [aliasField(selection, prefix)]
    }
  })
}
Add aliases to fields of the selection, including top-level fields of inline fragments.
Fragment spreads are converted to inline fragments and their top-level fields are also aliased.

Note that this method is shallow. It adds aliases only to the top-level fields and doesn't
descend to field sub-selections.

For example, transforms:
  {
    foo
    ... on Query { foo }
    ...FragmentWithBarField
  }
To:
  {
    gatsby1_foo: foo
    ... on Query { gatsby1_foo: foo }
    ... on Query { gatsby1_bar: bar }
  }