mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 18:42:30 +03:00
b9ec9b78dd
Introduces a new function, `metadataToDTO`, that converts a `Metadata` value to a `MetadataV3` DTO value. This is the next step in the alternative serialization path for metadata that comes with a generated OpenAPI specification. This PR carves up the existing `metadataToOrdJSON` function so that helpers previously embedded in the `where` block of that function can also be used in the implementation of `metadataToDTO`. If I did everything correctly `metadataToOrdJSON` should behave exactly as before. In a followup PR I will move the extracted helpers to a new submodule, `Hasura.RQL.Types.Metadata.Serialization`, since they add up to several hundred lines of code. I'm breaking up #5184 into smaller PRs, and this is the second PR in that effort. This PR is stacked on #5210. The tracking issue is https://hasurahq.atlassian.net/browse/MM-35 PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5211 GitOrigin-RevId: 2596ed5312d7b1232c47ae1d08a51d8ead11fcb8
57 lines
3.5 KiB
Haskell
57 lines
3.5 KiB
Haskell
module Hasura.Metadata.DTO.MetadataV3 (MetadataV3 (..)) where
|
|
|
|
import Autodocodec (Autodocodec (Autodocodec), HasCodec (codec), object, optionalField, requiredField, (.=))
|
|
import Autodocodec.OpenAPI ()
|
|
import Data.Aeson (FromJSON, ToJSON)
|
|
import Data.OpenApi qualified as OpenApi
|
|
import Hasura.Metadata.DTO.Placeholder (PlaceholderArray, PlaceholderObject)
|
|
import Hasura.Metadata.DTO.Utils (versionField)
|
|
import Hasura.Prelude
|
|
|
|
-- | Revision 3 of the Metadata export format. Note that values of the types,
|
|
-- 'PlaceholderArray' and 'PlaceholderObject' are placeholders that will
|
|
-- eventually be expanded to represent more detail.
|
|
data MetadataV3 = MetadataV3
|
|
{ metaV3Sources :: PlaceholderArray,
|
|
metaV3RemoteSchemas :: Maybe PlaceholderArray,
|
|
metaV3QueryCollections :: Maybe PlaceholderArray,
|
|
metaV3Allowlist :: Maybe PlaceholderArray,
|
|
metaV3Actions :: Maybe PlaceholderArray,
|
|
metaV3CustomTypes :: Maybe PlaceholderObject,
|
|
metaV3CronTriggers :: Maybe PlaceholderArray,
|
|
metaV3RestEndpoints :: Maybe PlaceholderArray,
|
|
metaV3ApiLimits :: Maybe PlaceholderObject,
|
|
metaV3MetricsConfig :: Maybe PlaceholderObject,
|
|
metaV3InheritedRoles :: Maybe PlaceholderArray,
|
|
metaV3GraphqlSchemaIntrospection :: Maybe PlaceholderObject,
|
|
metaV3Network :: Maybe PlaceholderObject,
|
|
metaV3BackendConfigs :: Maybe PlaceholderObject
|
|
}
|
|
deriving stock (Show, Eq, Generic)
|
|
deriving (FromJSON, ToJSON, OpenApi.ToSchema) via (Autodocodec MetadataV3)
|
|
|
|
-- | Codecs simultaneously provide serialization logic for a type, and
|
|
-- documentation. A codec can be used to generate a specification in OpenAPI or
|
|
-- another format that matches the JSON serialization of the same type.
|
|
-- Documentation strings (the second argument to 'optionalField' and to
|
|
-- 'requiredField') appear in the generated specification for users' reference.
|
|
instance HasCodec MetadataV3 where
|
|
codec =
|
|
object "MetadataV3" $
|
|
MetadataV3
|
|
<$ versionField 3
|
|
<*> requiredField "sources" "configured databases" .= metaV3Sources
|
|
<*> optionalField "remote_schemas" "merge remote GraphQL schemas and provide a unified GraphQL API" .= metaV3RemoteSchemas
|
|
<*> optionalField "query_collections" "group queries using query collections" .= metaV3QueryCollections
|
|
<*> optionalField "allowlist" "safe GraphQL operations - when allow lists are enabled only these operations are allowed" .= metaV3Allowlist
|
|
<*> optionalField "actions" "action definitions which extend Hasura's schema with custom business logic using custom queries and mutations" .= metaV3Actions
|
|
<*> optionalField "custom_types" "custom type definitions" .= metaV3CustomTypes
|
|
<*> optionalField "cron_triggers" "reliably trigger HTTP endpoints to run custom business logic periodically based on a cron schedule" .= metaV3CronTriggers
|
|
<*> optionalField "rest_endpoints" "REST interfaces to saved GraphQL queries and mutations" .= metaV3RestEndpoints
|
|
<*> optionalField "api_limits" "limts to depth and/or rate of API requests" .= metaV3ApiLimits
|
|
<*> optionalField "metrics_config" "TODO" .= metaV3MetricsConfig
|
|
<*> optionalField "inherited_roles" "an inherited role is a way to create a new role which inherits permissions from two or more roles" .= metaV3InheritedRoles
|
|
<*> optionalField "graphql_schema_introspection" "TODO" .= metaV3GraphqlSchemaIntrospection
|
|
<*> optionalField "network" "TODO" .= metaV3Network
|
|
<*> optionalField "backend_configs" "TODO" .= metaV3BackendConfigs
|