2021-06-11 06:26:50 +03:00
|
|
|
module Hasura.RQL.IR.Root
|
2021-09-24 01:56:37 +03:00
|
|
|
( SourceConfigWith (..),
|
|
|
|
RootField (..),
|
|
|
|
MutationDB (..),
|
|
|
|
ActionQuery (..),
|
|
|
|
ActionMutation (..),
|
|
|
|
QueryRootField,
|
|
|
|
MutationRootField,
|
|
|
|
SubscriptionRootField,
|
|
|
|
QueryDBRoot (..),
|
|
|
|
MutationDBRoot (..),
|
2021-12-07 16:12:02 +03:00
|
|
|
RemoteRelationshipField (..),
|
2021-09-24 01:56:37 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson.Ordered qualified as JO
|
|
|
|
import Data.Kind (Type)
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR.Delete
|
|
|
|
import Hasura.RQL.IR.Insert
|
2021-12-07 16:12:02 +03:00
|
|
|
import Hasura.RQL.IR.RemoteSchema
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.RQL.IR.Select
|
|
|
|
import Hasura.RQL.IR.Update
|
|
|
|
import Hasura.RQL.Types.Action qualified as RQL
|
|
|
|
import Hasura.RQL.Types.Backend qualified as RQL
|
|
|
|
import Hasura.RQL.Types.Common qualified as RQL
|
|
|
|
import Hasura.RQL.Types.QueryTags qualified as RQL
|
|
|
|
import Hasura.RQL.Types.RemoteSchema qualified as RQL
|
|
|
|
import Hasura.SQL.AnyBackend qualified as AB
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
|
|
|
|
data SourceConfigWith (db :: BackendType -> Type) (b :: BackendType)
|
|
|
|
= SourceConfigWith (RQL.SourceConfig b) (Maybe RQL.QueryTagsConfig) (db b)
|
2021-06-11 06:26:50 +03:00
|
|
|
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
data RootField (db :: BackendType -> Type) remote action raw where
|
2021-09-24 01:56:37 +03:00
|
|
|
RFDB ::
|
|
|
|
RQL.SourceName ->
|
|
|
|
AB.AnyBackend (SourceConfigWith db) ->
|
|
|
|
RootField db remote action raw
|
2021-06-11 06:26:50 +03:00
|
|
|
RFRemote :: remote -> RootField db remote action raw
|
|
|
|
RFAction :: action -> RootField db remote action raw
|
2021-09-24 01:56:37 +03:00
|
|
|
RFRaw :: raw -> RootField db remote action raw
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
data MutationDB (b :: BackendType) (r :: Type) v
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
= MDBInsert (AnnInsert b r v)
|
2021-11-25 00:39:42 +03:00
|
|
|
| MDBUpdate (AnnotatedUpdateG b r v)
|
2021-09-24 01:56:37 +03:00
|
|
|
| MDBDelete (AnnDelG b r v)
|
|
|
|
| -- | This represents a VOLATILE function, and is AnnSimpleSelG for easy
|
|
|
|
-- re-use of non-VOLATILE function tracking code.
|
|
|
|
MDBFunction RQL.JsonAggSelect (AnnSimpleSelectG b r v)
|
2021-07-08 18:41:59 +03:00
|
|
|
deriving stock (Generic, Functor, Foldable, Traversable)
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
data ActionQuery (b :: BackendType) (r :: Type) v
|
2021-09-24 01:56:37 +03:00
|
|
|
= AQQuery !(RQL.AnnActionExecution b r v)
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
| AQAsync !(RQL.AnnActionAsyncQuery b r v)
|
2021-07-08 18:41:59 +03:00
|
|
|
deriving (Functor, Foldable, Traversable)
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
data ActionMutation (b :: BackendType) (r :: Type) v
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
= AMSync !(RQL.AnnActionExecution b r v)
|
2021-06-11 06:26:50 +03:00
|
|
|
| AMAsync !RQL.AnnActionMutationAsync
|
2021-07-08 18:41:59 +03:00
|
|
|
deriving (Functor, Foldable, Traversable)
|
|
|
|
|
2021-06-11 06:26:50 +03:00
|
|
|
-- The `db` type argument of @RootField@ expects only one type argument, the backend `b`, as not all
|
|
|
|
-- types stored in a RootField will have a second parameter like @QueryDB@ does: they all only have
|
|
|
|
-- in common the fact that they're parametric over the backend. To define @QueryRootField@ in terms
|
|
|
|
-- of @QueryDB@ (and likewise for mutations), we need a type-level function `b -> QueryDB b (v
|
|
|
|
-- b)`. Sadly, neither type synonyms nor type families may be partially applied. Hence the need for
|
|
|
|
-- @QueryDBRoot@ and @MutationDBRoot@.
|
2021-09-24 01:56:37 +03:00
|
|
|
newtype QueryDBRoot r v b = QDBR (QueryDB b r (v b))
|
|
|
|
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
newtype MutationDBRoot r v b = MDBR (MutationDB b r (v b))
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
-- | IR of a remote relationship. A remote relationship currently can be to
|
|
|
|
-- either a remote schema or a database's table. See RemoteSourceSelect for
|
|
|
|
-- explanation on 'vf'.
|
|
|
|
data RemoteRelationshipField vf
|
|
|
|
= RemoteSchemaField RemoteSchemaSelect
|
|
|
|
| -- | AnyBackend is used here to capture a relationship to an arbitrary target
|
|
|
|
RemoteSourceField (AB.AnyBackend (RemoteSourceSelect (RemoteRelationshipField vf) vf))
|
|
|
|
|
2021-07-26 16:03:51 +03:00
|
|
|
-- | Represents a query root field to an action
|
2021-09-24 01:56:37 +03:00
|
|
|
type QueryActionRoot v =
|
2021-12-07 16:12:02 +03:00
|
|
|
ActionQuery ('Postgres 'Vanilla) (RemoteRelationshipField v) (v ('Postgres 'Vanilla))
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-07-26 16:03:51 +03:00
|
|
|
-- | Represents a mutation root field to an action
|
2021-09-24 01:56:37 +03:00
|
|
|
type MutationActionRoot v =
|
2021-12-07 16:12:02 +03:00
|
|
|
ActionMutation ('Postgres 'Vanilla) (RemoteRelationshipField v) (v ('Postgres 'Vanilla))
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
type QueryRootField v =
|
|
|
|
RootField
|
|
|
|
(QueryDBRoot (RemoteRelationshipField v) v)
|
|
|
|
RQL.RemoteField
|
|
|
|
(QueryActionRoot v)
|
|
|
|
JO.Value
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
type MutationRootField v =
|
|
|
|
RootField
|
|
|
|
(MutationDBRoot (RemoteRelationshipField v) v)
|
|
|
|
RQL.RemoteField
|
|
|
|
(MutationActionRoot v)
|
|
|
|
JO.Value
|
2021-07-26 16:03:51 +03:00
|
|
|
|
2021-12-07 16:12:02 +03:00
|
|
|
type SubscriptionRootField v =
|
|
|
|
RootField
|
|
|
|
(QueryDBRoot (RemoteRelationshipField v) v)
|
|
|
|
Void
|
|
|
|
Void
|
|
|
|
Void
|