summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL/AST/Encoder.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-01-03 13:10:33 +0100
committerEugen Wissner <belka@caraus.de>2023-01-03 13:10:33 +0100
commitbb4375313e91f4a4b8cf01e41ba25fd248fc392f (patch)
tree12748fef8ce7c854ebc1635598f6c267f4186c48 /src/Language/GraphQL/AST/Encoder.hs
parent70dedb691120b44fe13cd22eab62928f872c468b (diff)
downloadgraphql-bb4375313e91f4a4b8cf01e41ba25fd248fc392f.tar.gz
Encode object type definitions
Diffstat (limited to 'src/Language/GraphQL/AST/Encoder.hs')
-rw-r--r--src/Language/GraphQL/AST/Encoder.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs
index 8dddd1f..bd6dab8 100644
--- a/src/Language/GraphQL/AST/Encoder.hs
+++ b/src/Language/GraphQL/AST/Encoder.hs
@@ -18,7 +18,7 @@ module Language.GraphQL.AST.Encoder
, value
) where
-import Data.Foldable (fold)
+import Data.Foldable (fold, Foldable (..))
import qualified Data.List.NonEmpty as NonEmpty
import Data.Text (Text)
import qualified Data.Text as Text
@@ -106,13 +106,21 @@ argumentDefinition formatter definition' =
<> maybe mempty (defaultValue formatter . Full.node) defaultValue'
<> directives formatter directives'
-typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text.Text
+typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text
typeDefinition formatter = \case
Full.ScalarTypeDefinition description' name' directives'
-> optempty (description formatter) description'
<> "scalar "
<> Lazy.Text.fromStrict name'
<> optempty (directives formatter) directives'
+ Full.ObjectTypeDefinition description' name' ifaces' directives' fields'
+ -> optempty (description formatter) description'
+ <> "type "
+ <> Lazy.Text.fromStrict name'
+ <> optempty (" " <>) (implementsInterfaces ifaces')
+ <> optempty (directives formatter) directives'
+ <> eitherFormat formatter " " ""
+ <> bracesList formatter (fieldDefinition nextFormatter) fields'
Full.InterfaceTypeDefinition description' name' directives' fields'
-> optempty (description formatter) description'
<> "interface "
@@ -124,6 +132,14 @@ typeDefinition formatter = \case
where
nextFormatter = incrementIndent formatter
+implementsInterfaces :: Foldable t => Full.ImplementsInterfaces t -> Lazy.Text
+implementsInterfaces (Full.ImplementsInterfaces interfaces)
+ | null interfaces = mempty
+ | otherwise = Lazy.Text.fromStrict
+ $ Text.append "implements"
+ $ Text.intercalate " & "
+ $ toList interfaces
+
description :: Formatter -> Full.Description -> Lazy.Text.Text
description _formatter (Full.Description Nothing) = ""
description formatter (Full.Description (Just description')) =