Add golden test for kitchen-sink.graphql

This commit is contained in:
Danny Navarro 2015-09-14 17:01:14 +02:00
parent b4b8388392
commit 8d81f43b61
5 changed files with 79 additions and 0 deletions

5
TODO
View File

@ -14,3 +14,8 @@
- Arbitrary precision for number values? - Arbitrary precision for number values?
- Handle errors. Perhaps port to `parsers` or use a lexer and - Handle errors. Perhaps port to `parsers` or use a lexer and
`regex-applicative` `regex-applicative`
## Tests
- Golden data within package, `path_graphql` macro.
- Pretty Print golden result

View File

@ -18,13 +18,27 @@ tested-with: GHC == 7.10
extra-source-files: README.md CHANGELOG.md stack.yaml extra-source-files: README.md CHANGELOG.md stack.yaml
library library
default-language: Haskell2010
ghc-options: -Wall
exposed-modules: Data.GraphQL.AST exposed-modules: Data.GraphQL.AST
Data.GraphQL.Parser Data.GraphQL.Parser
build-depends: base >= 4.7 && < 5, build-depends: base >= 4.7 && < 5,
text >=0.11.3.1, text >=0.11.3.1,
attoparsec >=0.10.4.0 attoparsec >=0.10.4.0
test-suite golden
default-language: Haskell2010 default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: golden.hs
ghc-options: -Wall ghc-options: -Wall
build-depends: base >= 4.6 && <5,
bytestring,
text,
attoparsec,
tasty >=0.10,
tasty-golden,
graphql
source-repository head source-repository head
type: git type: git

View File

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

View File

@ -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")]))] [] [])])]

21
tests/golden.hs Normal file
View File

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