From f6ff0ab9c785273e3ceeac6b9d636c5ec519a008 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 7 Sep 2020 22:01:49 +0200 Subject: Validate fragments on composite types --- src/Language/GraphQL/AST/Encoder.hs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/Language/GraphQL/AST/Encoder.hs') diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index 7428365..0757867 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -128,10 +128,10 @@ selection formatter = Lazy.Text.append indent' . encodeSelection where encodeSelection (Field alias name args directives' selections _) = field incrementIndent alias name args directives' selections - encodeSelection (InlineFragment typeCondition directives' selections _) = - inlineFragment incrementIndent typeCondition directives' selections - encodeSelection (FragmentSpread name directives' _) = - fragmentSpread incrementIndent name directives' + encodeSelection (InlineFragmentSelection fragmentSelection) = + inlineFragment incrementIndent fragmentSelection + encodeSelection (FragmentSpreadSelection fragmentSelection) = + fragmentSpread incrementIndent fragmentSelection incrementIndent | Pretty indentation <- formatter = Pretty $ indentation + 1 | otherwise = Minified @@ -172,22 +172,18 @@ argument formatter (Argument name value') -- * Fragments -fragmentSpread :: Formatter -> Name -> [Directive] -> Lazy.Text -fragmentSpread formatter name directives' +fragmentSpread :: Formatter -> FragmentSpread -> Lazy.Text +fragmentSpread formatter (FragmentSpread name directives' _) = "..." <> Lazy.Text.fromStrict name <> optempty (directives formatter) directives' -inlineFragment :: - Formatter -> - Maybe TypeCondition -> - [Directive] -> - SelectionSet -> - Lazy.Text -inlineFragment formatter tc dirs sels = "... on " - <> Lazy.Text.fromStrict (fold tc) - <> directives formatter dirs +inlineFragment :: Formatter -> InlineFragment -> Lazy.Text +inlineFragment formatter (InlineFragment typeCondition directives' selections _) + = "... on " + <> Lazy.Text.fromStrict (fold typeCondition) + <> directives formatter directives' <> eitherFormat formatter " " mempty - <> selectionSet formatter sels + <> selectionSet formatter selections fragmentDefinition :: Formatter -> FragmentDefinition -> Lazy.Text fragmentDefinition formatter (FragmentDefinition name tc dirs sels _) -- cgit v1.2.3