diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-12-17 20:42:47 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-12-17 20:42:47 +0100 |
| commit | 5a6709030ceee63adb417c0fa2d2abce24c5d5cb (patch) | |
| tree | dd5c58238b7a0c6652b43c1136e352ab013bb10a | |
| parent | 2bcae9e0a7657ddb261328caadc884c57992f304 (diff) | |
| download | graphql-5a6709030ceee63adb417c0fa2d2abce24c5d5cb.tar.gz | |
Add show instances for AST type representation
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 13 |
2 files changed, 12 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec77ec..d35a35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to - `Type.Schema.implementations` contains a map from interfaces and objects to interfaces they implement. - Show instances for GraphQL type definitions in the `Type` modules. +- Custom Show instances for the type representation in the AST. ## [0.11.0.0] - 2020-11-07 ### Changed diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index b30271c..a134f35 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -281,7 +281,12 @@ data Type = TypeNamed Name | TypeList Type | TypeNonNull NonNullType - deriving (Eq, Show) + deriving Eq + +instance Show Type where + show (TypeNamed typeName) = Text.unpack typeName + show (TypeList listType) = concat ["[", show listType, "]"] + show (TypeNonNull nonNullType) = show nonNullType -- | Represents type names. type NamedType = Name @@ -290,7 +295,11 @@ type NamedType = Name data NonNullType = NonNullTypeNamed Name | NonNullTypeList Type - deriving (Eq, Show) + deriving Eq + +instance Show NonNullType where + show (NonNullTypeNamed typeName) = '!' : Text.unpack typeName + show (NonNullTypeList listType) = concat ["![", show listType, "]"] -- ** Directives |
