mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
gardening: move RQL.Instances to Base and clean it
GitOrigin-RevId: 01fa4133a4002f891d213c1f913511ccfd3c1741
This commit is contained in:
parent
f24caef627
commit
08d605baca
@ -48,7 +48,7 @@ source-repository-package
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/hasura/graphql-parser-hs.git
|
||||
tag: f3a20ab6201669bd683d5a0c8580410af264c7d0
|
||||
tag: c4af9f09b128756d0ee2b2997d0aa2a5aabb8e9e
|
||||
|
||||
source-repository-package
|
||||
type: git
|
||||
|
@ -303,6 +303,7 @@ library
|
||||
, Hasura.Metadata.Class
|
||||
|
||||
, Hasura.Base.Error
|
||||
, Hasura.Base.Instances
|
||||
|
||||
, Hasura.Backends.BigQuery.Connection
|
||||
, Hasura.Backends.BigQuery.DataLoader.Execute
|
||||
@ -426,7 +427,6 @@ library
|
||||
, Hasura.Server.Migrate.Internal
|
||||
, Hasura.Server.Auth.JWT.Internal
|
||||
, Hasura.Server.Auth.JWT.Logging
|
||||
, Hasura.RQL.Instances
|
||||
, Hasura.RQL.Types
|
||||
, Hasura.RQL.Types.Action
|
||||
, Hasura.RQL.Types.ApiLimit
|
||||
|
@ -34,6 +34,7 @@ import Hasura.Backends.Postgres.Translate.Returning
|
||||
import Hasura.Backends.Postgres.Translate.Select
|
||||
import Hasura.Backends.Postgres.Translate.Update
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.EncJSON
|
||||
import Hasura.RQL.DML.Internal
|
||||
import Hasura.RQL.IR.Delete
|
||||
@ -41,7 +42,6 @@ import Hasura.RQL.IR.Insert
|
||||
import Hasura.RQL.IR.Returning
|
||||
import Hasura.RQL.IR.Select
|
||||
import Hasura.RQL.IR.Update
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.RQL.Types
|
||||
import Hasura.SQL.Types
|
||||
import Hasura.Server.Version (HasVersion)
|
||||
|
@ -15,7 +15,7 @@ import Hasura.Backends.Postgres.SQL.Types
|
||||
import Hasura.Backends.Postgres.SQL.Value
|
||||
import Hasura.Backends.Postgres.Types.Column
|
||||
import Hasura.Base.Error
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.RQL.Types
|
||||
import Hasura.SQL.Types
|
||||
|
||||
|
@ -2,7 +2,7 @@ module Hasura.Backends.Postgres.Types.Column where
|
||||
|
||||
import Hasura.Backends.Postgres.Instances.Types ()
|
||||
import Hasura.Backends.Postgres.SQL.Types
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.RQL.Types.Column
|
||||
import Hasura.SQL.Backend
|
||||
|
||||
|
107
server/src-lib/Hasura/Base/Instances.hs
Normal file
107
server/src-lib/Hasura/Base/Instances.hs
Normal file
@ -0,0 +1,107 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
||||
{- | This module defines all missing instances of third party libraries.
|
||||
-}
|
||||
|
||||
module Hasura.Base.Instances where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Aeson as J
|
||||
import qualified Data.HashMap.Strict as M
|
||||
import qualified Data.HashSet as S
|
||||
import qualified Data.URL.Template as UT
|
||||
import qualified Database.PG.Query as Q
|
||||
import qualified Language.Haskell.TH.Syntax as TH
|
||||
import qualified System.Cron.Parser as C
|
||||
import qualified System.Cron.Types as C
|
||||
import qualified Text.Regex.TDFA as TDFA
|
||||
import qualified Text.Regex.TDFA.Pattern as TDFA
|
||||
|
||||
import Data.Functor.Product
|
||||
import Data.GADT.Compare
|
||||
import Data.Text
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Deepseq
|
||||
|
||||
instance NFData UT.Variable
|
||||
instance NFData UT.TemplateItem
|
||||
instance NFData UT.URLTemplate
|
||||
|
||||
instance NFData C.StepField
|
||||
instance NFData C.RangeField
|
||||
instance NFData C.SpecificField
|
||||
instance NFData C.BaseField
|
||||
instance NFData C.CronField
|
||||
instance NFData C.MonthSpec
|
||||
instance NFData C.DayOfMonthSpec
|
||||
instance NFData C.DayOfWeekSpec
|
||||
instance NFData C.HourSpec
|
||||
instance NFData C.MinuteSpec
|
||||
instance NFData C.CronSchedule
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Template Haskell
|
||||
|
||||
instance (TH.Lift k, TH.Lift v) => TH.Lift (M.HashMap k v) where
|
||||
lift m = [| M.fromList $(TH.lift $ M.toList m) |]
|
||||
liftTyped = TH.unsafeTExpCoerce . TH.lift
|
||||
|
||||
instance TH.Lift a => TH.Lift (S.HashSet a) where
|
||||
lift s = [| S.fromList $(TH.lift $ S.toList s) |]
|
||||
liftTyped = TH.unsafeTExpCoerce . TH.lift
|
||||
|
||||
deriving instance TH.Lift TDFA.CompOption
|
||||
deriving instance TH.Lift TDFA.DoPa
|
||||
deriving instance TH.Lift TDFA.ExecOption
|
||||
deriving instance TH.Lift TDFA.Pattern
|
||||
deriving instance TH.Lift TDFA.PatternSet
|
||||
deriving instance TH.Lift TDFA.PatternSetCharacterClass
|
||||
deriving instance TH.Lift TDFA.PatternSetCollatingElement
|
||||
deriving instance TH.Lift TDFA.PatternSetEquivalenceClass
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- GADT
|
||||
|
||||
instance (GCompare f, GCompare g) => GCompare (Product f g) where
|
||||
Pair a1 a2 `gcompare` Pair b1 b2 = case gcompare a1 b1 of
|
||||
GLT -> GLT
|
||||
GEQ -> case gcompare a2 b2 of
|
||||
GLT -> GLT
|
||||
GEQ -> GEQ
|
||||
GGT -> GGT
|
||||
GGT -> GGT
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- JSON
|
||||
|
||||
instance J.FromJSON C.CronSchedule where
|
||||
parseJSON = J.withText "CronSchedule" $ \t ->
|
||||
onLeft (C.parseCronSchedule t) fail
|
||||
|
||||
instance J.ToJSON C.CronSchedule where
|
||||
toJSON = J.String . C.serializeCronSchedule
|
||||
|
||||
instance J.ToJSONKey Void
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Postgres
|
||||
|
||||
instance Q.ToPrepArg C.CronSchedule where
|
||||
toPrepVal = Q.toPrepVal . C.serializeCronSchedule
|
||||
|
||||
instance Q.FromCol C.CronSchedule where
|
||||
fromCol bs =
|
||||
case Q.fromCol bs of
|
||||
Left err -> Left err
|
||||
Right dbCron ->
|
||||
case C.parseCronSchedule dbCron of
|
||||
Left err' -> Left $ "invalid cron schedule " <> pack err'
|
||||
Right cron -> Right cron
|
@ -2,14 +2,14 @@ module Hasura.RQL.DDL.Headers where
|
||||
|
||||
import Data.Aeson
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Instances ()
|
||||
|
||||
import qualified Data.CaseInsensitive as CI
|
||||
import qualified Data.Environment as Env
|
||||
import qualified Data.Text as T
|
||||
import qualified Network.HTTP.Types as HTTP
|
||||
import qualified Data.CaseInsensitive as CI
|
||||
import qualified Data.Environment as Env
|
||||
import qualified Data.Text as T
|
||||
import qualified Network.HTTP.Types as HTTP
|
||||
|
||||
|
||||
data HeaderConf = HeaderConf HeaderName HeaderValue
|
||||
|
@ -48,13 +48,13 @@ import Data.Aeson.TH
|
||||
|
||||
import Hasura.Backends.Postgres.DDL.RunSQL
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.EncJSON
|
||||
import Hasura.RQL.DDL.Schema.Cache
|
||||
import Hasura.RQL.DDL.Schema.Catalog
|
||||
import Hasura.RQL.DDL.Schema.Function
|
||||
import Hasura.RQL.DDL.Schema.Rename
|
||||
import Hasura.RQL.DDL.Schema.Table
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.RQL.Types
|
||||
import Hasura.Server.Utils (quoteRegex)
|
||||
|
||||
|
@ -45,9 +45,9 @@ import qualified Hasura.Backends.Postgres.SQL.DML as PG
|
||||
|
||||
import Hasura.Backends.Postgres.Instances.Types ()
|
||||
import Hasura.Backends.Postgres.SQL.Types
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
import Hasura.RQL.IR.OrderBy
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.RQL.Types.Column
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.SQL.Backend
|
||||
|
@ -12,7 +12,7 @@ import qualified Data.Text as T
|
||||
|
||||
import Data.Aeson
|
||||
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.SQL.Backend
|
||||
|
@ -1,130 +0,0 @@
|
||||
{-# LANGUAGE CPP #-}
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
|
||||
module Hasura.RQL.Instances where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import qualified Data.Aeson as J
|
||||
import qualified Data.HashMap.Strict as M
|
||||
import qualified Data.HashSet as S
|
||||
import qualified Data.URL.Template as UT
|
||||
import qualified Database.PG.Query as Q
|
||||
import qualified Language.GraphQL.Draft.Syntax as G
|
||||
import qualified Language.Haskell.TH.Syntax as TH
|
||||
import qualified Text.Regex.TDFA as TDFA
|
||||
import qualified Text.Regex.TDFA.Pattern as TDFA
|
||||
|
||||
import Control.DeepSeq (NFData (..))
|
||||
import Data.Functor.Product
|
||||
import Data.GADT.Compare
|
||||
import Data.Text
|
||||
import System.Cron.Parser
|
||||
import System.Cron.Types
|
||||
|
||||
|
||||
instance NFData G.FragmentDefinition
|
||||
instance NFData G.GType
|
||||
instance NFData G.OperationType
|
||||
instance NFData G.VariableDefinition
|
||||
instance NFData G.SchemaDefinition
|
||||
instance NFData G.RootOperationTypeDefinition
|
||||
instance NFData G.TypeSystemDefinition
|
||||
instance NFData G.SchemaDocument
|
||||
instance NFData UT.Variable
|
||||
instance NFData UT.TemplateItem
|
||||
instance NFData UT.URLTemplate
|
||||
|
||||
instance NFData G.Name where
|
||||
rnf = rnf . G.unName
|
||||
|
||||
instance NFData a => NFData (G.Directive a)
|
||||
instance NFData a => NFData (G.ExecutableDefinition a)
|
||||
instance (NFData (a b), NFData b) => NFData (G.Field a b)
|
||||
instance NFData a => NFData (G.FragmentSpread a)
|
||||
instance (NFData (a b), NFData b) => NFData (G.InlineFragment a b)
|
||||
instance (NFData (a b), NFData b) => NFData (G.OperationDefinition a b)
|
||||
instance (NFData (a b), NFData b) => NFData (G.Selection a b)
|
||||
instance (NFData (a b), NFData b) => NFData (G.TypedOperationDefinition a b)
|
||||
instance NFData G.InputValueDefinition
|
||||
instance NFData a => NFData (G.InputObjectTypeDefinition a)
|
||||
instance (NFData a) => NFData (G.ObjectTypeDefinition a)
|
||||
instance NFData G.UnionTypeDefinition
|
||||
instance NFData G.EnumTypeDefinition
|
||||
instance NFData G.EnumValueDefinition
|
||||
instance (NFData a) => NFData (G.FieldDefinition a)
|
||||
instance NFData G.ScalarTypeDefinition
|
||||
instance (NFData a, NFData b) => NFData (G.InterfaceTypeDefinition a b)
|
||||
instance (NFData a, NFData b) => NFData (G.TypeDefinition a b)
|
||||
instance NFData a => NFData (G.Value a)
|
||||
|
||||
deriving instance NFData G.Description
|
||||
deriving instance NFData G.EnumValue
|
||||
deriving instance NFData G.Nullability
|
||||
|
||||
deriving instance NFData a => NFData (G.ExecutableDocument a)
|
||||
|
||||
-- instances for CronSchedule from package `cron`
|
||||
instance NFData StepField
|
||||
instance NFData RangeField
|
||||
instance NFData SpecificField
|
||||
instance NFData BaseField
|
||||
instance NFData CronField
|
||||
instance NFData MonthSpec
|
||||
instance NFData DayOfMonthSpec
|
||||
instance NFData DayOfWeekSpec
|
||||
instance NFData HourSpec
|
||||
instance NFData MinuteSpec
|
||||
instance NFData CronSchedule
|
||||
|
||||
instance (TH.Lift k, TH.Lift v) => TH.Lift (M.HashMap k v) where
|
||||
lift m = [| M.fromList $(TH.lift $ M.toList m) |]
|
||||
#if MIN_VERSION_template_haskell(2,16,0)
|
||||
liftTyped = TH.unsafeTExpCoerce . TH.lift
|
||||
#endif
|
||||
|
||||
instance TH.Lift a => TH.Lift (S.HashSet a) where
|
||||
lift s = [| S.fromList $(TH.lift $ S.toList s) |]
|
||||
#if MIN_VERSION_template_haskell(2,16,0)
|
||||
liftTyped = TH.unsafeTExpCoerce . TH.lift
|
||||
#endif
|
||||
|
||||
deriving instance TH.Lift TDFA.CompOption
|
||||
deriving instance TH.Lift TDFA.DoPa
|
||||
deriving instance TH.Lift TDFA.ExecOption
|
||||
deriving instance TH.Lift TDFA.Pattern
|
||||
deriving instance TH.Lift TDFA.PatternSet
|
||||
deriving instance TH.Lift TDFA.PatternSetCharacterClass
|
||||
deriving instance TH.Lift TDFA.PatternSetCollatingElement
|
||||
deriving instance TH.Lift TDFA.PatternSetEquivalenceClass
|
||||
|
||||
instance (GCompare f, GCompare g) => GCompare (Product f g) where
|
||||
Pair a1 a2 `gcompare` Pair b1 b2 = case gcompare a1 b1 of
|
||||
GLT -> GLT
|
||||
GEQ -> case gcompare a2 b2 of
|
||||
GLT -> GLT
|
||||
GEQ -> GEQ
|
||||
GGT -> GGT
|
||||
GGT -> GGT
|
||||
|
||||
instance J.FromJSON CronSchedule where
|
||||
parseJSON = J.withText "CronSchedule" $ \t ->
|
||||
onLeft (parseCronSchedule t) fail
|
||||
|
||||
instance J.ToJSON CronSchedule where
|
||||
toJSON = J.String . serializeCronSchedule
|
||||
|
||||
instance Q.ToPrepArg CronSchedule where
|
||||
toPrepVal = Q.toPrepVal . serializeCronSchedule
|
||||
|
||||
instance Q.FromCol CronSchedule where
|
||||
fromCol bs =
|
||||
case Q.fromCol bs of
|
||||
Left err -> Left err
|
||||
Right dbCron ->
|
||||
case parseCronSchedule dbCron of
|
||||
Left err' -> Left $ "invalid cron schedule " <> pack err'
|
||||
Right cron -> Right cron
|
||||
|
||||
|
||||
instance J.ToJSONKey Void
|
@ -38,8 +38,8 @@ import Data.Aeson.TH
|
||||
import Data.Text.Extended
|
||||
|
||||
import Hasura.Base.Error
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.SQL.Backend
|
||||
|
@ -35,7 +35,7 @@ import qualified Data.Text as T
|
||||
import Data.Text.Extended
|
||||
import Data.Text.NonEmpty
|
||||
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.RQL.Types.Endpoint.Trie as Trie
|
||||
import Hasura.RQL.Types.QueryCollection (CollectionName, QueryName)
|
||||
import Web.HttpApiData (FromHttpApiData (..))
|
||||
|
@ -31,8 +31,8 @@ import Data.Aeson.TH
|
||||
import Data.Text.Extended
|
||||
import Data.Text.NonEmpty
|
||||
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.RQL.Instances ()
|
||||
|
||||
|
||||
|
||||
|
@ -2,17 +2,6 @@ module Hasura.Server.Utils where
|
||||
|
||||
import Hasura.Prelude
|
||||
|
||||
import Control.Lens ((^..))
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Internal
|
||||
import Data.Char
|
||||
import Data.Text.Extended
|
||||
import Data.Time
|
||||
import Language.Haskell.TH.Syntax (Q, TExp)
|
||||
import System.Environment
|
||||
import System.Exit
|
||||
import System.Process
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.CaseInsensitive as CI
|
||||
import qualified Data.HashSet as Set
|
||||
@ -31,7 +20,19 @@ import qualified Text.Regex.TDFA as TDFA
|
||||
import qualified Text.Regex.TDFA.ReadRegex as TDFA
|
||||
import qualified Text.Regex.TDFA.TDFA as TDFA
|
||||
|
||||
import Hasura.RQL.Instances ()
|
||||
import Control.Lens ((^..))
|
||||
import Data.Aeson
|
||||
import Data.Aeson.Internal
|
||||
import Data.Char
|
||||
import Data.Text.Extended
|
||||
import Data.Time
|
||||
import Language.Haskell.TH.Syntax (Q, TExp)
|
||||
import System.Environment
|
||||
import System.Exit
|
||||
import System.Process
|
||||
|
||||
import Hasura.Base.Instances ()
|
||||
|
||||
|
||||
jsonHeader :: HTTP.Header
|
||||
jsonHeader = ("Content-Type", "application/json; charset=utf-8")
|
||||
|
@ -23,7 +23,7 @@ import Data.FileEmbed (makeRelativeToProject)
|
||||
import Data.Text.Conversions (FromText (..), ToText (..))
|
||||
import Text.Regex.TDFA ((=~~))
|
||||
|
||||
import Hasura.RQL.Instances ()
|
||||
import Hasura.Base.Instances ()
|
||||
import Hasura.Server.Utils (getValFromEnvOrScript)
|
||||
|
||||
data Version
|
||||
|
Loading…
Reference in New Issue
Block a user