This commit is contained in:
Frederik Hanghøj Iversen 2019-07-31 20:19:22 +02:00
commit 40dea5111a
10 changed files with 167 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.stack-work/
gql2hs.cabal
*~

3
ChangeLog.md Normal file
View file

@ -0,0 +1,3 @@
# Changelog for gql2hs
## Unreleased changes

30
LICENSE Normal file
View file

@ -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.

1
README.md Normal file
View file

@ -0,0 +1 @@
# gql2hs

2
Setup.hs Normal file
View file

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

40
app/Main.hs Normal file
View file

@ -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 "<nothing>"
-- 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"

52
package.yaml Normal file
View file

@ -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 <https://github.com/fredefox/gql2hs#readme>
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

View file

@ -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) = _

7
stack.yaml Normal file
View file

@ -0,0 +1,7 @@
resolver: lts-13.30
packages:
- .
extra-deps:
- graphql-0.4.0.0

2
test/Spec.hs Normal file
View file

@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"