Introduce formatter type for the encoder
... to distinguish between minified and pretty printing.
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
module Test.KitchenSinkSpec
|
||||
( spec
|
||||
) where
|
||||
@ -16,10 +18,11 @@ import Test.Hspec.Expectations ( expectationFailure
|
||||
import Text.Megaparsec ( errorBundlePretty
|
||||
, parse
|
||||
)
|
||||
import Text.RawString.QQ (r)
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "Kitchen Sink" $
|
||||
it "prints the query" $ do
|
||||
spec = describe "Kitchen Sink" $ do
|
||||
it "minifies the query" $ do
|
||||
dataFileName <- getDataFileName "tests/data/kitchen-sink.graphql"
|
||||
minFileName <- getDataFileName "tests/data/kitchen-sink.min.graphql"
|
||||
actual <- Text.IO.readFile dataFileName
|
||||
@ -27,5 +30,46 @@ spec = describe "Kitchen Sink" $
|
||||
|
||||
either
|
||||
(expectationFailure . errorBundlePretty)
|
||||
(flip shouldBe expected . Encoder.document)
|
||||
(flip shouldBe expected . Encoder.document Encoder.Minified)
|
||||
$ parse Parser.document dataFileName actual
|
||||
|
||||
it "pretty prints the query" $ do
|
||||
dataFileName <- getDataFileName "tests/data/kitchen-sink.graphql"
|
||||
actual <- Text.IO.readFile dataFileName
|
||||
let expected = [r|query queryName($foo:ComplexType,$site:Site=MOBILE){
|
||||
whoever123is:node(id:[123,456]){
|
||||
id
|
||||
... 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
|
||||
}
|
||||
|]
|
||||
|
||||
either
|
||||
(expectationFailure . errorBundlePretty)
|
||||
(flip shouldBe expected . Encoder.document (Encoder.Pretty 0))
|
||||
$ parse Parser.document dataFileName actual
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
query queryName($foo: ComplexType, $site: Site = MOBILE) {
|
||||
whoever123is: node(id: [123, 456]) {
|
||||
id , # Inline test comment
|
||||
id, # Inline test comment
|
||||
... on User @defer {
|
||||
field2 {
|
||||
id ,
|
||||
alias: field1(first:10, after:$foo,) @include(if: $foo) {
|
||||
id,
|
||||
alias: field1(first: 10, after: $foo) @include(if: $foo) {
|
||||
id,
|
||||
...frag
|
||||
}
|
||||
|
@ -1,7 +1 @@
|
||||
query queryName($foo:ComplexType,$site:Site=MOBILE){whoever123is:node(id:[123,456]){id,... 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}
|
||||
query queryName($foo:ComplexType,$site:Site=MOBILE){whoever123is:node(id:[123,456]){id,... 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}
|
||||
|
Reference in New Issue
Block a user