forked from OSS/graphql
Add golden test for kitchen-sink.graphql
This commit is contained in:
parent
b4b8388392
commit
8d81f43b61
5
TODO
5
TODO
@ -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
|
||||||
|
@ -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
|
||||||
|
38
tests/data/kitchen-sink.graphql
Normal file
38
tests/data/kitchen-sink.graphql
Normal 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
|
||||||
|
}
|
1
tests/data/kitchen-sink.graphql.golden
Normal file
1
tests/data/kitchen-sink.graphql.golden
Normal 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
21
tests/golden.hs
Normal 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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user