diff options
| author | Eugen Wissner <belka@caraus.de> | 2022-12-27 10:37:34 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2022-12-27 10:38:08 +0100 |
| commit | a96d4e6ef3b1020d239f0061af5861aadeb278fc (patch) | |
| tree | ae822d7ca7f3eb03a42ef23d000d9ba7da6d0913 /src/Language/GraphQL/AST | |
| parent | 3ce6e7da461030d7d6f4b356096492c072ce16e2 (diff) | |
| download | graphql-a96d4e6ef3b1020d239f0061af5861aadeb278fc.tar.gz | |
Add Semigroup and Monoid instances for Description
Diffstat (limited to 'src/Language/GraphQL/AST')
| -rw-r--r-- | src/Language/GraphQL/AST/Document.hs | 8 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/Language/GraphQL/AST/Document.hs b/src/Language/GraphQL/AST/Document.hs index ea640df..131285d 100644 --- a/src/Language/GraphQL/AST/Document.hs +++ b/src/Language/GraphQL/AST/Document.hs @@ -464,6 +464,14 @@ data SchemaExtension newtype Description = Description (Maybe Text) deriving (Eq, Show) +instance Semigroup Description + where + Description lhs <> Description rhs = Description $ lhs <> rhs + +instance Monoid Description + where + mempty = Description mempty + -- ** Types -- | Type definitions describe various user-defined types. diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index a58a161..d19b9e6 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -72,7 +72,8 @@ typeSystemDefinition formatter = \case $ optempty (directives formatter) operationDirectives <> "schema " <> bracesList formatter operationTypeDefinition (NonEmpty.toList operationTypeDefinitions') - _ -> "" -- TODO: TypeDefinition and DerictiveDefinition missing. + Full.TypeDefinition typeDefinition' -> typeDefinition formatter typeDefinition' + _ -> "" -- TODO: DerictiveDefinition missing. where operationTypeDefinition (Full.OperationTypeDefinition operationType' namedType') = indentLine (incrementIndent formatter) @@ -80,6 +81,20 @@ typeSystemDefinition formatter = \case <> colon formatter <> Lazy.Text.fromStrict namedType' +typeDefinition :: Formatter -> Full.TypeDefinition -> Lazy.Text.Text +typeDefinition formatter = \case + Full.ScalarTypeDefinition description' name' directives' + -> optempty (description formatter) description' + <> "scalar " + <> Lazy.Text.fromStrict name' + <> optempty (directives formatter) directives' + _typeDefinition' -> "" -- TODO: Types missing. + +description :: Formatter -> Full.Description -> Lazy.Text.Text +description _formatter (Full.Description Nothing) = "" +description formatter (Full.Description (Just description')) = + stringValue formatter description' + -- | Converts a t'Full.ExecutableDefinition' into a string. definition :: Formatter -> Full.ExecutableDefinition -> Lazy.Text definition formatter x |
