generateReusableFragments = ({ fragments, selectionSet }) => {
  const fragmentsValues = Object.values(fragments)

  if (!fragmentsValues.length) {
    return ``
  }

  let builtFragments = buildReusableFragments({ fragments })

  if (fragments) {
    let regenerateFragments = false

    fragmentsValues.forEach(({ name, type }) => {
      // if our query didn't use the fragment due to the query depth AND the fragment isn't used in another fragment, delete it
      // @todo these fragments shouldn't be generated if they wont be used.
      // if we fix this todo, we can use the buildReusableFragments function directly
      // instead of running it twice to remove unused fragments
      if (
        !selectionSet.includes(`...${name}`) &&
        !builtFragments.includes(`...${name}`)
      ) {
        delete fragments[type]
        regenerateFragments = true
      }
    })

    if (regenerateFragments) {
      builtFragments = buildReusableFragments({ fragments })
    }
  }

  return builtFragments
}
Takes in a fragments object (built up during the buildSelectionSet function)
transforms that object into an actual fragment,
then checks for unused fragments and potential regenerates again
with the unused fragments removed