summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-01-10 09:53:18 +0100
committerEugen Wissner <belka@caraus.de>2023-01-10 09:53:18 +0100
commit9021f3a25d2b474160abae58cd98c4b6d08d87d0 (patch)
treeab75aadbade95707fbf645ae56b5241e6a9fbd58
parent025331a9ee07bd3080de6be0f5d514118052d1b5 (diff)
downloadgraphql-9021f3a25d2b474160abae58cd98c4b6d08d87d0.tar.gz
Encode input object types
-rw-r--r--src/Language/GraphQL/AST/Encoder.hs19
-rw-r--r--tests/Language/GraphQL/AST/EncoderSpec.hs18
2 files changed, 36 insertions, 1 deletions
diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs
index b5265cc..1ee0c6c 100644
--- a/src/Language/GraphQL/AST/Encoder.hs
+++ b/src/Language/GraphQL/AST/Encoder.hs
@@ -106,6 +106,17 @@ argumentDefinition formatter definition' =
<> maybe mempty (defaultValue formatter . Full.node) defaultValue'
<> 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 = \case
Full.ScalarTypeDefinition description' name' directives'
@@ -142,7 +153,13 @@ typeDefinition formatter = \case
<> optempty (directives formatter) directives'
<> eitherFormat formatter " " ""
<> 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
nextFormatter = incrementIndent formatter
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs
index a4ba470..3fa6a02 100644
--- a/tests/Language/GraphQL/AST/EncoderSpec.hs
+++ b/tests/Language/GraphQL/AST/EncoderSpec.hs
@@ -249,3 +249,21 @@ spec = do
|]
actual = typeSystemDefinition pretty definition'
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