commit 40dea5111af895b51f01f1105b696809226a493f Author: Frederik Hanghøj Iversen Date: Wed Jul 31 20:19:22 2019 +0200 waddap diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..160d761 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.stack-work/ +gql2hs.cabal +*~ \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..9145b15 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,3 @@ +# Changelog for gql2hs + +## Unreleased changes diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87bc158 --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +Copyright Frederik Hanghøj Iversen (c) 2019 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Frederik Hanghøj Iversen nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4211fa --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# gql2hs diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..03f9478 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,40 @@ +module Main where + +import qualified Language.GraphQL.Parser as GraphQL +import qualified Language.GraphQL.AST as GraphQL +import qualified Language.GraphQL.Reflection as GraphQL +import qualified Data.Text.IO as Text +import Text.Megaparsec (ParseErrorBundle) +import qualified Text.Megaparsec as Parsec +import qualified System.Environment as System +import qualified Language.Haskell.Exts.Syntax as Haskell +import Data.Foldable (traverse_) +import Control.Monad ((>=>)) +import Control.Category ((>>>)) +import qualified Language.Haskell.Exts.Syntax as Haskell +import Data.List.NonEmpty (NonEmpty) +import Control.Exception + +main :: IO () +main = print doc + where + doc :: GraphQL.Document + doc = Parsec.parseMaybe GraphQL.document "" +-- main :: IO () +-- main = System.getArgs >>= traverse_ run + +run :: FilePath -> IO () +run = parse >=> (GraphQL.toType >>> print @(NonEmpty (Haskell.Decl ()))) + +parse :: FilePath -> IO GraphQL.Document +parse p = do + txt <- Text.readFile p + either badFailureMechanism pure $ Parsec.parse GraphQL.document p txt + where + badFailureMechanism = fail . displayException + +getExample :: IO GraphQL.Document +getExample = parse p + where + p :: FilePath + p = "/Users/frederikhanghjiversen/git/zendesk/guide-graph/schema/schema.graphql" diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..6c86576 --- /dev/null +++ b/package.yaml @@ -0,0 +1,52 @@ +name: gql2hs +version: 0.1.0.0 +github: "fredefox/gql2hs" +license: BSD3 +author: "Frederik Hanghøj Iversen" +maintainer: "fhanghojiversen@zendesk.com" +copyright: "2019 Frederik Hanghøj Iversen" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: + - base >= 4.7 && < 5 + - graphql + - haskell-src-exts + - text + - megaparsec + +library: + source-dirs: src + +executables: + gql2hs-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - gql2hs + +tests: + gql2hs-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - gql2hs diff --git a/src/Language/GraphQL/Reflection.hs b/src/Language/GraphQL/Reflection.hs new file mode 100644 index 0000000..616e8b3 --- /dev/null +++ b/src/Language/GraphQL/Reflection.hs @@ -0,0 +1,27 @@ +module Language.GraphQL.Reflection (toType) where + +import Language.GraphQL.AST as GraphQL +import Data.List.NonEmpty (NonEmpty) +import qualified Language.Haskell.Exts.Syntax as Haskell + +toType :: GraphQL.Document -> NonEmpty (Haskell.Decl a) +toType = document + +document :: GraphQL.Document -> NonEmpty (Haskell.Decl a) +document = fmap definition + +definition :: GraphQL.Definition -> Haskell.Decl a +definition = \case + DefinitionOperation def -> definitionOperation def + DefinitionFragment def -> definitionFragment def + +definitionOperation :: OperationDefinition -> Haskell.Decl a +definitionOperation = \case + OperationSelectionSet op -> selectionSet op + OperationDefinition{} -> undefined + +selectionSet :: SelectionSet -> Haskell.Decl a +selectionSet = undefined + +definitionFragment :: FragmentDefinition -> Haskell.Decl a +definitionFragment (FragmentDefinition fragmentName typeCondition directive selectionSet) = _ diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..6bc42f5 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,7 @@ +resolver: lts-13.30 + +packages: + - . + +extra-deps: + - graphql-0.4.0.0 diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented"