Implement Show class for GraphQL type definitions
.. in the `Type` modules.
This commit is contained in:
		| @@ -13,6 +13,7 @@ and this project adheres to | |||||||
|   - `possibleFragmentSpreadsRule` |   - `possibleFragmentSpreadsRule` | ||||||
| - `Type.Schema.implementations` contains a map from interfaces and objects to | - `Type.Schema.implementations` contains a map from interfaces and objects to | ||||||
|   interfaces they implement. |   interfaces they implement. | ||||||
|  | - Show instances for GraphQL type definitions in the `Type` modules. | ||||||
|  |  | ||||||
| ## [0.11.0.0] - 2020-11-07 | ## [0.11.0.0] - 2020-11-07 | ||||||
| ### Changed | ### Changed | ||||||
|   | |||||||
| @@ -22,6 +22,7 @@ import Data.HashMap.Strict (HashMap) | |||||||
| import qualified Data.HashMap.Strict as HashMap | import qualified Data.HashMap.Strict as HashMap | ||||||
| import Data.String (IsString(..)) | import Data.String (IsString(..)) | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
|  | import qualified Data.Text as Text | ||||||
| import Language.GraphQL.AST (Name) | import Language.GraphQL.AST (Name) | ||||||
| import Prelude hiding (id) | import Prelude hiding (id) | ||||||
|  |  | ||||||
| @@ -63,6 +64,9 @@ data ScalarType = ScalarType Name (Maybe Text) | |||||||
| instance Eq ScalarType where | instance Eq ScalarType where | ||||||
|     (ScalarType this _) == (ScalarType that _) = this == that |     (ScalarType this _) == (ScalarType that _) = this == that | ||||||
|  |  | ||||||
|  | instance Show ScalarType where | ||||||
|  |     show (ScalarType typeName _) = Text.unpack typeName | ||||||
|  |  | ||||||
| -- | Enum type definition. | -- | Enum type definition. | ||||||
| -- | -- | ||||||
| -- Some leaf values of requests and input values are Enums. GraphQL serializes | -- 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 | instance Eq EnumType where | ||||||
|     (EnumType this _ _) == (EnumType that _ _) = this == that |     (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'. | -- | Enum value is a single member of an 'EnumType'. | ||||||
| newtype EnumValue = EnumValue (Maybe Text) | newtype EnumValue = EnumValue (Maybe Text) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -24,6 +24,7 @@ module Language.GraphQL.Type.In | |||||||
|  |  | ||||||
| import Data.HashMap.Strict (HashMap) | import Data.HashMap.Strict (HashMap) | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
|  | import qualified Data.Text as Text | ||||||
| import Language.GraphQL.AST.Document (Name) | import Language.GraphQL.AST.Document (Name) | ||||||
| import qualified Language.GraphQL.Type.Definition as Definition | import qualified Language.GraphQL.Type.Definition as Definition | ||||||
|  |  | ||||||
| @@ -40,6 +41,9 @@ data InputObjectType = InputObjectType | |||||||
| instance Eq InputObjectType where | instance Eq InputObjectType where | ||||||
|     (InputObjectType this _ _) == (InputObjectType that _ _) = this == that |     (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. | -- | These types may be used as input types for arguments and directives. | ||||||
| -- | -- | ||||||
| -- GraphQL distinguishes between "wrapping" and "named" types. Each wrapping | -- GraphQL distinguishes between "wrapping" and "named" types. Each wrapping | ||||||
| @@ -56,6 +60,16 @@ data Type | |||||||
|     | NonNullListType Type |     | NonNullListType Type | ||||||
|     deriving Eq |     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. | -- | Field argument definition. | ||||||
| data Argument = Argument (Maybe Text) Type (Maybe Definition.Value) | data Argument = Argument (Maybe Text) Type (Maybe Definition.Value) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -38,6 +38,7 @@ import Data.HashMap.Strict (HashMap) | |||||||
| import qualified Data.HashMap.Strict as HashMap | import qualified Data.HashMap.Strict as HashMap | ||||||
| import Data.Maybe (fromMaybe) | import Data.Maybe (fromMaybe) | ||||||
| import Data.Text (Text) | import Data.Text (Text) | ||||||
|  | import qualified Data.Text as Text | ||||||
| import Language.GraphQL.AST (Name) | import Language.GraphQL.AST (Name) | ||||||
| import Language.GraphQL.Type.Definition | import Language.GraphQL.Type.Definition | ||||||
| import qualified Language.GraphQL.Type.In as In | import qualified Language.GraphQL.Type.In as In | ||||||
| @@ -52,6 +53,9 @@ data ObjectType m = ObjectType | |||||||
| instance forall a. Eq (ObjectType a) where | instance forall a. Eq (ObjectType a) where | ||||||
|     (ObjectType this _ _ _) == (ObjectType that _ _ _) = this == that |     (ObjectType this _ _ _) == (ObjectType that _ _ _) = this == that | ||||||
|  |  | ||||||
|  | instance forall a. Show (ObjectType a) where | ||||||
|  |     show (ObjectType typeName _ _ _) = Text.unpack typeName | ||||||
|  |  | ||||||
| -- | Interface Type Definition. | -- | Interface Type Definition. | ||||||
| -- | -- | ||||||
| -- When a field can return one of a heterogeneous set of types, a Interface type | -- 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 | instance forall a. Eq (InterfaceType a) where | ||||||
|     (InterfaceType this _ _ _) == (InterfaceType that _ _ _) = this == that |     (InterfaceType this _ _ _) == (InterfaceType that _ _ _) = this == that | ||||||
|  |  | ||||||
|  | instance forall a. Show (InterfaceType a) where | ||||||
|  |     show (InterfaceType typeName _ _ _) = Text.unpack typeName | ||||||
|  |  | ||||||
| -- | Union Type Definition. | -- | Union Type Definition. | ||||||
| -- | -- | ||||||
| -- When a field can return one of a heterogeneous set of types, a Union type is | -- 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 | instance forall a. Eq (UnionType a) where | ||||||
|     (UnionType this _ _) == (UnionType that _ _) = this == that |     (UnionType this _ _) == (UnionType that _ _) = this == that | ||||||
|  |  | ||||||
|  | instance forall a. Show (UnionType a) where | ||||||
|  |     show (UnionType typeName _ _) = Text.unpack typeName | ||||||
|  |  | ||||||
| -- | Output object field definition. | -- | Output object field definition. | ||||||
| data Field m = Field | data Field m = Field | ||||||
|     (Maybe Text) -- ^ Description. |     (Maybe Text) -- ^ Description. | ||||||
| @@ -98,6 +108,20 @@ data Type m | |||||||
|     | NonNullListType (Type m) |     | NonNullListType (Type m) | ||||||
|     deriving Eq |     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'. | -- | Matches either 'NamedScalarType' or 'NonNullScalarType'. | ||||||
| pattern ScalarBaseType :: forall m. ScalarType -> Type m | pattern ScalarBaseType :: forall m. ScalarType -> Type m | ||||||
| pattern ScalarBaseType scalarType <- (isScalarType -> Just scalarType) | pattern ScalarBaseType scalarType <- (isScalarType -> Just scalarType) | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| resolver: lts-16.22 | resolver: lts-16.26 | ||||||
|  |  | ||||||
| packages: | packages: | ||||||
| - . | - . | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user