diff options
| author | Eugen Wissner <belka@caraus.de> | 2022-10-02 11:38:53 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2022-10-02 11:38:53 +0200 |
| commit | bf2e4925b45991476c430bd635d8fbabe7cbecbf (patch) | |
| tree | d0dfc22f70a405283681a2e3c70be4a2d93bae65 | |
| parent | 2321d1a1bcb1974bafa3914f673252993377b5b1 (diff) | |
| download | graphql-bf2e4925b45991476c430bd635d8fbabe7cbecbf.tar.gz | |
Add operation type encoder
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 9 | ||||
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 5 |
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b856f..ec5d2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ and this project adheres to - `Language.GraphQL`: Added information about the *json* flag and switching to *graphql-spice* for JSON support. +### Added +- Partial schema printing: operation type encoder. + ## [1.0.3.0] - 2022-03-27 ### Fixed - Index position in error path. (Index and Segment paths of a field have been diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index 4569823..54967ea 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -11,6 +11,7 @@ module Language.GraphQL.AST.Encoder , directive , document , minified + , operationType , pretty , type' , value @@ -34,7 +35,7 @@ import qualified Language.GraphQL.AST.Document as Full -- Use 'pretty' or 'minified' to construct the formatter. data Formatter = Minified - | Pretty Word + | Pretty !Word -- | Constructs a formatter for pretty printing. pretty :: Formatter @@ -294,6 +295,12 @@ nonNullType :: Full.NonNullType -> Lazy.Text nonNullType (Full.NonNullTypeNamed x) = Lazy.Text.fromStrict x <> "!" nonNullType (Full.NonNullTypeList x) = listType x <> "!" +-- | Produces lowercase operation type: query, mutation or subscription. +operationType :: Formatter -> Full.OperationType -> Lazy.Text +operationType _formatter Full.Query = "query" +operationType _formatter Full.Mutation = "mutation" +operationType _formatter Full.Subscription = "subscription" + -- * Internal between :: Char -> Char -> Lazy.Text -> Lazy.Text diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index bc6aac4..febd6fd 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -173,3 +173,8 @@ spec = do |] '\n' actual = definition pretty operation in actual `shouldBe` expected + + describe "operationType" $ + it "produces lowercase mutation operation type" $ + let actual = operationType pretty Full.Mutation + in actual `shouldBe` "mutation" |
