async function diffBuiltTypeDefs(typeDefs) {
  // only diff the schema if the user has opted in
  if (process.env.WP_DIFF_SCHEMA_CUSTOMIZATION !== `true`) {
    return
  }

  const state = getStore().getState()

  const {
    gatsbyApi: {
      helpers: { cache, reporter },
    },
    remoteSchema,
  } = state

  const previousTypeDefsKey = withPluginKey(`previousTypeDefinitions`)

  const previousTypeDefinitions = await cache.get(previousTypeDefsKey)
  const typeDefString = JSON.stringify(typeDefs)
  const typeNames = typeDefs.map(typeDef => typeDef.config.name)

  const remoteSchemaChanged =
    !previousTypeDefinitions ||
    previousTypeDefinitions?.schemaHash !== remoteSchema.schemaHash

  if (remoteSchemaChanged) {
    await cache.set(previousTypeDefsKey, {
      schemaHash: remoteSchema.schemaHash,
      typeDefString,
      typeNames,
    })
    return
  }

  // type defs are the same as last time, so don't check for missing/inconsistent types
  if (previousTypeDefinitions?.typeDefString === typeDefString) {
    return
  }

  const missingTypeNames = previousTypeDefinitions.typeNames.filter(
    name => !typeNames.includes(name)
  )

  const previousTypeDefJson = mergeDuplicateTypesAndReturnDedupedList(
    JSON.parse(previousTypeDefinitions.typeDefString)
  )

  const newParsedTypeDefs = mergeDuplicateTypesAndReturnDedupedList(
    JSON.parse(typeDefString)
  )

  const changedTypeDefs = newParsedTypeDefs
    .map(typeDef => {
      const previousTypeDef = previousTypeDefJson.find(
        previousTypeDef => previousTypeDef.config.name === typeDef.config.name
      )

      const isDifferent = diffString(previousTypeDef, typeDef)

      if (isDifferent) {
        return `Typename ${typeDef.config.name} diff:\n${diffString(
          previousTypeDef,
          typeDef,
          {
            // diff again to also show unchanged lines
            full: true,
          }
        )}`
      }

      return null
    })
    .filter(Boolean)

  let errorMessage = formatLogMessage(
    `The remote WPGraphQL schema hasn't changed but local generated type definitions have. This is a bug, please open an issue on Github${
      missingTypeNames.length || changedTypeDefs.length
        ? ` and include the following text.`
        : ``
    }.${
      missingTypeNames.length
        ? `\n\nMissing type names: ${missingTypeNames.join(`\n`)}\n`
        : ``
    }${
      changedTypeDefs.length
        ? `\n\nChanged type defs:\n\n${changedTypeDefs.join(`\n`)}`
        : ``
    }`
  )

  const maxErrorLength = 5000

  if (errorMessage.length > maxErrorLength) {
    errorMessage =
      errorMessage.substring(0, maxErrorLength) +
      `\n\n...\n[Diff exceeded ${maxErrorLength} characters and was truncated]`
  }

  if (process.env.WP_INCONSISTENT_SCHEMA_WARN !== `true`) {
    reporter.info(
      formatLogMessage(
        `Panicking due to inconsistent schema customization. Turn this into a warning by setting process.env.WP_INCONSISTENT_SCHEMA_WARN to a string of "true"`
      )
    )
    reporter.panic({
      id: CODES.InconsistentSchemaCustomization,
      context: {
        sourceMessage: errorMessage,
      },
    })
  } else {
    reporter.warn(errorMessage)
  }
}
Diffs the built types between this build and the last one with the same remote schema hash.
This is to catch and add helpful error messages for when an inconsistent schema between builds is inadvertently created due to some bug