aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Language/GraphQL/AST/EncoderSpec.hs4
-rw-r--r--tests/Language/GraphQL/ErrorSpec.hs4
-rw-r--r--tests/Language/GraphQL/Execute/CoerceSpec.hs4
-rw-r--r--tests/Language/GraphQL/Type/OutSpec.hs4
-rw-r--r--tests/Language/GraphQL/ValidateSpec.hs114
-rw-r--r--tests/Test/KitchenSinkSpec.hs69
-rw-r--r--tests/data/kitchen-sink.graphql38
-rw-r--r--tests/data/kitchen-sink.min.graphql1
8 files changed, 128 insertions, 110 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs
index 71ee948..5fa3706 100644
--- a/tests/Language/GraphQL/AST/EncoderSpec.hs
+++ b/tests/Language/GraphQL/AST/EncoderSpec.hs
@@ -123,7 +123,9 @@ spec = do
it "indents block strings in arguments" $
let arguments = [Argument "message" (String "line1\nline2")]
field = Field Nothing "field" arguments [] []
- operation = DefinitionOperation $ SelectionSet $ pure field
+ operation = DefinitionOperation
+ $ SelectionSet (pure field)
+ $ Location 0 0
in definition pretty operation `shouldBe` [r|{
field(message: """
line1
diff --git a/tests/Language/GraphQL/ErrorSpec.hs b/tests/Language/GraphQL/ErrorSpec.hs
index 482dc3a..1497c48 100644
--- a/tests/Language/GraphQL/ErrorSpec.hs
+++ b/tests/Language/GraphQL/ErrorSpec.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
{-# LANGUAGE OverloadedStrings #-}
module Language.GraphQL.ErrorSpec
( spec
diff --git a/tests/Language/GraphQL/Execute/CoerceSpec.hs b/tests/Language/GraphQL/Execute/CoerceSpec.hs
index 339c2e3..2b00895 100644
--- a/tests/Language/GraphQL/Execute/CoerceSpec.hs
+++ b/tests/Language/GraphQL/Execute/CoerceSpec.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
{-# LANGUAGE OverloadedStrings #-}
module Language.GraphQL.Execute.CoerceSpec
( spec
diff --git a/tests/Language/GraphQL/Type/OutSpec.hs b/tests/Language/GraphQL/Type/OutSpec.hs
index eecc374..733763d 100644
--- a/tests/Language/GraphQL/Type/OutSpec.hs
+++ b/tests/Language/GraphQL/Type/OutSpec.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
{-# LANGUAGE OverloadedStrings #-}
module Language.GraphQL.Type.OutSpec
( spec
diff --git a/tests/Language/GraphQL/ValidateSpec.hs b/tests/Language/GraphQL/ValidateSpec.hs
index f84322d..8f6626b 100644
--- a/tests/Language/GraphQL/ValidateSpec.hs
+++ b/tests/Language/GraphQL/ValidateSpec.hs
@@ -148,7 +148,7 @@ validate queryString =
spec :: Spec
spec =
- describe "document" $
+ describe "document" $ do
it "rejects type definitions" $
let queryString = [r|
query getDogName {
@@ -169,3 +169,115 @@ spec =
, path = []
}
in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects multiple subscription root fields" $
+ let queryString = [r|
+ subscription sub {
+ newMessage {
+ body
+ sender
+ }
+ disallowedSecondRootField
+ }
+ |]
+ expected = Error
+ { message =
+ "Subscription sub must select only one top level field."
+ , locations = [AST.Location 2 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects multiple subscription root fields coming from a fragment" $
+ let queryString = [r|
+ subscription sub {
+ ...multipleSubscriptions
+ }
+
+ fragment multipleSubscriptions on Subscription {
+ newMessage {
+ body
+ sender
+ }
+ disallowedSecondRootField
+ }
+ |]
+ expected = Error
+ { message =
+ "Subscription sub must select only one top level field."
+ , locations = [AST.Location 2 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects multiple anonymous operations" $
+ let queryString = [r|
+ {
+ dog {
+ name
+ }
+ }
+
+ query getName {
+ dog {
+ owner {
+ name
+ }
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "This anonymous operation must be the only defined operation."
+ , locations = [AST.Location 2 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects operations with the same name" $
+ let queryString = [r|
+ query dogOperation {
+ dog {
+ name
+ }
+ }
+
+ mutation dogOperation {
+ mutateDog {
+ id
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "There can be only one operation named \"dogOperation\"."
+ , locations = [AST.Location 2 15, AST.Location 8 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
+
+ it "rejects fragments with the same name" $
+ let queryString = [r|
+ {
+ dog {
+ ...fragmentOne
+ }
+ }
+
+ fragment fragmentOne on Dog {
+ name
+ }
+
+ fragment fragmentOne on Dog {
+ owner {
+ name
+ }
+ }
+ |]
+ expected = Error
+ { message =
+ "There can be only one fragment named \"fragmentOne\"."
+ , locations = [AST.Location 8 15, AST.Location 12 15]
+ , path = []
+ }
+ in validate queryString `shouldBe` Seq.singleton expected
diff --git a/tests/Test/KitchenSinkSpec.hs b/tests/Test/KitchenSinkSpec.hs
deleted file mode 100644
index 9f5a947..0000000
--- a/tests/Test/KitchenSinkSpec.hs
+++ /dev/null
@@ -1,69 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE QuasiQuotes #-}
-module Test.KitchenSinkSpec
- ( spec
- ) where
-
-import qualified Data.Text.IO as Text.IO
-import qualified Data.Text.Lazy.IO as Text.Lazy.IO
-import qualified Data.Text.Lazy as Lazy (Text)
-import qualified Language.GraphQL.AST.Encoder as Encoder
-import qualified Language.GraphQL.AST.Parser as Parser
-import Paths_graphql (getDataFileName)
-import Test.Hspec (Spec, describe, it)
-import Test.Hspec.Megaparsec (parseSatisfies)
-import Text.Megaparsec (parse)
-import Text.RawString.QQ (r)
-
-spec :: Spec
-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"
- expected <- Text.Lazy.IO.readFile minFileName
-
- shouldNormalize Encoder.minified dataFileName expected
-
- it "pretty prints the query" $ do
- dataFileName <- getDataFileName "tests/data/kitchen-sink.graphql"
- 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
-}
-|]
-
- shouldNormalize Encoder.pretty dataFileName expected
-
-shouldNormalize :: Encoder.Formatter -> FilePath -> Lazy.Text -> IO ()
-shouldNormalize formatter dataFileName expected = do
- actual <- Text.IO.readFile dataFileName
- parse Parser.document dataFileName actual `parseSatisfies` condition
- where
- condition = (expected ==) . Encoder.document formatter
diff --git a/tests/data/kitchen-sink.graphql b/tests/data/kitchen-sink.graphql
deleted file mode 100644
index 89903b7..0000000
--- a/tests/data/kitchen-sink.graphql
+++ /dev/null
@@ -1,38 +0,0 @@
-# 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.min.graphql b/tests/data/kitchen-sink.min.graphql
deleted file mode 100644
index 24f5c26..0000000
--- a/tests/data/kitchen-sink.min.graphql
+++ /dev/null
@@ -1 +0,0 @@
-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}