graphql-engine/server/src-lib/Hasura/RemoteSchema/Metadata/Permission.hs
Tom Harding e0c0043e76 Upgrade Ormolu to 0.7.0.0
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9284
GitOrigin-RevId: 2f2cf2ad01900a54e4bdb970205ac0ef313c7e00
2023-05-24 13:53:53 +00:00

65 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)