Encode input object types

This commit is contained in:
Eugen Wissner 2023-01-10 09:53:18 +01:00
parent 025331a9ee
commit 9021f3a25d
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 36 additions and 1 deletions

View File

@ -106,6 +106,17 @@ argumentDefinition formatter definition' =
<> maybe mempty (defaultValue formatter . Full.node) defaultValue' <> maybe mempty (defaultValue formatter . Full.node) defaultValue'
<> directives formatter directives' <> directives formatter directives'
inputValueDefinition :: Formatter -> Full.InputValueDefinition -> Lazy.Text.Text
inputValueDefinition formatter definition' =
let Full.InputValueDefinition description' name' type'' defaultValue' directives' = definition'
in optempty (description formatter) description'
<> indentLine formatter
<> Lazy.Text.fromStrict name'
<> colon formatter
<> type' type''
<> maybe mempty (defaultValue formatter . Full.node) defaultValue'
<> directives formatter directives'
typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text
typeDefinition formatter = \case typeDefinition formatter = \case
Full.ScalarTypeDefinition description' name' directives' Full.ScalarTypeDefinition description' name' directives'
@ -142,7 +153,13 @@ typeDefinition formatter = \case
<> optempty (directives formatter) directives' <> optempty (directives formatter) directives'
<> eitherFormat formatter " " "" <> eitherFormat formatter " " ""
<> bracesList formatter (enumValueDefinition formatter) members' <> bracesList formatter (enumValueDefinition formatter) members'
_typeDefinition' -> "" -- TODO: Types missing. Full.InputObjectTypeDefinition description' name' directives' fields'
-> optempty (description formatter) description'
<> "input "
<> Lazy.Text.fromStrict name'
<> optempty (directives formatter) directives'
<> eitherFormat formatter " " ""
<> bracesList formatter (inputValueDefinition nextFormatter) fields'
where where
nextFormatter = incrementIndent formatter nextFormatter = incrementIndent formatter

View File

@ -249,3 +249,21 @@ spec = do
|] |]
actual = typeSystemDefinition pretty definition' actual = typeSystemDefinition pretty definition'
in actual `shouldBe` expected in actual `shouldBe` expected
it "encodes an input type" $
let intType = Full.TypeNonNull $ Full.NonNullTypeNamed "Int"
stringType = Full.TypeNamed "String"
fields =
[ Full.InputValueDefinition mempty "a" stringType Nothing mempty
, Full.InputValueDefinition mempty "b" intType Nothing mempty
]
definition' = Full.TypeDefinition
$ Full.InputObjectTypeDefinition mempty "ExampleInputObject" mempty fields
expected = [gql|
input ExampleInputObject {
a: String
b: Int!
}
|]
actual = typeSystemDefinition pretty definition'
in actual `shouldBe` expected