summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-12-14 22:36:27 +0100
committerEugen Wissner <belka@caraus.de>2020-12-14 22:36:27 +0100
commit2bcae9e0a7657ddb261328caadc884c57992f304 (patch)
tree58f7bac4eca240a85d6cc83cefd786a603e18297 /src/Language/GraphQL
parent2dbc985dfcaacdb198fe41e2e88123e8a982bd71 (diff)
downloadgraphql-2bcae9e0a7657ddb261328caadc884c57992f304.tar.gz
Implement Show class for GraphQL type definitions
.. in the `Type` modules.
Diffstat (limited to 'src/Language/GraphQL')
-rw-r--r--src/Language/GraphQL/Type/Definition.hs7
-rw-r--r--src/Language/GraphQL/Type/In.hs14
-rw-r--r--src/Language/GraphQL/Type/Out.hs24
3 files changed, 45 insertions, 0 deletions
diff --git a/src/Language/GraphQL/Type/Definition.hs b/src/Language/GraphQL/Type/Definition.hs
index 476fb3a..6ca77aa 100644
--- a/src/Language/GraphQL/Type/Definition.hs
+++ b/src/Language/GraphQL/Type/Definition.hs
@@ -22,6 +22,7 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.String (IsString(..))
import Data.Text (Text)
+import qualified Data.Text as Text
import Language.GraphQL.AST (Name)
import Prelude hiding (id)
@@ -63,6 +64,9 @@ data ScalarType = ScalarType Name (Maybe Text)
instance Eq ScalarType where
(ScalarType this _) == (ScalarType that _) = this == that
+instance Show ScalarType where
+ show (ScalarType typeName _) = Text.unpack typeName
+
-- | Enum type definition.
--
-- Some leaf values of requests and input values are Enums. GraphQL serializes
@@ -73,6 +77,9 @@ data EnumType = EnumType Name (Maybe Text) (HashMap Name EnumValue)
instance Eq EnumType where
(EnumType this _ _) == (EnumType that _ _) = this == that
+instance Show EnumType where
+ show (EnumType typeName _ _) = Text.unpack typeName
+
-- | Enum value is a single member of an 'EnumType'.
newtype EnumValue = EnumValue (Maybe Text)
diff --git a/src/Language/GraphQL/Type/In.hs b/src/Language/GraphQL/Type/In.hs
index 59a6d59..d42599b 100644
--- a/src/Language/GraphQL/Type/In.hs
+++ b/src/Language/GraphQL/Type/In.hs
@@ -24,6 +24,7 @@ module Language.GraphQL.Type.In
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
+import qualified Data.Text as Text
import Language.GraphQL.AST.Document (Name)
import qualified Language.GraphQL.Type.Definition as Definition
@@ -40,6 +41,9 @@ data InputObjectType = InputObjectType
instance Eq InputObjectType where
(InputObjectType this _ _) == (InputObjectType that _ _) = this == that
+instance Show InputObjectType where
+ show (InputObjectType typeName _ _) = Text.unpack typeName
+
-- | These types may be used as input types for arguments and directives.
--
-- GraphQL distinguishes between "wrapping" and "named" types. Each wrapping
@@ -56,6 +60,16 @@ data Type
| NonNullListType Type
deriving Eq
+instance Show Type where
+ show (NamedScalarType scalarType) = show scalarType
+ show (NamedEnumType enumType) = show enumType
+ show (NamedInputObjectType inputObjectType) = show inputObjectType
+ show (ListType baseType) = concat ["[", show baseType, "]"]
+ show (NonNullScalarType scalarType) = '!' : show scalarType
+ show (NonNullEnumType enumType) = '!' : show enumType
+ show (NonNullInputObjectType inputObjectType) = '!' : show inputObjectType
+ show (NonNullListType baseType) = concat ["![", show baseType, "]"]
+
-- | Field argument definition.
data Argument = Argument (Maybe Text) Type (Maybe Definition.Value)
diff --git a/src/Language/GraphQL/Type/Out.hs b/src/Language/GraphQL/Type/Out.hs
index b0668f5..847a8a5 100644
--- a/src/Language/GraphQL/Type/Out.hs
+++ b/src/Language/GraphQL/Type/Out.hs
@@ -38,6 +38,7 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe (fromMaybe)
import Data.Text (Text)
+import qualified Data.Text as Text
import Language.GraphQL.AST (Name)
import Language.GraphQL.Type.Definition
import qualified Language.GraphQL.Type.In as In
@@ -52,6 +53,9 @@ data ObjectType m = ObjectType
instance forall a. Eq (ObjectType a) where
(ObjectType this _ _ _) == (ObjectType that _ _ _) = this == that
+instance forall a. Show (ObjectType a) where
+ show (ObjectType typeName _ _ _) = Text.unpack typeName
+
-- | Interface Type Definition.
--
-- When a field can return one of a heterogeneous set of types, a Interface type
@@ -63,6 +67,9 @@ data InterfaceType m = InterfaceType
instance forall a. Eq (InterfaceType a) where
(InterfaceType this _ _ _) == (InterfaceType that _ _ _) = this == that
+instance forall a. Show (InterfaceType a) where
+ show (InterfaceType typeName _ _ _) = Text.unpack typeName
+
-- | Union Type Definition.
--
-- When a field can return one of a heterogeneous set of types, a Union type is
@@ -72,6 +79,9 @@ data UnionType m = UnionType Name (Maybe Text) [ObjectType m]
instance forall a. Eq (UnionType a) where
(UnionType this _ _) == (UnionType that _ _) = this == that
+instance forall a. Show (UnionType a) where
+ show (UnionType typeName _ _) = Text.unpack typeName
+
-- | Output object field definition.
data Field m = Field
(Maybe Text) -- ^ Description.
@@ -98,6 +108,20 @@ data Type m
| NonNullListType (Type m)
deriving Eq
+instance forall a. Show (Type a) where
+ show (NamedScalarType scalarType) = show scalarType
+ show (NamedEnumType enumType) = show enumType
+ show (NamedObjectType inputObjectType) = show inputObjectType
+ show (NamedInterfaceType interfaceType) = show interfaceType
+ show (NamedUnionType unionType) = show unionType
+ show (ListType baseType) = concat ["[", show baseType, "]"]
+ show (NonNullScalarType scalarType) = '!' : show scalarType
+ show (NonNullEnumType enumType) = '!' : show enumType
+ show (NonNullObjectType inputObjectType) = '!' : show inputObjectType
+ show (NonNullInterfaceType interfaceType) = '!' : show interfaceType
+ show (NonNullUnionType unionType) = '!' : show unionType
+ show (NonNullListType baseType) = concat ["![", show baseType, "]"]
+
-- | Matches either 'NamedScalarType' or 'NonNullScalarType'.
pattern ScalarBaseType :: forall m. ScalarType -> Type m
pattern ScalarBaseType scalarType <- (isScalarType -> Just scalarType)