createFieldName = key => {
  // Check if the key is really a string otherwise GraphQL will throw.
  invariant(
    typeof key === `string`,
    `GraphQL field name (key) is not a string: \`${key}\`.`
  )

  const fieldName = key.split(`___NODE`)[0]
  const replaced = fieldName.replace(NON_ALPHA_NUMERIC_EXPR, `_`)

  // key is invalid; normalize with leading underscore and rest with x
  if (replaced.match(/^__/)) {
    return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `x`))
  }

  // key is invalid (starts with numeric); normalize with leading underscore
  if (replaced.match(/^[0-9]/)) {
    return `_` + replaced
  }

  return replaced
}
GraphQL field names must be a string and cannot contain anything other than
alphanumeric characters and `_`. They also can't start with `__` which is
reserved for internal fields (`___foo` doesn't work either).