summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-11-08 20:05:51 +0100
committerEugen Wissner <belka@caraus.de>2023-11-08 20:08:47 +0100
commita961b168dbc0d594dab4eb38e14f0295af6d69b4 (patch)
treec2f564c0cdecd1dcea0e37b9525ee01a33b369ea
parenta1cda38e20ae42ce771b056a1067eff75a0f25ad (diff)
downloadgraphql-a961b168dbc0d594dab4eb38e14f0295af6d69b4.tar.gz
Add a test for the input object coercion issue
-rw-r--r--CHANGELOG.md1
-rw-r--r--graphql.cabal2
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs43
3 files changed, 33 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 08ee22d..3a87e7e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to
### Fixed
- `gql` removes not only leading `\n` but also `\r`.
- Fix non nullable type string representation in executor error messages.
+- Fix input objects not being coerced to lists.
## [1.2.0.1] - 2023-04-25
### Fixed
diff --git a/graphql.cabal b/graphql.cabal
index 104b757..63498d9 100644
--- a/graphql.cabal
+++ b/graphql.cabal
@@ -21,7 +21,7 @@ extra-source-files:
CHANGELOG.md
README.md
tested-with:
- GHC == 9.2.8,
+ GHC == 9.4.7,
GHC == 9.6.3
source-repository head
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index 58e0187..52bd410 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -69,6 +69,7 @@ queryType = Out.ObjectType "Query" Nothing []
, ("throwing", ValueResolver throwingField throwingResolver)
, ("count", ValueResolver countField countResolver)
, ("sequence", ValueResolver sequenceField sequenceResolver)
+ , ("withInputObject", ValueResolver withInputObjectField withInputObjectResolver)
]
where
philosopherField =
@@ -89,6 +90,17 @@ queryType = Out.ObjectType "Query" Nothing []
let fieldType = Out.ListType $ Out.NonNullScalarType int
in Out.Field Nothing fieldType HashMap.empty
sequenceResolver = pure intSequence
+ withInputObjectResolver = pure $ Type.Int 0
+ withInputObjectField =
+ Out.Field Nothing (Out.NonNullScalarType int) $ HashMap.fromList
+ [("values", In.Argument Nothing withInputObjectArgumentType Nothing)]
+ withInputObjectArgumentType = In.NonNullListType
+ $ In.NonNullInputObjectType inputObjectType
+
+inputObjectType :: In.InputObjectType
+inputObjectType = In.InputObjectType "InputObject" Nothing $
+ HashMap.singleton "name" $
+ In.InputField Nothing (In.NonNullScalarType int) Nothing
intSequence :: Value
intSequence = Type.List [Type.Int 1, Type.Int 2, Type.Int 3]
@@ -328,18 +340,6 @@ spec =
sourceQuery = "{ philosopher { majorWork { title } } }"
in sourceQuery `shouldResolveTo` expected
- it "gives location information for invalid scalar arguments" $
- let data'' = Object $ HashMap.singleton "philosopher" Null
- executionErrors = pure $ Error
- { message =
- "Argument \"id\" has invalid type. Expected type ID, found: True."
- , locations = [Location 1 15]
- , path = [Segment "philosopher"]
- }
- expected = Response data'' executionErrors
- sourceQuery = "{ philosopher(id: true) { lastName } }"
- in sourceQuery `shouldResolveTo` expected
-
it "gives location information for failed result coercion" $
let data'' = Object $ HashMap.singleton "philosopher" Null
executionErrors = pure $ Error
@@ -389,6 +389,25 @@ spec =
sourceQuery = "{ sequence }"
in sourceQuery `shouldResolveTo` expected
+ context "Arguments" $ do
+ it "gives location information for invalid scalar arguments" $
+ let data'' = Object $ HashMap.singleton "philosopher" Null
+ executionErrors = pure $ Error
+ { message =
+ "Argument \"id\" has invalid type. Expected type ID, found: True."
+ , locations = [Location 1 15]
+ , path = [Segment "philosopher"]
+ }
+ expected = Response data'' executionErrors
+ sourceQuery = "{ philosopher(id: true) { lastName } }"
+ in sourceQuery `shouldResolveTo` expected
+
+ it "puts an object in a list if needed" $
+ let data'' = Object $ HashMap.singleton "withInputObject" $ Type.Int 0
+ expected = Response data'' mempty
+ sourceQuery = "{ withInputObject(values: { name: 0 }) }"
+ in sourceQuery `shouldResolveTo` expected
+
context "queryError" $ do
let namedQuery name = "query " <> name <> " { philosopher(id: \"1\") { interest } }"
twoQueries = namedQuery "A" <> " " <> namedQuery "B"