diff options
Diffstat (limited to 'tests/Language/GraphQL')
| -rw-r--r-- | tests/Language/GraphQL/AST/DocumentSpec.hs | 6 | ||||
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 89 | ||||
| -rw-r--r-- | tests/Language/GraphQL/ExecuteSpec.hs | 28 |
3 files changed, 116 insertions, 7 deletions
diff --git a/tests/Language/GraphQL/AST/DocumentSpec.hs b/tests/Language/GraphQL/AST/DocumentSpec.hs index ca13e17..d09d6b1 100644 --- a/tests/Language/GraphQL/AST/DocumentSpec.hs +++ b/tests/Language/GraphQL/AST/DocumentSpec.hs @@ -18,3 +18,9 @@ spec = do ] expected = "{ field1: 1.2, field2: null }" in show object `shouldBe` expected + + describe "Description" $ + it "keeps content when merging with no description" $ + let expected = Description $ Just "Left description" + actual = expected <> Description Nothing + in actual `shouldBe` expected diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index febd6fd..3fa6a02 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -4,6 +4,7 @@ module Language.GraphQL.AST.EncoderSpec ( spec ) where +import Data.List.NonEmpty (NonEmpty(..)) import qualified Language.GraphQL.AST.Document as Full import Language.GraphQL.AST.Encoder import Language.GraphQL.TH @@ -178,3 +179,91 @@ spec = do it "produces lowercase mutation operation type" $ let actual = operationType pretty Full.Mutation in actual `shouldBe` "mutation" + + describe "typeSystemDefinition" $ do + it "produces a schema with an indented operation type definition" $ + let queryType = Full.OperationTypeDefinition Full.Query "QueryRootType" + mutationType = Full.OperationTypeDefinition Full.Mutation "MutationType" + operations = queryType :| pure mutationType + definition' = Full.SchemaDefinition [] operations + expected = Text.Lazy.snoc [gql| + schema { + query: QueryRootType + mutation: MutationType + } + |] '\n' + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected + + it "encodes a scalar type definition" $ + let uuidType = Full.ScalarTypeDefinition mempty "UUID" mempty + definition' = Full.TypeDefinition uuidType + expected = "scalar UUID" + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected + + it "encodes an interface definition" $ + let someType = Full.TypeNamed "String" + argument = Full.InputValueDefinition mempty "arg" someType Nothing mempty + arguments = Full.ArgumentsDefinition [argument] + definition' = Full.TypeDefinition + $ Full.InterfaceTypeDefinition mempty "UUID" mempty + $ pure + $ Full.FieldDefinition mempty "value" arguments someType mempty + expected = [gql| + interface UUID { + value(arg: String): String + } + |] + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected + + it "encodes an union definition" $ + let definition' = Full.TypeDefinition + $ Full.UnionTypeDefinition mempty "SearchResult" mempty + $ Full.UnionMemberTypes ["Photo", "Person"] + expected = [gql| + union SearchResult = + | Photo + | Person + |] + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected + + it "encodes an enum definition" $ + let values = + [ Full.EnumValueDefinition mempty "NORTH" mempty + , Full.EnumValueDefinition mempty "EAST" mempty + , Full.EnumValueDefinition mempty "SOUTH" mempty + , Full.EnumValueDefinition mempty "WEST" mempty + ] + definition' = Full.TypeDefinition + $ Full.EnumTypeDefinition mempty "Direction" mempty values + expected = [gql| + enum Direction { + NORTH + EAST + SOUTH + WEST + } + |] + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected + + it "encodes an input type" $ + let intType = Full.TypeNonNull $ Full.NonNullTypeNamed "Int" + stringType = Full.TypeNamed "String" + fields = + [ Full.InputValueDefinition mempty "a" stringType Nothing mempty + , Full.InputValueDefinition mempty "b" intType Nothing mempty + ] + definition' = Full.TypeDefinition + $ Full.InputObjectTypeDefinition mempty "ExampleInputObject" mempty fields + expected = [gql| + input ExampleInputObject { + a: String + b: Int! + } + |] + actual = typeSystemDefinition pretty definition' + in actual `shouldBe` expected diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs index c313df0..65033ae 100644 --- a/tests/Language/GraphQL/ExecuteSpec.hs +++ b/tests/Language/GraphQL/ExecuteSpec.hs @@ -66,8 +66,9 @@ queryType :: Out.ObjectType IO queryType = Out.ObjectType "Query" Nothing [] $ HashMap.fromList [ ("philosopher", ValueResolver philosopherField philosopherResolver) - , ("genres", ValueResolver genresField genresResolver) + , ("throwing", ValueResolver throwingField throwingResolver) , ("count", ValueResolver countField countResolver) + , ("sequence", ValueResolver sequenceField sequenceResolver) ] where philosopherField = @@ -75,15 +76,22 @@ queryType = Out.ObjectType "Query" Nothing [] $ HashMap.singleton "id" $ In.Argument Nothing (In.NamedScalarType id) Nothing philosopherResolver = pure $ Object mempty - genresField = + throwingField = let fieldType = Out.ListType $ Out.NonNullScalarType string in Out.Field Nothing fieldType HashMap.empty - genresResolver :: Resolve IO - genresResolver = throwM PhilosopherException + throwingResolver :: Resolve IO + throwingResolver = throwM PhilosopherException countField = let fieldType = Out.NonNullScalarType int in Out.Field Nothing fieldType HashMap.empty countResolver = pure "" + sequenceField = + let fieldType = Out.ListType $ Out.NonNullScalarType int + in Out.Field Nothing fieldType HashMap.empty + sequenceResolver = pure intSequence + +intSequence :: Value +intSequence = Type.List [Type.Int 1, Type.Int 2, Type.Int 3] musicType :: Out.ObjectType IO musicType = Out.ObjectType "Music" Nothing [] @@ -344,14 +352,14 @@ spec = in sourceQuery `shouldResolveTo` expected it "gives location information for failed result coercion" $ - let data'' = Object $ HashMap.singleton "genres" Null + let data'' = Object $ HashMap.singleton "throwing" Null executionErrors = pure $ Error { message = "PhilosopherException" , locations = [Location 1 3] - , path = [Segment "genres"] + , path = [Segment "throwing"] } expected = Response data'' executionErrors - sourceQuery = "{ genres }" + sourceQuery = "{ throwing }" in sourceQuery `shouldResolveTo` expected it "sets data to null if a root field isn't nullable" $ @@ -375,6 +383,12 @@ spec = sourceQuery = "{ philosopher(id: \"1\") { firstLanguage } }" in sourceQuery `shouldResolveTo` expected + it "returns list elements in the original order" $ + let data'' = Object $ HashMap.singleton "sequence" intSequence + expected = Response data'' mempty + sourceQuery = "{ sequence }" + in sourceQuery `shouldResolveTo` expected + context "queryError" $ do let namedQuery name = "query " <> name <> " { philosopher(id: \"1\") { interest } }" twoQueries = namedQuery "A" <> " " <> namedQuery "B" |
