mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-24 07:52:14 +03:00
94331e23f5
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3924 GitOrigin-RevId: 75b276edcd2d1f88bbdbed1b96b08708f9c68450
56 lines
1.6 KiB
Haskell
56 lines
1.6 KiB
Haskell
{-# LANGUAGE StandaloneKindSignatures #-}
|
|
|
|
module Hasura.Backends.DataWrapper.IR.Name
|
|
( Name (..),
|
|
NameType (..),
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
|
|
import Data.Kind (Type)
|
|
import Data.Text.Extended (ToTxt)
|
|
import Hasura.Backends.DataWrapper.API qualified as API
|
|
import Hasura.Incremental (Cacheable)
|
|
import Hasura.Prelude
|
|
import Witch
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | A tagged, opaque wrapper around 'Text' that provides a number of derived
|
|
-- derived instances (primarily as required by the @Backend@ typeclass).
|
|
--
|
|
-- This wrapper is indexed by 'NameType' so that different "names" can be
|
|
-- represented as semantically distinct types without the boilerplate of
|
|
-- actually defining these wrappers separately.
|
|
type Name :: NameType -> Type
|
|
newtype Name ty = Name {unName :: Text}
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
deriving newtype
|
|
( Cacheable,
|
|
FromJSON,
|
|
FromJSONKey,
|
|
Hashable,
|
|
NFData,
|
|
ToJSON,
|
|
ToJSONKey,
|
|
ToTxt
|
|
)
|
|
|
|
instance From API.TableName (Name 'Table) where
|
|
from (API.TableName n) = coerce @Text @(Name 'Table) n
|
|
|
|
instance From API.ColumnName (Name 'Column) where
|
|
from (API.ColumnName n) = coerce @Text @(Name 'Column) n
|
|
|
|
-- | The "type" of "name" that the 'Name' type is meant to provide a textual
|
|
-- representation for.
|
|
--
|
|
-- In other words: an enumeration of all the types for which 'Name' acts as a
|
|
-- shared abstraction.
|
|
data NameType
|
|
= Column
|
|
| Function
|
|
| Table
|