diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-02-26 09:43:43 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-02-26 09:43:43 +0100 |
| commit | 2834360411d41f8d7cb22d914d5cb914d928d51f (patch) | |
| tree | 00f47e28747e3fa8f32f1582a29f12922f8fdac9 /src/Language/GraphQL/Execute/Coerce.hs | |
| parent | 83f2dc1a2d4820a9d58618ff4d3724db420fe3b6 (diff) | |
| download | graphql-2834360411d41f8d7cb22d914d5cb914d928d51f.tar.gz | |
Remove JSON support in the core package
Diffstat (limited to 'src/Language/GraphQL/Execute/Coerce.hs')
| -rw-r--r-- | src/Language/GraphQL/Execute/Coerce.hs | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/Language/GraphQL/Execute/Coerce.hs b/src/Language/GraphQL/Execute/Coerce.hs index 4725d74..54fc1c1 100644 --- a/src/Language/GraphQL/Execute/Coerce.hs +++ b/src/Language/GraphQL/Execute/Coerce.hs @@ -5,14 +5,8 @@ {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE CPP #-} -- | Types and functions used for input and result coercion. --- --- JSON instances in this module are only available with the __json__ --- flag that is currently on by default, but will be disabled in the future. --- Refer to the documentation in the 'Language.GraphQL' module and to --- the __graphql-spice__ package. module Language.GraphQL.Execute.Coerce ( Output(..) , Serialize(..) @@ -21,10 +15,6 @@ module Language.GraphQL.Execute.Coerce , matchFieldValues ) where -#ifdef WITH_JSON -import qualified Data.Aeson as Aeson -import Data.Scientific (toBoundedInteger, toRealFloat) -#endif import Data.Int (Int32) import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HashMap @@ -232,69 +222,3 @@ instance Serialize Type.Value where $ HashMap.fromList $ OrderedMap.toList object serialize _ _ = Nothing - -#ifdef WITH_JSON -instance Serialize Aeson.Value where - serialize (Out.ScalarBaseType scalarType) value - | Type.ScalarType "Int" _ <- scalarType - , Int int <- value = Just $ Aeson.toJSON int - | Type.ScalarType "Float" _ <- scalarType - , Float float <- value = Just $ Aeson.toJSON float - | Type.ScalarType "String" _ <- scalarType - , String string <- value = Just $ Aeson.String string - | Type.ScalarType "ID" _ <- scalarType - , String string <- value = Just $ Aeson.String string - | Type.ScalarType "Boolean" _ <- scalarType - , Boolean boolean <- value = Just $ Aeson.Bool boolean - serialize _ (Enum enum) = Just $ Aeson.String enum - serialize _ (List list) = Just $ Aeson.toJSON list - serialize _ (Object object) = Just - $ Aeson.object - $ OrderedMap.toList - $ Aeson.toJSON <$> object - serialize _ _ = Nothing - null = Aeson.Null - -instance VariableValue Aeson.Value where - coerceVariableValue _ Aeson.Null = Just Type.Null - coerceVariableValue (In.ScalarBaseType scalarType) value - | (Aeson.String stringValue) <- value = Just $ Type.String stringValue - | (Aeson.Bool booleanValue) <- value = Just $ Type.Boolean booleanValue - | (Aeson.Number numberValue) <- value - , (Type.ScalarType "Float" _) <- scalarType = - Just $ Type.Float $ toRealFloat numberValue - | (Aeson.Number numberValue) <- value = -- ID or Int - Type.Int <$> toBoundedInteger numberValue - coerceVariableValue (In.EnumBaseType _) (Aeson.String stringValue) = - Just $ Type.Enum stringValue - coerceVariableValue (In.InputObjectBaseType objectType) value - | (Aeson.Object objectValue) <- value = do - let (In.InputObjectType _ _ inputFields) = objectType - (newObjectValue, resultMap) <- foldWithKey objectValue inputFields - if HashMap.null newObjectValue - then Just $ Type.Object resultMap - else Nothing - where - foldWithKey objectValue = HashMap.foldrWithKey matchFieldValues' - $ Just (objectValue, HashMap.empty) - matchFieldValues' _ _ Nothing = Nothing - matchFieldValues' fieldName inputField (Just (objectValue, resultMap)) = - let (In.InputField _ fieldType _) = inputField - insert = flip (HashMap.insert fieldName) resultMap - newObjectValue = HashMap.delete fieldName objectValue - in case HashMap.lookup fieldName objectValue of - Just variableValue -> do - coerced <- coerceVariableValue fieldType variableValue - pure (newObjectValue, insert coerced) - Nothing -> Just (objectValue, resultMap) - coerceVariableValue (In.ListBaseType listType) value - | (Aeson.Array arrayValue) <- value = - Type.List <$> foldr foldVector (Just []) arrayValue - | otherwise = coerceVariableValue listType value - where - foldVector _ Nothing = Nothing - foldVector variableValue (Just list) = do - coerced <- coerceVariableValue listType variableValue - pure $ coerced : list - coerceVariableValue _ _ = Nothing -#endif |
