forked from OSS/graphql
Encode directive definitions
This commit is contained in:
parent
9021f3a25d
commit
05fa5df558
@ -29,6 +29,7 @@ import qualified Data.Text.Lazy.Builder as Builder
|
|||||||
import Data.Text.Lazy.Builder.Int (decimal)
|
import Data.Text.Lazy.Builder.Int (decimal)
|
||||||
import Data.Text.Lazy.Builder.RealFloat (realFloat)
|
import Data.Text.Lazy.Builder.RealFloat (realFloat)
|
||||||
import qualified Language.GraphQL.AST.Document as Full
|
import qualified Language.GraphQL.AST.Document as Full
|
||||||
|
import qualified Language.GraphQL.AST.DirectiveLocation as DirectiveLocation
|
||||||
|
|
||||||
-- | Instructs the encoder whether the GraphQL document should be minified or
|
-- | Instructs the encoder whether the GraphQL document should be minified or
|
||||||
-- pretty printed.
|
-- pretty printed.
|
||||||
@ -59,6 +60,9 @@ document formatter defs
|
|||||||
typeSystemDefinition formatter typeSystemDefinition' : acc
|
typeSystemDefinition formatter typeSystemDefinition' : acc
|
||||||
executableDefinition _ acc = acc -- TODO: TypeSystemExtension missing.
|
executableDefinition _ acc = acc -- TODO: TypeSystemExtension missing.
|
||||||
|
|
||||||
|
directiveLocation :: DirectiveLocation.DirectiveLocation -> Lazy.Text
|
||||||
|
directiveLocation = Lazy.Text.pack . show
|
||||||
|
|
||||||
withLineBreak :: Formatter -> Lazy.Text.Text -> Lazy.Text.Text
|
withLineBreak :: Formatter -> Lazy.Text.Text -> Lazy.Text.Text
|
||||||
withLineBreak formatter encodeDefinition
|
withLineBreak formatter encodeDefinition
|
||||||
| Pretty _ <- formatter = Lazy.Text.snoc encodeDefinition '\n'
|
| Pretty _ <- formatter = Lazy.Text.snoc encodeDefinition '\n'
|
||||||
@ -73,7 +77,13 @@ typeSystemDefinition formatter = \case
|
|||||||
<> "schema "
|
<> "schema "
|
||||||
<> bracesList formatter operationTypeDefinition (NonEmpty.toList operationTypeDefinitions')
|
<> bracesList formatter operationTypeDefinition (NonEmpty.toList operationTypeDefinitions')
|
||||||
Full.TypeDefinition typeDefinition' -> typeDefinition formatter typeDefinition'
|
Full.TypeDefinition typeDefinition' -> typeDefinition formatter typeDefinition'
|
||||||
_ -> "" -- TODO: DerictiveDefinition missing.
|
Full.DirectiveDefinition description' name' arguments' locations
|
||||||
|
-> description formatter description'
|
||||||
|
<> "@"
|
||||||
|
<> Lazy.Text.fromStrict name' -- TODO: TypeSystemExtension missing.
|
||||||
|
<> argumentsDefinition formatter arguments'
|
||||||
|
<> " on"
|
||||||
|
<> pipeList formatter (directiveLocation <$> locations)
|
||||||
where
|
where
|
||||||
operationTypeDefinition (Full.OperationTypeDefinition operationType' namedType')
|
operationTypeDefinition (Full.OperationTypeDefinition operationType' namedType')
|
||||||
= indentLine (incrementIndent formatter)
|
= indentLine (incrementIndent formatter)
|
||||||
@ -174,16 +184,17 @@ implementsInterfaces (Full.ImplementsInterfaces interfaces)
|
|||||||
unionMemberTypes :: Foldable t => Formatter -> Full.UnionMemberTypes t -> Lazy.Text
|
unionMemberTypes :: Foldable t => Formatter -> Full.UnionMemberTypes t -> Lazy.Text
|
||||||
unionMemberTypes formatter (Full.UnionMemberTypes memberTypes)
|
unionMemberTypes formatter (Full.UnionMemberTypes memberTypes)
|
||||||
| null memberTypes = mempty
|
| null memberTypes = mempty
|
||||||
| Minified <- formatter = Lazy.Text.fromStrict
|
| otherwise = Lazy.Text.append "="
|
||||||
$ Text.append "= "
|
$ pipeList formatter
|
||||||
$ Text.intercalate " | "
|
$ Lazy.Text.fromStrict
|
||||||
$ toList memberTypes
|
|
||||||
| Pretty _ <- formatter
|
|
||||||
= Lazy.Text.append "="
|
|
||||||
$ Lazy.Text.concat
|
|
||||||
$ (("\n" <> indentSymbol <> "| ") <>) . Lazy.Text.fromStrict
|
|
||||||
<$> toList memberTypes
|
<$> toList memberTypes
|
||||||
|
|
||||||
|
pipeList :: Foldable t => Formatter -> t Lazy.Text -> Lazy.Text
|
||||||
|
pipeList Minified = (" " <>) . Lazy.Text.intercalate " | " . toList
|
||||||
|
pipeList (Pretty _) = Lazy.Text.concat
|
||||||
|
. fmap (("\n" <> indentSymbol <> "| ") <>)
|
||||||
|
. toList
|
||||||
|
|
||||||
enumValueDefinition :: Formatter -> Full.EnumValueDefinition -> Lazy.Text
|
enumValueDefinition :: Formatter -> Full.EnumValueDefinition -> Lazy.Text
|
||||||
enumValueDefinition (Pretty _) enumValue =
|
enumValueDefinition (Pretty _) enumValue =
|
||||||
let Full.EnumValueDefinition description' name' directives' = enumValue
|
let Full.EnumValueDefinition description' name' directives' = enumValue
|
||||||
|
Loading…
Reference in New Issue
Block a user