mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 13:02:11 +03:00
b094947239
This PR expands the set of codecs for source metadata to include `TableMetadata`, `FunctionMetadata`, and various permission types. This fills out more detail in the generated OpenAPI document. See the [generated OpenAPI spec](https://gist.github.com/hallettj/783d06a926cbc854eececa4964e8aa5b) based on this PR. See also the [generated TypeScript types](https://github.com/hasura/graphql-engine-mono/files/9448102/client-typescript.tar.gz) based on that spec. Ticket: https://hasurahq.atlassian.net/browse/MM-66 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5664 GitOrigin-RevId: b6e1f32c669368cd6150e6f69fc36b78b748d9bb
86 lines
3.2 KiB
Haskell
86 lines
3.2 KiB
Haskell
module Autodocodec.Extended
|
|
( optionalFieldOrIncludedNull,
|
|
optionalFieldOrIncludedNull',
|
|
optionalFieldOrIncludedNullWith,
|
|
optionalFieldOrIncludedNullWith',
|
|
)
|
|
where
|
|
|
|
import Autodocodec
|
|
import Hasura.Prelude
|
|
|
|
-- | An optional field that might be @null@ where a @Nothing@ value should be
|
|
-- represented as @null@ on serialization instead of omitting the field.
|
|
--
|
|
-- This differs from Autodocodec's stock 'optionalFieldOrNull' in that that
|
|
-- function omits the field during serialization if the Haskell value is
|
|
-- @Nothing@. This version includes the field with a serialized value of @null@.
|
|
optionalFieldOrIncludedNull ::
|
|
HasCodec output =>
|
|
-- | Key
|
|
Text ->
|
|
-- | Documentation
|
|
Text ->
|
|
ObjectCodec (Maybe output) (Maybe output)
|
|
optionalFieldOrIncludedNull key doc = optionalFieldOrIncludedNullWith key codec doc
|
|
|
|
-- | An optional field that might be @null@ where a @Nothing@ value should be
|
|
-- represented as @null@ on serialization instead of omitting the field.
|
|
--
|
|
-- This differs from Autodocodec's stock 'optionalFieldOrNull'' in that that
|
|
-- function omits the field during serialization if the Haskell value is
|
|
-- @Nothing@. This version includes the field with a serialized value of @null@.
|
|
optionalFieldOrIncludedNull' ::
|
|
HasCodec output =>
|
|
-- | Key
|
|
Text ->
|
|
ObjectCodec (Maybe output) (Maybe output)
|
|
optionalFieldOrIncludedNull' key = optionalFieldOrIncludedNullWith' key codec
|
|
|
|
-- | An optional field that might be @null@ where a @Nothing@ value should be
|
|
-- represented as @null@ on serialization instead of omitting the field.
|
|
--
|
|
-- This differs from Autodocodec's stock 'optionalFieldOrNullWith' in that that
|
|
-- function omits the field during serialization if the Haskell value is
|
|
-- @Nothing@. This version includes the field with a serialized value of @null@.
|
|
optionalFieldOrIncludedNullWith ::
|
|
-- | Key
|
|
Text ->
|
|
-- | Codec for the value
|
|
JSONCodec output ->
|
|
-- | Documentation
|
|
Text ->
|
|
ObjectCodec (Maybe output) (Maybe output)
|
|
optionalFieldOrIncludedNullWith key c doc =
|
|
orIncludedNullHelper $
|
|
OptionalKeyCodec key (maybeCodec c) (Just doc)
|
|
|
|
-- | An optional field that might be @null@ where a @Nothing@ value should be
|
|
-- represented as @null@ on serialization instead of omitting the field.
|
|
--
|
|
-- This differs from Autodocodec's stock 'optionalFieldOrNullWith'' in that that
|
|
-- function omits the field during serialization if the Haskell value is
|
|
-- @Nothing@. This version includes the field with a serialized value of @null@.
|
|
optionalFieldOrIncludedNullWith' ::
|
|
-- | Key
|
|
Text ->
|
|
-- | Codec for the value
|
|
JSONCodec output ->
|
|
ObjectCodec (Maybe output) (Maybe output)
|
|
optionalFieldOrIncludedNullWith' key c =
|
|
orIncludedNullHelper $
|
|
OptionalKeyCodec key (maybeCodec c) Nothing
|
|
|
|
orIncludedNullHelper :: ObjectCodec (Maybe (Maybe input)) (Maybe (Maybe output)) -> ObjectCodec (Maybe input) (Maybe output)
|
|
orIncludedNullHelper = dimapCodec dec enc
|
|
where
|
|
dec :: Maybe (Maybe input) -> Maybe input
|
|
dec = \case
|
|
Nothing -> Nothing
|
|
Just Nothing -> Nothing
|
|
Just (Just a) -> Just a
|
|
enc :: Maybe output -> Maybe (Maybe output)
|
|
enc = \case
|
|
Nothing -> Just Nothing -- This is the case that differs from the stock `orNullHelper`
|
|
Just a -> Just (Just a)
|