import           Text.Megaparsec            (runParser)

countParsedTypes :: Text -> Int
countParsedTypes txt = either (const 0) length (parseTypeDefinitions txt)

parseTypeDefinitions :: Text -> Either Text [GQL.TypeSystemDefinition]
parseTypeDefinitions s =
  case runParser GQL.document "<doc>" s of
    Right (toList -> d) ->
      let tds = [td | GQL.TypeSystemDefinition td _ <- d]
       in if length d == length tds
            then Right tds
            else Left "unexpected query or type system extension"
    Left e ->