summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Navarro <j@dannynavarro.net>2015-09-14 17:01:14 +0200
committerDanny Navarro <j@dannynavarro.net>2015-09-14 17:01:14 +0200
commit8d81f43b611bd9624ab1ebfdb8c0cd9c2e4d9539 (patch)
tree5b81e9f0c5a19a3b89b4b4c56ae1cc2faafd8069
parentb4b83883924a0e7c8eacd63f26b098fe31c9e0be (diff)
downloadgraphql-8d81f43b611bd9624ab1ebfdb8c0cd9c2e4d9539.tar.gz
Add golden test for kitchen-sink.graphql
-rw-r--r--TODO5
-rw-r--r--graphql.cabal14
-rw-r--r--tests/data/kitchen-sink.graphql38
-rw-r--r--tests/data/kitchen-sink.graphql.golden1
-rw-r--r--tests/golden.hs21
5 files changed, 79 insertions, 0 deletions
diff --git a/TODO b/TODO
index c8e5bc3..9502263 100644
--- a/TODO
+++ b/TODO
@@ -14,3 +14,8 @@
- Arbitrary precision for number values?
- Handle errors. Perhaps port to `parsers` or use a lexer and
`regex-applicative`
+
+## Tests
+
+- Golden data within package, `path_graphql` macro.
+- Pretty Print golden result
diff --git a/graphql.cabal b/graphql.cabal
index 55759d1..790a2af 100644
--- a/graphql.cabal
+++ b/graphql.cabal
@@ -18,13 +18,27 @@ tested-with: GHC == 7.10
extra-source-files: README.md CHANGELOG.md stack.yaml
library
+ default-language: Haskell2010
+ ghc-options: -Wall
exposed-modules: Data.GraphQL.AST
Data.GraphQL.Parser
build-depends: base >= 4.7 && < 5,
text >=0.11.3.1,
attoparsec >=0.10.4.0
+
+test-suite golden
default-language: Haskell2010
+ type: exitcode-stdio-1.0
+ hs-source-dirs: tests
+ main-is: golden.hs
ghc-options: -Wall
+ build-depends: base >= 4.6 && <5,
+ bytestring,
+ text,
+ attoparsec,
+ tasty >=0.10,
+ tasty-golden,
+ graphql
source-repository head
type: git
diff --git a/tests/data/kitchen-sink.graphql b/tests/data/kitchen-sink.graphql
new file mode 100644
index 0000000..46fd10e
--- /dev/null
+++ b/tests/data/kitchen-sink.graphql
@@ -0,0 +1,38 @@
+# Copyright (c) 2015, Facebook, Inc.
+# All rights reserved.
+#
+# This source code is licensed under the BSD-style license found in the
+# LICENSE file in the root directory of this source tree. An additional grant
+# of patent rights can be found in the PATENTS file in the same directory.
+
+query queryName($foo: ComplexType, $site: Site = MOBILE) {
+ whoever123is: node(id: [123, 456]) {
+ id , # Inline test comment
+ ... on User @defer {
+ field2 {
+ id ,
+ alias: field1(first:10, after:$foo,) @include(if: $foo) {
+ id,
+ ...frag
+ }
+ }
+ }
+ }
+}
+
+mutation likeStory {
+ like(story: 123) @defer {
+ story {
+ id
+ }
+ }
+}
+
+fragment frag on Friend {
+ foo(size: $size, bar: $b, obj: {key: "value"})
+}
+
+{
+ unnamed(truthy: true, falsey: false),
+ query
+}
diff --git a/tests/data/kitchen-sink.graphql.golden b/tests/data/kitchen-sink.graphql.golden
new file mode 100644
index 0000000..2542cd5
--- /dev/null
+++ b/tests/data/kitchen-sink.graphql.golden
@@ -0,0 +1 @@
+Document [DefinitionOperation (Query "queryName" [VariableDefinition (Variable "foo") (TypeNamed (NamedType "ComplexType")) Nothing,VariableDefinition (Variable "site") (TypeNamed (NamedType "Site")) (Just (ValueEnum "MOBILE"))] [] [SelectionField (Field "whoever123is" "node" [Argument "id" (ValueList (ListValue [ValueInt 123,ValueInt 456]))] [] [SelectionField (Field "" "id" [] [] []),SelectionInlineFragment (InlineFragment (NamedType "User") [Directive "defer" []] [SelectionField (Field "" "field2" [] [] [SelectionField (Field "" "id" [] [] []),SelectionField (Field "alias" "field1" [Argument "first" (ValueInt 10),Argument "after" (ValueVariable (Variable "foo"))] [Directive "include" [Argument "if" (ValueVariable (Variable "foo"))]] [SelectionField (Field "" "id" [] [] []),SelectionFragmentSpread (FragmentSpread "frag" [])])])])])]),DefinitionOperation (Mutation "likeStory" [] [] [SelectionField (Field "" "like" [Argument "story" (ValueInt 123)] [Directive "defer" []] [SelectionField (Field "" "story" [] [] [SelectionField (Field "" "id" [] [] [])])])]),DefinitionFragment (FragmentDefinition "frag" (NamedType "Friend") [] [SelectionField (Field "" "foo" [Argument "size" (ValueVariable (Variable "size")),Argument "bar" (ValueVariable (Variable "b")),Argument "obj" (ValueObject (ObjectValue [ObjectField "key" (ValueString "value")]))] [] [])])]
diff --git a/tests/golden.hs b/tests/golden.hs
new file mode 100644
index 0000000..e7ab70f
--- /dev/null
+++ b/tests/golden.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+import Control.Monad ((>=>))
+import Data.Attoparsec.Text (parseOnly)
+import Data.ByteString.Lazy.Char8 as B8
+import qualified Data.Text.IO as TIO
+import Test.Tasty (defaultMain)
+import Test.Tasty.Golden (goldenVsString)
+
+import Data.GraphQL.Parser (document)
+
+main :: IO ()
+main = defaultMain
+ $ goldenVsString "kitchen-sink.graphql"
+ "./tests/data/kitchen-sink.graphql.golden"
+ (parse "./tests/data/kitchen-sink.graphql")
+ where
+ parse = fmap (parseOnly document) . TIO.readFile
+ >=> pure . either B8.pack (flip B8.snoc '\n' . B8.pack . show)
+