summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/Execute
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-12-22 08:56:01 +0100
committerEugen Wissner <belka@caraus.de>2021-12-22 08:56:01 +0100
commitdf078a59d0ea80b383df251a789df8f6f539b072 (patch)
treebba30b1bf8810cf25131502e9043255f5328d384 /src/Language/GraphQL/Execute
parent930b8f10b7d083132c05c8d8fe39f337eeddbeca (diff)
downloadgraphql-df078a59d0ea80b383df251a789df8f6f539b072.tar.gz
Add Serialize and VariableValue value instances
- `Serialize` instance for `Type.Definition.Value`. - `VariableValue` instance for `Type.Definition.Value`. It makes it possible to use the library without an additional serialization format like JSON.
Diffstat (limited to 'src/Language/GraphQL/Execute')
-rw-r--r--src/Language/GraphQL/Execute/Coerce.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Execute/Coerce.hs b/src/Language/GraphQL/Execute/Coerce.hs
index f5ee204..9d5af96 100644
--- a/src/Language/GraphQL/Execute/Coerce.hs
+++ b/src/Language/GraphQL/Execute/Coerce.hs
@@ -3,6 +3,7 @@
obtain one at https://mozilla.org/MPL/2.0/. -}
{-# LANGUAGE ExplicitForAll #-}
+{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
@@ -61,6 +62,9 @@ class VariableValue a where
-> a -- ^ Variable value being coerced.
-> Maybe Type.Value -- ^ Coerced value on success, 'Nothing' otherwise.
+instance VariableValue Type.Value where
+ coerceVariableValue = const Just
+
instance VariableValue Aeson.Value where
coerceVariableValue _ Aeson.Null = Just Type.Null
coerceVariableValue (In.ScalarBaseType scalarType) value
@@ -216,6 +220,20 @@ data Output a
instance forall a. IsString (Output a) where
fromString = String . fromString
+instance Serialize Type.Value where
+ null = Type.Null
+ serialize _ = \case
+ Int int -> Just $ Type.Int int
+ Float float -> Just $ Type.Float float
+ String string -> Just $ Type.String string
+ Boolean boolean -> Just $ Type.Boolean boolean
+ Enum enum -> Just $ Type.Enum enum
+ List list -> Just $ Type.List list
+ Object object -> Just
+ $ Type.Object
+ $ HashMap.fromList
+ $ OrderedMap.toList object
+
instance Serialize Aeson.Value where
serialize (Out.ScalarBaseType scalarType) value
| Type.ScalarType "Int" _ <- scalarType