gql2hs/app/Main.hs

32 lines
996 B
Haskell
Raw Normal View History

2019-07-31 20:25:10 +00:00
{-# OPTIONS_GHC -Wall #-}
2019-07-31 18:19:22 +00:00
module Main where
2019-07-31 20:25:10 +00:00
import Control.Category ((>>>))
import Control.Monad ((>=>))
import Control.Monad.Fail (fail)
import Data.Attoparsec.Text (Parser)
import Data.Foldable (traverse_)
import Data.Text (Text)
import Language.Haskell.Exts.Pretty
import Prelude hiding (fail)
import qualified Data.Attoparsec.Text as Parser
2019-07-31 18:19:22 +00:00
import qualified Data.Text.IO as Text
2019-07-31 20:25:10 +00:00
import qualified GraphQL.Internal.Syntax.AST as GraphQL
import qualified GraphQL.Internal.Syntax.Parser as GraphQL.Parser
import qualified Language.GraphQL.Reflection as GraphQL
2019-07-31 18:19:22 +00:00
import qualified System.Environment as System
main :: IO ()
2019-07-31 20:25:10 +00:00
main = System.getArgs >>= traverse_ run
2019-07-31 18:19:22 +00:00
run :: FilePath -> IO ()
2019-07-31 20:25:10 +00:00
run = parseFile >=> (GraphQL.schemaDocument >>> traverse_ (prettyPrint >>> putStrLn))
2019-07-31 18:19:22 +00:00
2019-07-31 20:25:10 +00:00
parseFile :: FilePath -> IO GraphQL.SchemaDocument
parseFile p = do
2019-07-31 18:19:22 +00:00
txt <- Text.readFile p
2019-07-31 20:25:10 +00:00
parse GraphQL.Parser.schemaDocument txt
2019-07-31 18:19:22 +00:00
2019-07-31 20:25:10 +00:00
parse :: Parser a -> Text -> IO a
parse p = Parser.parseOnly p >>> either fail pure