Encode enums
This commit is contained in:
parent
ab4808c44d
commit
025331a9ee
@ -135,6 +135,13 @@ typeDefinition formatter = \case
|
|||||||
<> optempty (directives formatter) directives'
|
<> optempty (directives formatter) directives'
|
||||||
<> eitherFormat formatter " " ""
|
<> eitherFormat formatter " " ""
|
||||||
<> unionMemberTypes formatter members'
|
<> unionMemberTypes formatter members'
|
||||||
|
Full.EnumTypeDefinition description' name' directives' members'
|
||||||
|
-> optempty (description formatter) description'
|
||||||
|
<> "enum "
|
||||||
|
<> Lazy.Text.fromStrict name'
|
||||||
|
<> optempty (directives formatter) directives'
|
||||||
|
<> eitherFormat formatter " " ""
|
||||||
|
<> bracesList formatter (enumValueDefinition formatter) members'
|
||||||
_typeDefinition' -> "" -- TODO: Types missing.
|
_typeDefinition' -> "" -- TODO: Types missing.
|
||||||
where
|
where
|
||||||
nextFormatter = incrementIndent formatter
|
nextFormatter = incrementIndent formatter
|
||||||
@ -160,6 +167,20 @@ unionMemberTypes formatter (Full.UnionMemberTypes memberTypes)
|
|||||||
$ (("\n" <> indentSymbol <> "| ") <>) . Lazy.Text.fromStrict
|
$ (("\n" <> indentSymbol <> "| ") <>) . Lazy.Text.fromStrict
|
||||||
<$> toList memberTypes
|
<$> toList memberTypes
|
||||||
|
|
||||||
|
enumValueDefinition :: Formatter -> Full.EnumValueDefinition -> Lazy.Text
|
||||||
|
enumValueDefinition (Pretty _) enumValue =
|
||||||
|
let Full.EnumValueDefinition description' name' directives' = enumValue
|
||||||
|
formatter = Pretty 1
|
||||||
|
in description formatter description'
|
||||||
|
<> indentLine formatter
|
||||||
|
<> Lazy.Text.fromStrict name'
|
||||||
|
<> directives formatter directives'
|
||||||
|
enumValueDefinition Minified enumValue =
|
||||||
|
let Full.EnumValueDefinition description' name' directives' = enumValue
|
||||||
|
in description Minified description'
|
||||||
|
<> Lazy.Text.fromStrict name'
|
||||||
|
<> directives Minified directives'
|
||||||
|
|
||||||
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')) =
|
||||||
|
@ -218,7 +218,7 @@ spec = do
|
|||||||
actual = typeSystemDefinition pretty definition'
|
actual = typeSystemDefinition pretty definition'
|
||||||
in actual `shouldBe` expected
|
in actual `shouldBe` expected
|
||||||
|
|
||||||
it "encodes an enum definition" $
|
it "encodes an union definition" $
|
||||||
let definition' = Full.TypeDefinition
|
let definition' = Full.TypeDefinition
|
||||||
$ Full.UnionTypeDefinition mempty "SearchResult" mempty
|
$ Full.UnionTypeDefinition mempty "SearchResult" mempty
|
||||||
$ Full.UnionMemberTypes ["Photo", "Person"]
|
$ Full.UnionMemberTypes ["Photo", "Person"]
|
||||||
@ -229,3 +229,23 @@ spec = do
|
|||||||
|]
|
|]
|
||||||
actual = typeSystemDefinition pretty definition'
|
actual = typeSystemDefinition pretty definition'
|
||||||
in actual `shouldBe` expected
|
in actual `shouldBe` expected
|
||||||
|
|
||||||
|
it "encodes an enum definition" $
|
||||||
|
let values =
|
||||||
|
[ Full.EnumValueDefinition mempty "NORTH" mempty
|
||||||
|
, Full.EnumValueDefinition mempty "EAST" mempty
|
||||||
|
, Full.EnumValueDefinition mempty "SOUTH" mempty
|
||||||
|
, Full.EnumValueDefinition mempty "WEST" mempty
|
||||||
|
]
|
||||||
|
definition' = Full.TypeDefinition
|
||||||
|
$ Full.EnumTypeDefinition mempty "Direction" mempty values
|
||||||
|
expected = [gql|
|
||||||
|
enum Direction {
|
||||||
|
NORTH
|
||||||
|
EAST
|
||||||
|
SOUTH
|
||||||
|
WEST
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
actual = typeSystemDefinition pretty definition'
|
||||||
|
in actual `shouldBe` expected
|
||||||
|
Loading…
Reference in New Issue
Block a user