Encode object type definitions
This commit is contained in:
parent
70dedb6911
commit
bb4375313e
@ -18,7 +18,7 @@ module Language.GraphQL.AST.Encoder
|
|||||||
, value
|
, value
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Foldable (fold)
|
import Data.Foldable (fold, Foldable (..))
|
||||||
import qualified Data.List.NonEmpty as NonEmpty
|
import qualified Data.List.NonEmpty as NonEmpty
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
@ -106,13 +106,21 @@ argumentDefinition formatter definition' =
|
|||||||
<> maybe mempty (defaultValue formatter . Full.node) defaultValue'
|
<> maybe mempty (defaultValue formatter . Full.node) defaultValue'
|
||||||
<> directives formatter directives'
|
<> directives formatter directives'
|
||||||
|
|
||||||
typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text.Text
|
typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text
|
||||||
typeDefinition formatter = \case
|
typeDefinition formatter = \case
|
||||||
Full.ScalarTypeDefinition description' name' directives'
|
Full.ScalarTypeDefinition description' name' directives'
|
||||||
-> optempty (description formatter) description'
|
-> optempty (description formatter) description'
|
||||||
<> "scalar "
|
<> "scalar "
|
||||||
<> Lazy.Text.fromStrict name'
|
<> Lazy.Text.fromStrict name'
|
||||||
<> optempty (directives formatter) directives'
|
<> 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'
|
Full.InterfaceTypeDefinition description' name' directives' fields'
|
||||||
-> optempty (description formatter) description'
|
-> optempty (description formatter) description'
|
||||||
<> "interface "
|
<> "interface "
|
||||||
@ -124,6 +132,14 @@ typeDefinition formatter = \case
|
|||||||
where
|
where
|
||||||
nextFormatter = incrementIndent formatter
|
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 -> Lazy.Text.Text
|
||||||
description _formatter (Full.Description Nothing) = ""
|
description _formatter (Full.Description Nothing) = ""
|
||||||
description formatter (Full.Description (Just description')) =
|
description formatter (Full.Description (Just description')) =
|
||||||
|
Loading…
Reference in New Issue
Block a user