2021-06-11 06:26:50 +03:00
|
|
|
module Hasura.GraphQL.Execute.RemoteJoin.Collect
|
2021-09-24 01:56:37 +03:00
|
|
|
( getRemoteJoins,
|
|
|
|
getRemoteJoinsSelect,
|
|
|
|
getRemoteJoinsMutationDB,
|
|
|
|
getRemoteJoinsActionQuery,
|
|
|
|
getRemoteJoinsActionMutation,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Control.Lens (Traversal', preview, _2)
|
|
|
|
import Control.Monad.Writer
|
|
|
|
import Data.HashMap.Strict qualified as Map
|
|
|
|
import Data.List.NonEmpty qualified as NE
|
|
|
|
import Data.Text qualified as T
|
|
|
|
import Hasura.GraphQL.Execute.RemoteJoin.Types
|
|
|
|
import Hasura.GraphQL.Parser.Column (UnpreparedValue (..))
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR
|
|
|
|
import Hasura.RQL.Types
|
|
|
|
import Hasura.SQL.AnyBackend qualified as AB
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
{- Note: [Remote Joins Architecture]
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Unparsed Incoming GraphQL +------------------------------+
|
|
|
|
--------------------------> | Parsing of the GraphQL query |-----+
|
|
|
|
+------------------------------+ |
|
|
|
|
| DB Query and remote joins (if any)
|
|
|
|
|
|
|
|
|
V
|
|
|
|
+----------------------------------+ SQL query response +----------------------------+
|
|
|
|
| Traverse the DB response to | <------------------- | Execution of the DB query |
|
|
|
|
| get the values of the arguments | +----------------------------+
|
|
|
|
| of the remote field |
|
|
|
|
+----------------------------------+
|
|
|
|
|
|
|
|
|
| Remote field arguments
|
|
|
|
V
|
|
|
|
+--------------------------+ Remote schema response +----------------------------------------+
|
|
|
|
| Query the remote schema | ------------------------> | Replace the remote join fields in |
|
|
|
|
| with the remote field | | the SQL query response (JSON) with |
|
|
|
|
| arguments to the remote | | the response obtained from the remote |
|
|
|
|
| field configured in the | | schema at appropriate places. |
|
|
|
|
| remote join. | +----------------------------------------+
|
|
|
|
+--------------------------+
|
|
|
|
-}
|
|
|
|
|
2021-08-06 16:39:00 +03:00
|
|
|
-- | A writer monad used to collect together all remote joins
|
|
|
|
-- appearing in some data structure.
|
|
|
|
--
|
|
|
|
-- In the functions below, the 'withField' function is used to track the
|
|
|
|
-- context of the path from the root of the current selection set.
|
|
|
|
--
|
|
|
|
-- It is important that we work bottom-up, and do not 'collect' duplicate
|
|
|
|
-- field names at any level, because the 'Semigroup' instance for 'RemoteJoins'
|
|
|
|
-- does not allow for these duplicates.
|
2021-09-24 01:56:37 +03:00
|
|
|
newtype Collector a = Collector {runCollector :: (a, Maybe RemoteJoins)}
|
|
|
|
deriving
|
|
|
|
(Functor, Applicative, Monad, MonadWriter (Maybe RemoteJoins))
|
2021-08-06 16:39:00 +03:00
|
|
|
via Writer (Maybe RemoteJoins)
|
|
|
|
|
|
|
|
-- | Collect some remote joins appearing at the given field names in the current
|
|
|
|
-- context.
|
|
|
|
collect :: NonEmpty (FieldName, RemoteJoin) -> Collector ()
|
|
|
|
collect = tell . Just . JoinTree . fmap (second Leaf)
|
|
|
|
|
|
|
|
-- | Keep track of the given field name in the current path from the root of the
|
|
|
|
-- selection set.
|
|
|
|
withField :: FieldName -> Collector a -> Collector a
|
2021-09-24 01:56:37 +03:00
|
|
|
withField name = censor (fmap wrap)
|
|
|
|
where
|
|
|
|
wrap rjs = JoinTree ((name, Tree rjs) :| [])
|
2021-08-06 16:39:00 +03:00
|
|
|
|
2021-06-11 06:26:50 +03:00
|
|
|
-- | Collects remote joins from the AST and also adds the necessary join fields
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoins ::
|
|
|
|
Backend b =>
|
|
|
|
QueryDB b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(QueryDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
2021-06-11 06:26:50 +03:00
|
|
|
getRemoteJoins = \case
|
|
|
|
QDBMultipleRows s -> first QDBMultipleRows $ getRemoteJoinsSelect s
|
2021-09-24 01:56:37 +03:00
|
|
|
QDBSingleRow s -> first QDBSingleRow $ getRemoteJoinsSelect s
|
|
|
|
QDBAggregation s -> first QDBAggregation $ getRemoteJoinsAggregateSelect s
|
|
|
|
QDBConnection s -> first QDBConnection $ getRemoteJoinsConnectionSelect s
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
-- | Traverse through 'AnnSimpleSel' and collect remote join fields (if any).
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsSelect ::
|
|
|
|
Backend b =>
|
|
|
|
AnnSimpleSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(AnnSimpleSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
2021-06-11 06:26:50 +03:00
|
|
|
getRemoteJoinsSelect =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformSelect
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
-- | Traverse through @'AnnAggregateSelect' and collect remote join fields (if any).
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsAggregateSelect ::
|
|
|
|
Backend b =>
|
|
|
|
AnnAggregateSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(AnnAggregateSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
2021-06-11 06:26:50 +03:00
|
|
|
getRemoteJoinsAggregateSelect =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformAggregateSelect
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
-- | Traverse through @'ConnectionSelect' and collect remote join fields (if any).
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsConnectionSelect ::
|
|
|
|
Backend b =>
|
|
|
|
ConnectionSelect b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(ConnectionSelect b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
2021-06-11 06:26:50 +03:00
|
|
|
getRemoteJoinsConnectionSelect =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformConnectionSelect
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
-- | Traverse through 'MutationOutput' and collect remote join fields (if any)
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsMutationOutput ::
|
|
|
|
Backend b =>
|
|
|
|
MutationOutputG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(MutationOutputG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
2021-06-11 06:26:50 +03:00
|
|
|
getRemoteJoinsMutationOutput =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformMutationOutput
|
2021-06-11 06:26:50 +03:00
|
|
|
where
|
2021-08-06 16:39:00 +03:00
|
|
|
transformMutationOutput = \case
|
2021-06-11 06:26:50 +03:00
|
|
|
MOutMultirowFields mutationFields ->
|
|
|
|
MOutMultirowFields <$> transfromMutationFields mutationFields
|
|
|
|
MOutSinglerowObject annFields ->
|
2021-08-06 16:39:00 +03:00
|
|
|
MOutSinglerowObject <$> transformAnnFields annFields
|
2021-06-11 06:26:50 +03:00
|
|
|
where
|
|
|
|
transfromMutationFields fields =
|
2021-08-06 16:39:00 +03:00
|
|
|
for fields $ \(fieldName, field') -> withField fieldName do
|
|
|
|
(fieldName,) <$> case field' of
|
2021-09-24 01:56:37 +03:00
|
|
|
MCount -> pure MCount
|
|
|
|
MExp t -> pure $ MExp t
|
2021-08-06 16:39:00 +03:00
|
|
|
MRet annFields -> MRet <$> transformAnnFields annFields
|
2021-06-11 06:26:50 +03:00
|
|
|
|
|
|
|
-- local helpers
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsAnnFields ::
|
|
|
|
Backend b =>
|
|
|
|
AnnFieldsG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(AnnFieldsG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
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
|
|
|
getRemoteJoinsAnnFields =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformAnnFields
|
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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsMutationDB ::
|
|
|
|
Backend b =>
|
|
|
|
MutationDB b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(MutationDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
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
|
|
|
getRemoteJoinsMutationDB = \case
|
|
|
|
MDBInsert insert ->
|
|
|
|
first MDBInsert $ getRemoteJoinsInsert insert
|
|
|
|
MDBUpdate update ->
|
|
|
|
first MDBUpdate $ getRemoteJoinsUpdate update
|
|
|
|
MDBDelete delete ->
|
|
|
|
first MDBDelete $ getRemoteJoinsDelete delete
|
|
|
|
MDBFunction aggSelect select ->
|
|
|
|
first (MDBFunction aggSelect) $ getRemoteJoinsSelect select
|
|
|
|
where
|
|
|
|
getRemoteJoinsInsert insert =
|
|
|
|
let (output', remoteJoins) = getRemoteJoinsMutationOutput $ _aiOutput insert
|
2021-09-24 01:56:37 +03:00
|
|
|
in (insert {_aiOutput = output'}, remoteJoins)
|
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
|
|
|
|
|
|
|
getRemoteJoinsUpdate update =
|
|
|
|
let (output', remoteJoins) = getRemoteJoinsMutationOutput $ uqp1Output update
|
2021-09-24 01:56:37 +03:00
|
|
|
in (update {uqp1Output = output'}, remoteJoins)
|
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
|
|
|
|
|
|
|
getRemoteJoinsDelete delete =
|
|
|
|
let (output', remoteJoins) = getRemoteJoinsMutationOutput $ dqp1Output delete
|
2021-09-24 01:56:37 +03:00
|
|
|
in (delete {dqp1Output = output'}, remoteJoins)
|
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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsSyncAction ::
|
|
|
|
(Backend b) =>
|
|
|
|
AnnActionExecution b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(AnnActionExecution b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
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
|
|
|
getRemoteJoinsSyncAction actionExecution =
|
|
|
|
let (fields', remoteJoins) = getRemoteJoinsAnnFields $ _aaeFields actionExecution
|
2021-09-24 01:56:37 +03:00
|
|
|
in (actionExecution {_aaeFields = fields'}, remoteJoins)
|
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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsActionQuery ::
|
|
|
|
(Backend b) =>
|
|
|
|
ActionQuery b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(ActionQuery b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
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
|
|
|
getRemoteJoinsActionQuery = \case
|
|
|
|
AQQuery sync ->
|
|
|
|
first AQQuery $ getRemoteJoinsSyncAction sync
|
|
|
|
AQAsync async ->
|
|
|
|
first AQAsync $ getRemoteJoinsAsyncQuery async
|
|
|
|
where
|
|
|
|
getRemoteJoinsAsyncQuery async =
|
|
|
|
let (fields', remoteJoins) =
|
2021-08-06 16:39:00 +03:00
|
|
|
runCollector . transformAsyncFields $
|
2021-09-24 01:56:37 +03:00
|
|
|
_aaaqFields async
|
|
|
|
in (async {_aaaqFields = fields'}, remoteJoins)
|
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
|
|
|
|
2021-08-06 16:39:00 +03:00
|
|
|
transformAsyncFields fields =
|
|
|
|
for fields $ \(fieldName, field) -> withField fieldName do
|
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
|
|
|
(fieldName,) <$> case field of
|
|
|
|
AsyncTypename t -> pure $ AsyncTypename t
|
|
|
|
AsyncOutput outputFields ->
|
2021-08-06 16:39:00 +03:00
|
|
|
AsyncOutput <$> transformAnnFields outputFields
|
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
|
|
|
AsyncId -> pure AsyncId
|
|
|
|
AsyncCreatedAt -> pure AsyncCreatedAt
|
|
|
|
AsyncErrors -> pure AsyncErrors
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
getRemoteJoinsActionMutation ::
|
|
|
|
(Backend b) =>
|
|
|
|
ActionMutation b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
(ActionMutation b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
|
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
|
|
|
getRemoteJoinsActionMutation = \case
|
|
|
|
AMAsync async -> (AMAsync async, Nothing)
|
2021-09-24 01:56:37 +03:00
|
|
|
AMSync sync -> first AMSync $ getRemoteJoinsSyncAction sync
|
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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
transformSelect ::
|
|
|
|
Backend b =>
|
|
|
|
AnnSimpleSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
Collector (AnnSimpleSelectG b (Const Void) (UnpreparedValue b))
|
|
|
|
transformSelect select@AnnSelectG {_asnFields = fields} = do
|
2021-06-11 06:26:50 +03:00
|
|
|
-- Transform selects in array, object and computed fields
|
2021-08-06 16:39:00 +03:00
|
|
|
transformedFields <- transformAnnFields fields
|
2021-09-24 01:56:37 +03:00
|
|
|
pure select {_asnFields = transformedFields}
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
transformAggregateSelect ::
|
|
|
|
Backend b =>
|
|
|
|
AnnAggregateSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
Collector (AnnAggregateSelectG b (Const Void) (UnpreparedValue b))
|
|
|
|
transformAggregateSelect select@AnnSelectG {_asnFields = aggFields} = do
|
2021-08-06 16:39:00 +03:00
|
|
|
transformedFields <- for aggFields \(fieldName, aggField) ->
|
|
|
|
withField fieldName $ case aggField of
|
2021-09-24 01:56:37 +03:00
|
|
|
TAFAgg agg -> pure (fieldName, TAFAgg agg)
|
|
|
|
TAFExp t -> pure (fieldName, TAFExp t)
|
|
|
|
TAFNodes nodesAgg annFields -> do
|
|
|
|
transformed <- transformAnnFields annFields
|
|
|
|
pure (fieldName, TAFNodes nodesAgg transformed)
|
|
|
|
pure select {_asnFields = transformedFields}
|
|
|
|
|
|
|
|
transformConnectionSelect ::
|
|
|
|
forall b.
|
|
|
|
Backend b =>
|
|
|
|
ConnectionSelect b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
Collector (ConnectionSelect b (Const Void) (UnpreparedValue b))
|
|
|
|
transformConnectionSelect connSelect@ConnectionSelect {..} = do
|
2021-08-06 16:39:00 +03:00
|
|
|
transformedFields <- for (_asnFields _csSelect) \(fieldName, connField) ->
|
|
|
|
withField fieldName $ case connField of
|
2021-09-24 01:56:37 +03:00
|
|
|
ConnectionTypename t -> pure (fieldName, ConnectionTypename t)
|
|
|
|
ConnectionPageInfo p -> pure (fieldName, ConnectionPageInfo p)
|
2021-08-06 16:39:00 +03:00
|
|
|
ConnectionEdges edges -> do
|
|
|
|
transformed <- transformEdges edges
|
|
|
|
pure (fieldName, ConnectionEdges transformed)
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
let select = _csSelect {_asnFields = transformedFields}
|
|
|
|
pure connSelect {_csSelect = select}
|
2021-06-11 06:26:50 +03:00
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
transformEdges ::
|
|
|
|
[(FieldName, EdgeField b (RemoteSelect UnpreparedValue) (UnpreparedValue b))] ->
|
|
|
|
Collector [(FieldName, EdgeField b (Const Void) (UnpreparedValue b))]
|
2021-08-06 16:39:00 +03:00
|
|
|
transformEdges edgeFields = for edgeFields \(fieldName, edgeField) ->
|
|
|
|
withField fieldName $ case edgeField of
|
2021-09-24 01:56:37 +03:00
|
|
|
EdgeTypename t -> pure (fieldName, EdgeTypename t)
|
|
|
|
EdgeCursor -> pure (fieldName, EdgeCursor)
|
2021-08-06 16:39:00 +03:00
|
|
|
EdgeNode annFields -> do
|
|
|
|
transformed <- transformAnnFields annFields
|
|
|
|
pure (fieldName, EdgeNode transformed)
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
transformObjectSelect ::
|
|
|
|
Backend b =>
|
|
|
|
AnnObjectSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b) ->
|
|
|
|
Collector (AnnObjectSelectG b (Const Void) (UnpreparedValue b))
|
|
|
|
transformObjectSelect select@AnnObjectSelectG {_aosFields = fields} = do
|
2021-08-06 16:39:00 +03:00
|
|
|
transformedFields <- transformAnnFields fields
|
2021-09-24 01:56:37 +03:00
|
|
|
pure select {_aosFields = transformedFields}
|
2021-06-11 06:26:50 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
transformAnnFields ::
|
|
|
|
forall src.
|
|
|
|
Backend src =>
|
|
|
|
AnnFieldsG src (RemoteSelect UnpreparedValue) (UnpreparedValue src) ->
|
|
|
|
Collector (AnnFieldsG src (Const Void) (UnpreparedValue src))
|
2021-08-06 16:39:00 +03:00
|
|
|
transformAnnFields fields = do
|
|
|
|
-- Produces a list of transformed fields that may or may not have an
|
|
|
|
-- associated remote join.
|
|
|
|
annotatedFields <- for fields \(fieldName, field') -> withField fieldName do
|
|
|
|
-- FIXME: There's way too much going on in this 'case .. of' block...
|
2021-06-11 06:26:50 +03:00
|
|
|
(fieldName,) <$> case field' of
|
2021-08-06 16:39:00 +03:00
|
|
|
-- AnnFields which do not need to be transformed.
|
|
|
|
AFNodeId x qt pkeys -> pure (AFNodeId x qt pkeys, Nothing)
|
2021-09-24 01:56:37 +03:00
|
|
|
AFColumn c -> pure (AFColumn c, Nothing)
|
|
|
|
AFExpression t -> pure (AFExpression t, Nothing)
|
2021-08-06 16:39:00 +03:00
|
|
|
-- AnnFields with no associated remote joins and whose transformations are
|
|
|
|
-- relatively straightforward.
|
|
|
|
AFObjectRelation annRel -> do
|
|
|
|
transformed <- transformAnnRelation transformObjectSelect annRel
|
|
|
|
pure (AFObjectRelation transformed, Nothing)
|
|
|
|
AFArrayRelation (ASSimple annRel) -> do
|
|
|
|
transformed <- transformAnnRelation transformSelect annRel
|
|
|
|
pure (AFArrayRelation . ASSimple $ transformed, Nothing)
|
|
|
|
AFArrayRelation (ASAggregate aggRel) -> do
|
|
|
|
transformed <- transformAnnRelation transformAggregateSelect aggRel
|
|
|
|
pure (AFArrayRelation . ASAggregate $ transformed, Nothing)
|
|
|
|
AFArrayRelation (ASConnection annRel) -> do
|
|
|
|
transformed <- transformAnnRelation transformConnectionSelect annRel
|
|
|
|
pure (AFArrayRelation . ASConnection $ transformed, Nothing)
|
|
|
|
AFComputedField computedField computedFieldName computedFieldSelect -> do
|
|
|
|
transformed <- case computedFieldSelect of
|
2021-09-24 01:56:37 +03:00
|
|
|
CFSScalar cfss cbe -> pure $ CFSScalar cfss cbe
|
2021-08-06 16:39:00 +03:00
|
|
|
CFSTable jsonAggSel annSel -> do
|
|
|
|
transformed <- transformSelect annSel
|
|
|
|
pure $ CFSTable jsonAggSel transformed
|
|
|
|
pure (AFComputedField computedField computedFieldName transformed, Nothing)
|
|
|
|
-- Remote AnnFields, whose elements require annotation so that they can be
|
|
|
|
-- used to construct a remote join.
|
|
|
|
--
|
|
|
|
-- We generate this so that the response has a key with the relationship,
|
2021-07-26 16:03:51 +03:00
|
|
|
-- without which preserving the order of fields in the final response
|
2021-08-06 16:39:00 +03:00
|
|
|
-- would require a lot of bookkeeping.
|
2021-09-24 01:56:37 +03:00
|
|
|
AFRemote (RemoteSelectRemoteSchema RemoteSchemaSelect {..}) ->
|
|
|
|
let annotatedJoinColumns =
|
|
|
|
Map.fromList $ map annotateDBJoinField (toList _rselHasuraFields)
|
|
|
|
phantomColumns =
|
|
|
|
annotatedJoinColumns & Map.mapMaybe \(columnInfo, alias) ->
|
|
|
|
case alias of
|
|
|
|
JCSelected _ -> Nothing
|
|
|
|
JCPhantom a -> Just (columnInfo, a)
|
|
|
|
joinColumnAliases = fmap snd annotatedJoinColumns
|
|
|
|
inputArgsToMap = Map.fromList . map (_rfaArgument &&& _rfaValue)
|
|
|
|
remoteJoin =
|
|
|
|
RemoteJoinRemoteSchema $
|
|
|
|
RemoteSchemaJoin
|
|
|
|
(inputArgsToMap _rselArgs)
|
|
|
|
_rselResultCustomizer
|
|
|
|
_rselSelection
|
|
|
|
joinColumnAliases
|
|
|
|
_rselFieldCall
|
|
|
|
_rselRemoteSchema
|
|
|
|
annotatedJoin = Just (phantomColumns, remoteJoin)
|
|
|
|
in pure (remoteAnnPlaceholder, annotatedJoin)
|
|
|
|
AFRemote (RemoteSelectSource anySourceSelect) -> AB.dispatchAnyBackend @Backend
|
|
|
|
anySourceSelect
|
2021-09-22 13:43:05 +03:00
|
|
|
-- NOTE: This is necessary to bring 'tgt' into scope, so that it can be
|
|
|
|
-- passed to the helper function as a type argument.
|
2021-09-24 01:56:37 +03:00
|
|
|
\(RemoteSourceSelect {..} :: RemoteSourceSelect src UnpreparedValue tgt) ->
|
|
|
|
let (transformedSourceRelationship, sourceRelationshipJoins) =
|
|
|
|
getRemoteJoinsSourceRelation _rssSelection
|
|
|
|
annotatedJoinColumns = annotateSourceJoin @tgt <$> _rssJoinMapping
|
|
|
|
phantomColumns =
|
|
|
|
annotatedJoinColumns & Map.mapMaybe \(columnInfo, (alias, _, _)) ->
|
|
|
|
case alias of
|
|
|
|
JCSelected _ -> Nothing
|
|
|
|
JCPhantom a -> Just (columnInfo, a)
|
|
|
|
anySourceJoin =
|
|
|
|
AB.mkAnyBackend $
|
|
|
|
RemoteSourceJoin
|
|
|
|
_rssName
|
|
|
|
_rssConfig
|
|
|
|
transformedSourceRelationship
|
|
|
|
(fmap snd annotatedJoinColumns)
|
|
|
|
remoteJoin = RemoteJoinSource anySourceJoin sourceRelationshipJoins
|
|
|
|
annotatedJoin = Just (phantomColumns, remoteJoin)
|
|
|
|
in pure (remoteAnnPlaceholder, annotatedJoin)
|
|
|
|
|
|
|
|
let transformedFields = (fmap . fmap) fst annotatedFields
|
|
|
|
remoteJoins =
|
|
|
|
annotatedFields & mapMaybe \(fieldName, (_, mRemoteJoin)) ->
|
|
|
|
mRemoteJoin <&> \remoteJoin -> (fieldName, remoteJoin)
|
2021-06-11 06:26:50 +03:00
|
|
|
case NE.nonEmpty remoteJoins of
|
|
|
|
Nothing -> pure transformedFields
|
2021-08-06 16:39:00 +03:00
|
|
|
Just neRemoteJoins -> do
|
2021-09-24 01:56:37 +03:00
|
|
|
let phantomFields =
|
|
|
|
(Map.elems . Map.unions . map (fst . snd) $ remoteJoins)
|
|
|
|
<&> \(joinField, alias) -> case joinField of
|
|
|
|
JoinColumn columnInfo ->
|
|
|
|
let column = AFColumn $ AnnColumnField (pgiColumn columnInfo) (pgiType columnInfo) False Nothing Nothing
|
|
|
|
in (alias, column)
|
|
|
|
JoinComputedField computedFieldInfo ->
|
|
|
|
(alias, mkScalarComputedFieldSelect computedFieldInfo)
|
2021-08-06 16:39:00 +03:00
|
|
|
collect $ (fmap . fmap) snd neRemoteJoins
|
|
|
|
pure $ transformedFields <> phantomFields
|
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
|
|
|
where
|
2021-08-06 16:39:00 +03:00
|
|
|
-- Placeholder text to annotate a remote relationship field.
|
2021-09-22 13:43:05 +03:00
|
|
|
remoteAnnPlaceholder :: AnnFieldG src (Const Void) (UnpreparedValue src)
|
2021-08-06 16:39:00 +03:00
|
|
|
remoteAnnPlaceholder = AFExpression "remote relationship placeholder"
|
|
|
|
|
|
|
|
-- Annotate a 'DBJoinField' with its field name and an alias so that it may
|
|
|
|
-- be used to construct a remote join.
|
2021-09-24 01:56:37 +03:00
|
|
|
annotateDBJoinField ::
|
|
|
|
DBJoinField src -> (FieldName, (DBJoinField src, JoinColumnAlias))
|
2021-08-06 16:39:00 +03:00
|
|
|
annotateDBJoinField = \case
|
|
|
|
jc@(JoinColumn columnInfo) ->
|
2021-09-24 01:56:37 +03:00
|
|
|
let column = pgiColumn columnInfo
|
|
|
|
columnFieldName = fromCol @src column
|
|
|
|
alias = getJoinColumnAlias columnFieldName column columnFields
|
|
|
|
in (columnFieldName, (jc, alias))
|
|
|
|
jcf@(JoinComputedField ScalarComputedField {..}) ->
|
|
|
|
let computedFieldName = fromComputedField _scfName
|
|
|
|
alias = getJoinColumnAlias computedFieldName _scfName computedFields
|
|
|
|
in (computedFieldName, (jcf, alias))
|
2021-08-06 16:39:00 +03:00
|
|
|
|
2021-09-22 13:43:05 +03:00
|
|
|
-- Annotate an element a remote source join from '_rssJoinMapping' so that
|
|
|
|
-- a remote join can be constructed.
|
2021-09-24 01:56:37 +03:00
|
|
|
annotateSourceJoin ::
|
|
|
|
forall tgt.
|
|
|
|
(ColumnInfo src, ScalarType tgt, Column tgt) ->
|
|
|
|
(DBJoinField src, (JoinColumnAlias, ScalarType tgt, Column tgt))
|
2021-09-22 13:43:05 +03:00
|
|
|
annotateSourceJoin (columnInfo, rhsColumnType, rhsColumn) =
|
2021-09-24 01:56:37 +03:00
|
|
|
let lhsColumn = pgiColumn columnInfo
|
|
|
|
lhsColumnFieldName = fromCol @src lhsColumn
|
|
|
|
alias = getJoinColumnAlias lhsColumnFieldName lhsColumn columnFields
|
|
|
|
in (JoinColumn columnInfo, (alias, rhsColumnType, rhsColumn))
|
2021-09-22 13:43:05 +03:00
|
|
|
|
2021-08-06 16:39:00 +03:00
|
|
|
-- Get the fields targeted by some 'Traversal' for an arbitrary list of
|
|
|
|
-- tuples, discarding any elements whose fields cannot be focused upon.
|
|
|
|
getFields :: Traversal' super sub -> [(any, super)] -> [(any, sub)]
|
|
|
|
getFields focus = mapMaybe (traverse $ preview focus)
|
|
|
|
|
|
|
|
-- This is a map of column name to its alias of all columns in the
|
|
|
|
-- selection set.
|
2021-09-22 13:43:05 +03:00
|
|
|
columnFields :: HashMap (Column src) FieldName
|
2021-09-24 01:56:37 +03:00
|
|
|
columnFields =
|
|
|
|
Map.fromList $
|
|
|
|
[ (_acfColumn annColumn, alias)
|
|
|
|
| (alias, annColumn) <- getFields _AFColumn fields
|
|
|
|
]
|
2021-08-06 16:39:00 +03:00
|
|
|
|
|
|
|
-- This is a map of computed field name to its alias of all computed fields
|
|
|
|
-- in the selection set.
|
|
|
|
computedFields :: Map.HashMap ComputedFieldName FieldName
|
2021-09-24 01:56:37 +03:00
|
|
|
computedFields =
|
|
|
|
Map.fromList $
|
|
|
|
[ (fieldName, alias)
|
|
|
|
| -- Note that we do not currently care about input arguments to a computed
|
|
|
|
-- field because only computed fields which do not accept input arguments
|
|
|
|
-- are currently allowed.
|
|
|
|
(alias, fieldName) <- getFields (_AFComputedField . _2) fields
|
|
|
|
]
|
|
|
|
|
|
|
|
getJoinColumnAlias ::
|
|
|
|
(Eq field, Hashable field) =>
|
|
|
|
FieldName ->
|
|
|
|
field ->
|
|
|
|
HashMap field FieldName ->
|
|
|
|
JoinColumnAlias
|
2021-08-06 16:39:00 +03:00
|
|
|
getJoinColumnAlias fieldName field selectedFields =
|
|
|
|
case Map.lookup field selectedFields of
|
2021-09-24 01:56:37 +03:00
|
|
|
Nothing -> makeUniqueAlias fieldName
|
2021-08-06 16:39:00 +03:00
|
|
|
Just fieldAlias -> JCSelected fieldAlias
|
|
|
|
|
|
|
|
longestAliasLength = maximum $ map (T.length . coerce . fst) fields
|
|
|
|
|
|
|
|
-- This generates an alias for a phantom field that does not conflict with
|
|
|
|
-- any of the existing aliases in the seleciton set
|
|
|
|
--
|
|
|
|
-- If we generate a unique name for each field name which is longer than
|
|
|
|
-- the longest alias in the selection set, the generated name would be
|
|
|
|
-- unique
|
|
|
|
makeUniqueAlias :: FieldName -> JoinColumnAlias
|
|
|
|
makeUniqueAlias fieldName =
|
2021-09-24 01:56:37 +03:00
|
|
|
let suffix =
|
|
|
|
"_join_column"
|
|
|
|
<>
|
|
|
|
-- 12 is the length of "_join_column"
|
|
|
|
T.replicate ((longestAliasLength - (T.length (coerce fieldName) + 12)) + 1) "_"
|
|
|
|
in JCPhantom $ fieldName <> FieldName suffix
|
|
|
|
|
|
|
|
transformAnnRelation ::
|
|
|
|
(a -> Collector b) ->
|
|
|
|
AnnRelationSelectG src a ->
|
|
|
|
Collector (AnnRelationSelectG src b)
|
2021-08-06 16:39:00 +03:00
|
|
|
transformAnnRelation transform relation@(AnnRelationSelectG _ _ select) = do
|
|
|
|
transformedSelect <- transform select
|
2021-09-24 01:56:37 +03:00
|
|
|
pure $ relation {aarAnnSelect = transformedSelect}
|
|
|
|
|
|
|
|
mkScalarComputedFieldSelect ::
|
|
|
|
ScalarComputedField b ->
|
|
|
|
(AnnFieldG b (Const Void) (UnpreparedValue b))
|
|
|
|
mkScalarComputedFieldSelect ScalarComputedField {..} =
|
|
|
|
let functionArgs =
|
|
|
|
flip FunctionArgsExp mempty $
|
|
|
|
functionArgsWithTableRowAndSession UVSession _scfTableArgument _scfSessionArgument
|
|
|
|
fieldSelect =
|
|
|
|
flip CFSScalar Nothing $
|
|
|
|
ComputedFieldScalarSelect _scfFunction functionArgs _scfType Nothing
|
|
|
|
in AFComputedField _scfXField _scfName fieldSelect
|
|
|
|
|
|
|
|
getRemoteJoinsSourceRelation ::
|
|
|
|
Backend b =>
|
|
|
|
SourceRelationshipSelection b (RemoteSelect UnpreparedValue) UnpreparedValue ->
|
|
|
|
(SourceRelationshipSelection b (Const Void) UnpreparedValue, Maybe RemoteJoins)
|
2021-09-22 13:43:05 +03:00
|
|
|
getRemoteJoinsSourceRelation = runCollector . transformSourceRelation
|
|
|
|
where
|
|
|
|
transformSourceRelation = \case
|
|
|
|
SourceRelationshipObject objectSelect ->
|
|
|
|
SourceRelationshipObject <$> transformObjectSelect objectSelect
|
|
|
|
SourceRelationshipArray simpleSelect ->
|
|
|
|
SourceRelationshipArray <$> transformSelect simpleSelect
|
|
|
|
SourceRelationshipArrayAggregate aggregateSelect ->
|
|
|
|
SourceRelationshipArrayAggregate <$> transformAggregateSelect aggregateSelect
|