diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-01-08 17:33:25 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-01-08 17:33:25 +0100 |
| commit | ab4808c44de3e5cda60887ede92c8cff0d62ee90 (patch) | |
| tree | 10cebe0fddd0377bc4e6d7259322ec0d67fcea32 /src | |
| parent | bb4375313e91f4a4b8cf01e41ba25fd248fc392f (diff) | |
| download | graphql-ab4808c44de3e5cda60887ede92c8cff0d62ee90.tar.gz | |
Encode unions
Diffstat (limited to 'src')
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index bd6dab8..ab17929 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -128,6 +128,13 @@ typeDefinition formatter = \case <> optempty (directives formatter) directives' <> eitherFormat formatter " " "" <> bracesList formatter (fieldDefinition nextFormatter) fields' + Full.UnionTypeDefinition description' name' directives' members' + -> optempty (description formatter) description' + <> "union " + <> Lazy.Text.fromStrict name' + <> optempty (directives formatter) directives' + <> eitherFormat formatter " " "" + <> unionMemberTypes formatter members' _typeDefinition' -> "" -- TODO: Types missing. where nextFormatter = incrementIndent formatter @@ -136,10 +143,23 @@ implementsInterfaces :: Foldable t => Full.ImplementsInterfaces t -> Lazy.Text implementsInterfaces (Full.ImplementsInterfaces interfaces) | null interfaces = mempty | otherwise = Lazy.Text.fromStrict - $ Text.append "implements" + $ Text.append "implements " $ Text.intercalate " & " $ toList interfaces +unionMemberTypes :: Foldable t => Formatter -> Full.UnionMemberTypes t -> Lazy.Text +unionMemberTypes formatter (Full.UnionMemberTypes memberTypes) + | null memberTypes = mempty + | Minified <- formatter = Lazy.Text.fromStrict + $ Text.append "= " + $ Text.intercalate " | " + $ toList memberTypes + | Pretty _ <- formatter + = Lazy.Text.append "=" + $ Lazy.Text.concat + $ (("\n" <> indentSymbol <> "| ") <>) . Lazy.Text.fromStrict + <$> toList memberTypes + description :: Formatter -> Full.Description -> Lazy.Text.Text description _formatter (Full.Description Nothing) = "" description formatter (Full.Description (Just description')) = |
