mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
2f3ae93ab0
This implements an initial set of DTO types that represent serialized metadata. These new types come with codecs using autodocodec which are used to derive both JSON serialization, and OpenAPI documentation. This ensures that we can automatically generate API documentation that is guaranteed to match JSON produced by the server. For the moment the new types are not used for anything except to generate an early version of an OpenAPI document. Because this is early work the DTO types for each metadata format version list top-level properties only with placeholders for the types of each top-level property. This early iteration demonstrates using a sum type in Haskell that maps to a tagged union in OpenAPI (using the `version` field value as a tag). This work is experimental and incomplete! Please do not incorporate the generated OpenAPI documentation into essential workflows at this time. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4801 GitOrigin-RevId: d2f110a6237b73520cdba24667333ef14e8cdd3d
40 lines
2.2 KiB
Haskell
40 lines
2.2 KiB
Haskell
module Hasura.Metadata.DTO.MetadataV2 (MetadataV2 (..)) 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 2 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 MetadataV2 = MetadataV2
|
|
{ metaV2Actions :: Maybe PlaceholderArray,
|
|
metaV2Allowlist :: Maybe PlaceholderArray,
|
|
metaV2CronTriggers :: Maybe PlaceholderArray,
|
|
metaV2CustomTypes :: Maybe PlaceholderObject,
|
|
metaV2Functions :: Maybe PlaceholderArray,
|
|
metaV2QueryCollections :: Maybe PlaceholderArray,
|
|
metaV2RemoteSchemas :: Maybe PlaceholderArray,
|
|
metaV2Tables :: PlaceholderArray
|
|
}
|
|
deriving stock (Show, Eq, Generic)
|
|
deriving (FromJSON, ToJSON, OpenApi.ToSchema) via (Autodocodec MetadataV2)
|
|
|
|
instance HasCodec MetadataV2 where
|
|
codec =
|
|
object "MetadataV2" $
|
|
MetadataV2
|
|
<$ versionField 2
|
|
<*> optionalField "actions" "action definitions which extend Hasura's schema with custom business logic using custom queries and mutations" .= metaV2Actions
|
|
<*> optionalField "allowlist" "safe GraphQL operations - when allow lists are enabled only these operations are allowed" .= metaV2Allowlist
|
|
<*> optionalField "cron_triggers" "reliably trigger HTTP endpoints to run custom business logic periodically based on a cron schedule" .= metaV2CronTriggers
|
|
<*> optionalField "custom_types" "custom type definitions" .= metaV2CustomTypes
|
|
<*> optionalField "functions" "user-defined SQL functions" .= metaV2Functions
|
|
<*> optionalField "query_collections" "group queries using query collections" .= metaV2QueryCollections
|
|
<*> optionalField "remote_schemas" "merge remote GraphQL schemas and provide a unified GraphQL API" .= metaV2RemoteSchemas
|
|
<*> requiredField "tables" "configured database tables" .= metaV2Tables
|