From 97d304d283ee9d26e9451be3e04ee6148df34e2d Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Tue, 10 Oct 2023 01:30:31 +0200 Subject: [PATCH] Fix values not being coerced to lists --- graphql.cabal | 2 ++ src/Language/GraphQL/Execute.hs | 41 +++++++++++++-------------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/graphql.cabal b/graphql.cabal index bcf69af..5bfa0fe 100644 --- a/graphql.cabal +++ b/graphql.cabal @@ -106,4 +106,6 @@ test-suite graphql-test unordered-containers, containers, vector + build-tool-depends: + hspec-discover:hspec-discover default-language: Haskell2010 diff --git a/src/Language/GraphQL/Execute.hs b/src/Language/GraphQL/Execute.hs index bbacdd2..10772e7 100644 --- a/src/Language/GraphQL/Execute.hs +++ b/src/Language/GraphQL/Execute.hs @@ -556,33 +556,24 @@ coerceArgumentValues argumentDefinitions argumentValues = $ Just inputValue | otherwise -> throwM $ InputCoercionException (Text.unpack argumentName) variableType Nothing + matchFieldValues' = matchFieldValues coerceArgumentValue $ Full.node <$> argumentValues - coerceArgumentValue inputType (Transform.Int integer) = - coerceInputLiteral inputType (Type.Int integer) - coerceArgumentValue inputType (Transform.Boolean boolean) = - coerceInputLiteral inputType (Type.Boolean boolean) - coerceArgumentValue inputType (Transform.String string) = - coerceInputLiteral inputType (Type.String string) - coerceArgumentValue inputType (Transform.Float float) = - coerceInputLiteral inputType (Type.Float float) - coerceArgumentValue inputType (Transform.Enum enum) = - coerceInputLiteral inputType (Type.Enum enum) - coerceArgumentValue inputType Transform.Null - | In.isNonNullType inputType = Nothing - | otherwise = coerceInputLiteral inputType Type.Null - coerceArgumentValue (In.ListBaseType inputType) (Transform.List list) = - let coerceItem = coerceArgumentValue inputType - in Type.List <$> traverse coerceItem list - coerceArgumentValue (In.InputObjectBaseType inputType) (Transform.Object object) - | In.InputObjectType _ _ inputFields <- inputType = - let go = forEachField object - resultMap = HashMap.foldrWithKey go (pure mempty) inputFields - in Type.Object <$> resultMap - coerceArgumentValue _ (Transform.Variable variable) = pure variable - coerceArgumentValue _ _ = Nothing - forEachField object variableName (In.InputField _ variableType defaultValue) = - matchFieldValues coerceArgumentValue object variableName variableType defaultValue + + coerceArgumentValue inputType transform = + coerceInputLiteral inputType $ extractArgumentValue transform + + extractArgumentValue (Transform.Int integer) = Type.Int integer + extractArgumentValue (Transform.Boolean boolean) = Type.Boolean boolean + extractArgumentValue (Transform.String string) = Type.String string + extractArgumentValue (Transform.Float float) = Type.Float float + extractArgumentValue (Transform.Enum enum) = Type.Enum enum + extractArgumentValue Transform.Null = Type.Null + extractArgumentValue (Transform.List list) = + Type.List $ extractArgumentValue <$> list + extractArgumentValue (Transform.Object object) = + Type.Object $ extractArgumentValue <$> object + extractArgumentValue (Transform.Variable variable) = variable collectFields :: Monad m => Out.ObjectType m