mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-19 05:21:47 +03:00
1698f9dd91
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8856 Co-authored-by: Daniel Harvey <4729125+danieljharvey@users.noreply.github.com> GitOrigin-RevId: 38ad67de9b3d765c4eb50943dd52b8fc32317540
62 lines
2.1 KiB
Haskell
62 lines
2.1 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module Hasura.RemoteSchema.Metadata.Permission
|
|
( RemoteSchemaPermissionDefinition (..),
|
|
RemoteSchemaPermissionMetadata (..),
|
|
)
|
|
where
|
|
|
|
import Autodocodec (HasCodec (codec), object, optionalField', requiredField', requiredFieldWith, (.=))
|
|
import Autodocodec.Extended (graphQLSchemaDocumentCodec)
|
|
import Data.Aeson qualified as J
|
|
import Data.Aeson.TH qualified as J
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.Types.Roles (RoleName)
|
|
import Language.GraphQL.Draft.Printer qualified as G
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
import Text.Builder qualified as TB
|
|
|
|
newtype RemoteSchemaPermissionDefinition = RemoteSchemaPermissionDefinition
|
|
{ _rspdSchema :: G.SchemaDocument
|
|
}
|
|
deriving (Show, Eq, Generic)
|
|
|
|
instance NFData RemoteSchemaPermissionDefinition
|
|
|
|
instance Hashable RemoteSchemaPermissionDefinition
|
|
|
|
instance HasCodec RemoteSchemaPermissionDefinition where
|
|
codec =
|
|
object "RemoteSchemaPermissionDefinition" $
|
|
RemoteSchemaPermissionDefinition
|
|
<$> requiredFieldWith
|
|
"schema"
|
|
graphQLSchemaDocumentCodec
|
|
"GraphQL schema document, e.g. the content of schema.gql"
|
|
.= _rspdSchema
|
|
|
|
instance J.FromJSON RemoteSchemaPermissionDefinition where
|
|
parseJSON = J.withObject "RemoteSchemaPermissionDefinition" $ \obj -> do
|
|
fmap RemoteSchemaPermissionDefinition $ obj J..: "schema"
|
|
|
|
instance J.ToJSON RemoteSchemaPermissionDefinition where
|
|
toJSON (RemoteSchemaPermissionDefinition schema) =
|
|
J.object $ ["schema" J..= J.String (TB.run . G.schemaDocument $ schema)]
|
|
|
|
data RemoteSchemaPermissionMetadata = RemoteSchemaPermissionMetadata
|
|
{ _rspmRole :: RoleName,
|
|
_rspmDefinition :: RemoteSchemaPermissionDefinition,
|
|
_rspmComment :: Maybe Text
|
|
}
|
|
deriving (Show, Eq, Generic)
|
|
|
|
instance HasCodec RemoteSchemaPermissionMetadata where
|
|
codec =
|
|
object "RemoteSchemaPermissionMetadata" $
|
|
RemoteSchemaPermissionMetadata
|
|
<$> requiredField' "role" .= _rspmRole
|
|
<*> requiredField' "definition" .= _rspmDefinition
|
|
<*> optionalField' "comment" .= _rspmComment
|
|
|
|
$(J.deriveJSON hasuraJSON {J.omitNothingFields = True} ''RemoteSchemaPermissionMetadata)
|