src/sort-definitions.js
function visitFragment(fragment, fragments, fragmentsHash) {
  if (fragment.marked) {
    throw Error('Fragments cannot contain a cycle');
  }
  if (!fragment.visited) {
    fragment.marked = true;
    // Visit every spread in this fragment definition
    visit(fragment, {
      FragmentSpread(node) {
        // Visit the corresponding fragment definition
        visitFragment(fragmentsHash[node.name.value], fragments, fragmentsHash);
      }
    });
    fragment.visited = true;
    fragment.marked = false;
    fragments.push(fragment);
  }
}
function visitFragment(fragment, fragments, fragmentsHash) {
  if (fragment.marked) {
    throw Error('Fragments cannot contain a cycle');
  }
  if (!fragment.visited) {
    fragment.marked = true;
    // Visit every spread in this fragment definition
    visit(fragment, {
      FragmentSpread(node) {
        // Visit the corresponding fragment definition
        visitFragment(fragmentsHash[node.name.value], fragments, fragmentsHash);
      }
    });
    fragment.visited = true;
    fragment.marked = false;
    fragments.push(fragment);
  }
}
function visitFragment ( fragment , fragments , fragmentsHash ) { if ( fragment . marked ) { throw Error ( 'Fragments cannot contain a cycle' ) ; } if ( ! fragment . visited ) { fragment . marked = true ; // Visit every spread in this fragment definition visit ( fragment , { FragmentSpread ( node ) { // Visit the corresponding fragment definition visitFragment ( fragmentsHash [ node . name . value ] , fragments , fragmentsHash ) ; } } ) ; fragment . visited = true ; fragment . marked = false ; fragments . push ( fragment ) ; } }
Recursive helper function for sortDefinitions
Recursive helper function for sortDefinitions