2021-06-11 06:26:50 +03:00
|
|
|
module Hasura.GraphQL.Execute.RemoteJoin.Join
|
2021-09-24 01:56:37 +03:00
|
|
|
( processRemoteJoins,
|
2022-03-10 18:25:25 +03:00
|
|
|
foldJoinTreeWith,
|
2021-09-24 01:56:37 +03:00
|
|
|
)
|
|
|
|
where
|
2020-05-27 18:02:58 +03:00
|
|
|
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
import Control.Lens (view, _3)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Aeson.Ordered qualified as JO
|
2022-03-10 18:25:25 +03:00
|
|
|
import Data.ByteString.Lazy qualified as BL
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Environment qualified as Env
|
|
|
|
import Data.HashMap.Strict.Extended qualified as Map
|
|
|
|
import Data.HashMap.Strict.InsOrd qualified as OMap
|
2022-03-01 19:03:23 +03:00
|
|
|
import Data.HashMap.Strict.NonEmpty qualified as NEMap
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.HashSet qualified as HS
|
2022-03-03 23:12:09 +03:00
|
|
|
import Data.IntMap.Strict.Extended qualified as IntMap
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Text qualified as T
|
|
|
|
import Data.Tuple (swap)
|
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.EncJSON
|
|
|
|
import Hasura.GraphQL.Execute.Backend qualified as EB
|
|
|
|
import Hasura.GraphQL.Execute.Instances ()
|
|
|
|
import Hasura.GraphQL.Execute.RemoteJoin.RemoteSchema qualified as RS
|
2022-03-10 18:25:25 +03:00
|
|
|
import Hasura.GraphQL.Execute.RemoteJoin.Source qualified as S
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Execute.RemoteJoin.Types
|
|
|
|
import Hasura.GraphQL.Logging (MonadQueryLog)
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
import Hasura.GraphQL.RemoteServer (execRemoteGQ)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Transport.Backend qualified as TB
|
2022-03-10 18:25:25 +03:00
|
|
|
import Hasura.GraphQL.Transport.HTTP.Protocol (GQLReqOutgoing, GQLReqUnparsed)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Transport.Instances ()
|
|
|
|
import Hasura.Logging qualified as L
|
|
|
|
import Hasura.Prelude
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Common
|
|
|
|
import Hasura.RQL.Types.RemoteSchema
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.SQL.AnyBackend qualified as AB
|
|
|
|
import Hasura.Server.Types (RequestId)
|
|
|
|
import Hasura.Session
|
|
|
|
import Hasura.Tracing qualified as Tracing
|
|
|
|
import Network.HTTP.Client qualified as HTTP
|
2022-02-16 10:08:51 +03:00
|
|
|
import Network.HTTP.Types qualified as HTTP
|
2020-05-27 18:02:58 +03:00
|
|
|
|
2022-03-10 18:25:25 +03:00
|
|
|
-------------------------------------------------------------------------------
|
2021-08-06 16:39:00 +03:00
|
|
|
|
2022-03-10 18:25:25 +03:00
|
|
|
-- | Process all remote joins, recursively.
|
|
|
|
--
|
|
|
|
-- Given the result of the first step of an execution and its associated remote
|
|
|
|
-- joins, process all joins recursively to build the resulting JSON object.
|
|
|
|
--
|
|
|
|
-- This function is a thin wrapper around 'processRemoteJoinsWith', and starts
|
|
|
|
-- the join tree traversal process by re-parsing the 'EncJSON' value into an
|
|
|
|
-- introspectable JSON 'Value', and "injects" the required functions to process
|
|
|
|
-- each join over the network.
|
2021-09-24 01:56:37 +03:00
|
|
|
processRemoteJoins ::
|
2022-03-10 18:25:25 +03:00
|
|
|
forall m.
|
2021-10-13 19:38:56 +03:00
|
|
|
( MonadError QErr m,
|
2021-09-24 01:56:37 +03:00
|
|
|
MonadIO m,
|
|
|
|
EB.MonadQueryTags m,
|
|
|
|
MonadQueryLog m,
|
|
|
|
Tracing.MonadTrace m
|
|
|
|
) =>
|
|
|
|
RequestId ->
|
|
|
|
L.Logger L.Hasura ->
|
|
|
|
Env.Environment ->
|
|
|
|
HTTP.Manager ->
|
2022-02-16 10:08:51 +03:00
|
|
|
[HTTP.Header] ->
|
2021-09-24 01:56:37 +03:00
|
|
|
UserInfo ->
|
|
|
|
EncJSON ->
|
|
|
|
Maybe RemoteJoins ->
|
|
|
|
GQLReqUnparsed ->
|
|
|
|
m EncJSON
|
2022-03-10 18:25:25 +03:00
|
|
|
processRemoteJoins requestId logger env manager requestHeaders userInfo lhs maybeJoinTree gqlreq =
|
|
|
|
forRemoteJoins maybeJoinTree lhs \joinTree -> do
|
|
|
|
lhsParsed <-
|
|
|
|
JO.eitherDecode (encJToLBS lhs)
|
|
|
|
`onLeft` (throw500 . T.pack)
|
|
|
|
jsonResult <-
|
|
|
|
foldJoinTreeWith
|
|
|
|
callSource
|
|
|
|
callRemoteServer
|
2021-09-24 01:56:37 +03:00
|
|
|
userInfo
|
|
|
|
(Identity lhsParsed)
|
2022-03-10 18:25:25 +03:00
|
|
|
joinTree
|
|
|
|
pure $ encJFromOrderedValue $ runIdentity jsonResult
|
|
|
|
where
|
|
|
|
-- How to process a source join call over the network.
|
|
|
|
callSource ::
|
|
|
|
-- Generated information about the step
|
|
|
|
AB.AnyBackend S.SourceJoinCall ->
|
|
|
|
-- Resulting JSON object, as a 'ByteString'.
|
|
|
|
m BL.ByteString
|
|
|
|
callSource sourceJoinCall =
|
|
|
|
AB.dispatchAnyBackend @TB.BackendTransport sourceJoinCall \(S.SourceJoinCall {..} :: S.SourceJoinCall b) -> do
|
|
|
|
response <-
|
|
|
|
TB.runDBQuery @b
|
|
|
|
requestId
|
|
|
|
gqlreq
|
|
|
|
_sjcRootFieldAlias
|
|
|
|
userInfo
|
|
|
|
logger
|
|
|
|
_sjcSourceConfig
|
|
|
|
(EB.dbsiAction _sjcStepInfo)
|
|
|
|
(EB.dbsiPreparedQuery _sjcStepInfo)
|
|
|
|
pure $ encJToLBS $ snd response
|
2021-08-06 16:39:00 +03:00
|
|
|
|
2022-03-10 18:25:25 +03:00
|
|
|
-- How to process a remote schema join call over the network.
|
|
|
|
callRemoteServer ::
|
|
|
|
-- Information about the remote schema
|
|
|
|
ValidatedRemoteSchemaDef ->
|
|
|
|
-- Generated GraphQL request
|
|
|
|
GQLReqOutgoing ->
|
|
|
|
-- Resulting JSON object, as a 'ByteString'.
|
|
|
|
m BL.ByteString
|
|
|
|
callRemoteServer remoteSchemaInfo request =
|
|
|
|
fmap (view _3) $
|
|
|
|
execRemoteGQ env manager userInfo requestHeaders remoteSchemaInfo request
|
|
|
|
|
|
|
|
-- | Fold the join tree.
|
|
|
|
--
|
|
|
|
-- This function takes as an argument the functions that will be used to do the
|
|
|
|
-- actual network calls; this allows this function not to require 'MonadIO',
|
|
|
|
-- allowing it to be used in tests.
|
|
|
|
foldJoinTreeWith ::
|
2021-10-13 19:38:56 +03:00
|
|
|
( MonadError QErr m,
|
2021-09-24 01:56:37 +03:00
|
|
|
EB.MonadQueryTags m,
|
|
|
|
Traversable f
|
|
|
|
) =>
|
2022-03-10 18:25:25 +03:00
|
|
|
-- | How to process a call to a source.
|
|
|
|
(AB.AnyBackend S.SourceJoinCall -> m BL.ByteString) ->
|
|
|
|
-- | How to process a call to a remote schema.
|
|
|
|
(ValidatedRemoteSchemaDef -> GQLReqOutgoing -> m BL.ByteString) ->
|
|
|
|
-- | User information.
|
2021-09-24 01:56:37 +03:00
|
|
|
UserInfo ->
|
2022-03-10 18:25:25 +03:00
|
|
|
-- | Initial accumulator; the LHS of this join tree.
|
|
|
|
(f JO.Value) ->
|
2021-09-24 01:56:37 +03:00
|
|
|
RemoteJoins ->
|
|
|
|
m (f JO.Value)
|
2022-03-10 18:25:25 +03:00
|
|
|
foldJoinTreeWith callSource callRemoteSchema userInfo lhs joinTree = do
|
2021-08-06 16:39:00 +03:00
|
|
|
(compositeValue, joins) <- collectJoinArguments (assignJoinIds joinTree) lhs
|
2022-03-03 23:12:09 +03:00
|
|
|
joinIndices <- fmap IntMap.catMaybes $
|
2021-09-24 01:56:37 +03:00
|
|
|
for joins $ \JoinArguments {..} -> do
|
|
|
|
let joinArguments = IntMap.fromList $ map swap $ Map.toList _jalArguments
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
previousStep <- case _jalJoin of
|
|
|
|
RemoteJoinRemoteSchema remoteSchemaJoin childJoinTree -> do
|
|
|
|
let remoteSchemaInfo = rsDef $ _rsjRemoteSchema remoteSchemaJoin
|
2022-03-10 18:25:25 +03:00
|
|
|
maybeJoinIndex <- RS.makeRemoteSchemaJoinCall (callRemoteSchema remoteSchemaInfo) userInfo remoteSchemaJoin joinArguments
|
|
|
|
pure $ fmap (childJoinTree,) maybeJoinIndex
|
|
|
|
RemoteJoinSource sourceJoin childJoinTree -> do
|
|
|
|
maybeJoinIndex <- S.makeSourceJoinCall callSource userInfo sourceJoin _jalFieldName joinArguments
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
pure $ fmap (childJoinTree,) maybeJoinIndex
|
|
|
|
for previousStep $ \(childJoinTree, joinIndex) -> do
|
|
|
|
forRemoteJoins childJoinTree joinIndex $ \childRemoteJoins -> do
|
|
|
|
results <-
|
2022-03-10 18:25:25 +03:00
|
|
|
foldJoinTreeWith
|
|
|
|
callSource
|
|
|
|
callRemoteSchema
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
userInfo
|
|
|
|
(IntMap.elems joinIndex)
|
|
|
|
childRemoteJoins
|
|
|
|
pure $ IntMap.fromAscList $ zip (IntMap.keys joinIndex) results
|
2021-08-06 16:39:00 +03:00
|
|
|
joinResults joinIndices compositeValue
|
2020-05-27 18:02:58 +03:00
|
|
|
|
2022-03-10 18:25:25 +03:00
|
|
|
-------------------------------------------------------------------------------
|
2020-05-27 18:02:58 +03:00
|
|
|
|
2022-03-10 18:25:25 +03:00
|
|
|
-- | Simple convenient wrapper around @Maybe RemoteJoins@.
|
|
|
|
forRemoteJoins ::
|
|
|
|
(Applicative f) =>
|
|
|
|
Maybe RemoteJoins ->
|
|
|
|
a ->
|
|
|
|
(RemoteJoins -> f a) ->
|
|
|
|
f a
|
|
|
|
forRemoteJoins remoteJoins onNoJoins f =
|
|
|
|
maybe (pure onNoJoins) f remoteJoins
|
2021-08-06 16:39:00 +03:00
|
|
|
|
|
|
|
-- | When traversing a responses's json, wherever the join columns of a remote
|
|
|
|
-- join are expected, we want to collect these arguments.
|
|
|
|
--
|
|
|
|
-- However looking up by a remote join's definition to collect these arguments
|
|
|
|
-- does not work because we don't have an 'Ord' or a 'Hashable' instance (it
|
|
|
|
-- would be a bit of work).
|
|
|
|
--
|
|
|
|
-- So this assigned each remote join a unique integer ID by using just the 'Eq'
|
|
|
|
-- instance. This ID then can be used for the collection of arguments (which
|
|
|
|
-- should also be faster).
|
2022-03-10 18:25:25 +03:00
|
|
|
--
|
|
|
|
-- TODO(nicuveo): https://github.com/hasura/graphql-engine-mono/issues/3891.
|
2021-08-06 16:39:00 +03:00
|
|
|
assignJoinIds :: JoinTree RemoteJoin -> JoinTree (JoinCallId, RemoteJoin)
|
|
|
|
assignJoinIds joinTree =
|
|
|
|
evalState (traverse assignId joinTree) (0, [])
|
2020-05-27 18:02:58 +03:00
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
assignId ::
|
|
|
|
RemoteJoin ->
|
|
|
|
State (JoinCallId, [(JoinCallId, RemoteJoin)]) (JoinCallId, RemoteJoin)
|
2021-08-06 16:39:00 +03:00
|
|
|
assignId remoteJoin = do
|
|
|
|
(joinCallId, joinIds) <- get
|
2021-09-22 13:43:05 +03:00
|
|
|
let mJoinId = joinIds & find \(_, j) -> j == remoteJoin
|
2021-08-06 16:39:00 +03:00
|
|
|
mJoinId `onNothing` do
|
2021-09-24 01:56:37 +03:00
|
|
|
put (joinCallId + 1, (joinCallId, remoteJoin) : joinIds)
|
2021-08-06 16:39:00 +03:00
|
|
|
pure (joinCallId, remoteJoin)
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
collectJoinArguments ::
|
|
|
|
forall f m.
|
|
|
|
(MonadError QErr m, Traversable f) =>
|
|
|
|
JoinTree (JoinCallId, RemoteJoin) ->
|
|
|
|
f JO.Value ->
|
|
|
|
m (f (CompositeValue ReplacementToken), IntMap.IntMap JoinArguments)
|
2021-08-06 16:39:00 +03:00
|
|
|
collectJoinArguments joinTree lhs = do
|
|
|
|
result <- flip runStateT (0, mempty) $ traverse (traverseValue joinTree) lhs
|
|
|
|
-- Discard the 'JoinArgumentId' from the intermediate state transformation.
|
|
|
|
pure $ second snd result
|
2020-05-27 18:02:58 +03:00
|
|
|
where
|
2021-09-24 01:56:37 +03:00
|
|
|
getReplacementToken ::
|
|
|
|
IntMap.Key ->
|
|
|
|
RemoteJoin ->
|
|
|
|
JoinArgument ->
|
|
|
|
FieldName ->
|
|
|
|
StateT
|
|
|
|
(JoinArgumentId, IntMap.IntMap JoinArguments)
|
|
|
|
m
|
|
|
|
ReplacementToken
|
2021-09-22 13:43:05 +03:00
|
|
|
getReplacementToken joinId remoteJoin argument fieldName = do
|
2021-08-06 16:39:00 +03:00
|
|
|
(counter, joins) <- get
|
|
|
|
case IntMap.lookup joinId joins of
|
2021-09-22 13:43:05 +03:00
|
|
|
-- XXX: We're making an explicit decision to ignore the existing
|
|
|
|
-- 'fieldName' and replace it with the argument provided to this
|
|
|
|
-- function.
|
|
|
|
--
|
|
|
|
-- This needs to be tested so we can verify that the result of this
|
|
|
|
-- function call is reasonable.
|
|
|
|
Just (JoinArguments _remoteJoin arguments _fieldName) ->
|
2021-08-06 16:39:00 +03:00
|
|
|
case Map.lookup argument arguments of
|
|
|
|
Just argumentId -> pure $ ReplacementToken joinId argumentId
|
2021-09-24 01:56:37 +03:00
|
|
|
Nothing -> addNewArgument counter joins arguments
|
2021-08-06 16:39:00 +03:00
|
|
|
Nothing -> addNewArgument counter joins mempty
|
|
|
|
where
|
|
|
|
addNewArgument counter joins arguments = do
|
|
|
|
let argumentId = counter
|
2021-09-22 13:43:05 +03:00
|
|
|
newArguments =
|
|
|
|
JoinArguments
|
|
|
|
remoteJoin
|
|
|
|
(Map.insert argument argumentId arguments)
|
|
|
|
fieldName
|
2021-08-06 16:39:00 +03:00
|
|
|
put (counter + 1, IntMap.insert joinId newArguments joins)
|
|
|
|
pure $ ReplacementToken joinId argumentId
|
2020-05-27 18:02:58 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
traverseValue ::
|
|
|
|
JoinTree (IntMap.Key, RemoteJoin) ->
|
|
|
|
JO.Value ->
|
|
|
|
StateT
|
|
|
|
(JoinArgumentId, IntMap.IntMap JoinArguments)
|
|
|
|
m
|
|
|
|
(CompositeValue ReplacementToken)
|
2021-08-06 16:39:00 +03:00
|
|
|
traverseValue joinTree_ = \case
|
2021-09-22 13:43:05 +03:00
|
|
|
-- 'JO.Null' is a special case of scalar value here, which indicates that
|
2021-08-06 16:39:00 +03:00
|
|
|
-- the previous step did not return enough data for us to continue
|
|
|
|
-- traversing down this path.
|
|
|
|
--
|
|
|
|
-- This can occur in the following cases:
|
|
|
|
-- * Permission errors; when the user joins on a value they are not
|
|
|
|
-- allowed to access
|
|
|
|
-- * Queries with remote sources that resolve to null, for example:
|
|
|
|
-- {
|
|
|
|
-- q {
|
|
|
|
-- user_by_pk() {
|
|
|
|
-- id
|
|
|
|
-- name
|
|
|
|
-- r {
|
|
|
|
-- }
|
|
|
|
-- address {
|
|
|
|
-- r_geo {
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- }
|
2021-09-24 01:56:37 +03:00
|
|
|
JO.Null -> pure $ CVOrdValue JO.Null
|
2021-09-22 13:43:05 +03:00
|
|
|
JO.Object object -> CVObject <$> traverseObject joinTree_ object
|
2021-09-24 01:56:37 +03:00
|
|
|
JO.Array array -> CVObjectArray <$> mapM (traverseValue joinTree_) (toList array)
|
|
|
|
_ -> throw500 "found a scalar value when traversing with a non-empty join tree"
|
2021-08-06 16:39:00 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
traverseObject ::
|
|
|
|
JoinTree (IntMap.Key, RemoteJoin) ->
|
|
|
|
JO.Object ->
|
|
|
|
StateT
|
|
|
|
(JoinArgumentId, IntMap.IntMap JoinArguments)
|
|
|
|
m
|
|
|
|
(InsOrdHashMap Text (CompositeValue ReplacementToken))
|
2021-08-06 16:39:00 +03:00
|
|
|
traverseObject joinTree_ object = do
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
let joinTreeNodes = unJoinTree joinTree_
|
|
|
|
phantomFields =
|
2021-09-24 01:56:37 +03:00
|
|
|
HS.fromList $
|
|
|
|
map getFieldNameTxt $
|
|
|
|
concatMap (getPhantomFields . snd) $ toList joinTree_
|
2021-08-06 16:39:00 +03:00
|
|
|
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
-- If we need the typename to disambiguate branches in the join tree, it
|
|
|
|
-- will be present in the answer as a placeholder internal field.
|
|
|
|
--
|
|
|
|
-- We currently have no way of checking whether we explicitly requested
|
|
|
|
-- that field, and it would be possible for a malicious user to attempt to
|
|
|
|
-- spoof that value by explicitly requesting a value they control.
|
|
|
|
-- However, there's no actual risk: we only use that value for lookups
|
|
|
|
-- inside the join tree, and if we didn't request this field, the keys in
|
|
|
|
-- the join tree map will explicitly require a typename NOT to be
|
|
|
|
-- provided. Meaning that any spoofing attempt will just, at worst, result
|
|
|
|
-- in remote joins not being performed.
|
|
|
|
--
|
|
|
|
-- We always remove that key from the resulting object.
|
|
|
|
joinTypeName <- case JO.lookup "__hasura_internal_typename" object of
|
|
|
|
Nothing -> pure Nothing
|
|
|
|
Just (JO.String typename) -> pure $ Just typename
|
|
|
|
Just value -> throw500 $ "The reserved __hasura_internal_typename field contains an unexpected value: " <> tshow value
|
2021-08-06 16:39:00 +03:00
|
|
|
|
|
|
|
-- during this traversal we assume that the remote join column has some
|
|
|
|
-- placeholder value in the response. If this weren't present it would
|
|
|
|
-- involve a lot more book-keeping to preserve the order of the original
|
|
|
|
-- selection set in the response
|
2021-09-22 13:43:05 +03:00
|
|
|
compositeObject <- for (JO.toList object) $ \(fieldName, value_) ->
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
(fieldName,) <$> case NEMap.lookup (QualifiedFieldName joinTypeName fieldName) joinTreeNodes of
|
2021-08-06 16:39:00 +03:00
|
|
|
Just (Leaf (joinId, remoteJoin)) -> do
|
|
|
|
joinArgument <- forM (getJoinColumnMapping remoteJoin) $ \alias -> do
|
|
|
|
let aliasTxt = getFieldNameTxt $ getAliasFieldName alias
|
2021-09-22 13:43:05 +03:00
|
|
|
onNothing (JO.lookup aliasTxt object) $
|
2021-08-06 16:39:00 +03:00
|
|
|
throw500 $ "a join column is missing from the response: " <> aliasTxt
|
2021-09-22 13:43:05 +03:00
|
|
|
if Map.null (Map.filter (== JO.Null) joinArgument)
|
2021-09-24 01:56:37 +03:00
|
|
|
then
|
|
|
|
Just . CVFromRemote
|
|
|
|
<$> getReplacementToken joinId remoteJoin (JoinArgument joinArgument) (FieldName fieldName)
|
|
|
|
else -- we do not join with the remote field if any of the leaves of
|
|
|
|
-- the join argument are null
|
|
|
|
pure $ Just $ CVOrdValue JO.Null
|
2021-08-06 16:39:00 +03:00
|
|
|
Just (Tree joinSubTree) ->
|
|
|
|
Just <$> traverseValue joinSubTree value_
|
|
|
|
Nothing ->
|
Enable remote joins from remote schemas in the execution engine.
### Description
This PR adds the ability to perform remote joins from remote schemas in the engine. To do so, we alter the definition of an `ExecutionStep` targeting a remote schema: the `ExecStepRemote` constructor now expects a `Maybe RemoteJoins`. This new argument is used when processing the execution step, in the transport layer (either `Transport.HTTP` or `Transport.WebSocket`).
For this `Maybe RemoteJoins` to be extracted from a parsed query, this PR also extends the `Execute.RemoteJoin.Collect` module, to implement "collection" from a selection set. Not only do those new functions extract the remote joins, but they also apply all necessary transformations to the selection sets (such as inserting the necessary "phantom" fields used as join keys).
Finally in `Execute.RemoteJoin.Join`, we make two changes. First, we now always look for nested remote joins, regardless of whether the join we just performed went to a source or a remote schema; and second we adapt our join tree logic according to the special cases that were added to deal with remote server edge cases.
Additionally, this PR refactors / cleans / documents `Execute.RemoteJoin.RemoteServer`. This is not required as part of this change and could be moved to a separate PR if needed (a similar cleanup of `Join` is done independently in #3894). It also introduces a draft of a new documentation page for this project, that will be refined in the release PR that ships the feature (either #3069 or a copy of it).
While this PR extends the engine, it doesn't plug such relationships in the schema, meaning that, as of this PR, the new code paths in `Join` are technically unreachable. Adding the corresponding schema code and, ultimately, enabling the metadata API will be done in subsequent PRs.
### Keeping track of concrete type names
The main change this PR makes to the existing `Join` code is to handle a new reserved field we sometimes use when targeting remote servers: the `__hasura_internal_typename` field. In short, a GraphQL selection set can sometimes "branch" based on the concrete "runtime type" of the object on which the selection happens:
```graphql
query {
author(id: 53478) {
... on Writer {
name
articles {
title
}
}
... on Artist {
name
articles {
title
}
}
}
}
```
If both of those `articles` are remote joins, we need to be able, when we get the answer, to differentiate between the two different cases. We do this by asking for `__typename`, to be able to decide if we're in the `Writer` or the `Artist` branch of the query.
To avoid further processing / customization of results, we only insert this `__hasura_internal_typename: __typename` field in the query in the case of unions of interfaces AND if we have the guarantee that we will processing the request as part of the remote joins "folding": that is, if there's any remote join in this branch in the tree. Otherwise, we don't insert the field, and we leave that part of the response untouched.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3810
GitOrigin-RevId: 89aaf16274d68e26ad3730b80c2d2fdc2896b96c
2022-03-09 06:17:28 +03:00
|
|
|
if HS.member fieldName phantomFields || fieldName == "__hasura_internal_typename"
|
2021-09-24 01:56:37 +03:00
|
|
|
then pure Nothing
|
|
|
|
else pure $ Just $ CVOrdValue value_
|
2021-08-06 16:39:00 +03:00
|
|
|
|
|
|
|
pure . OMap.fromList $
|
|
|
|
-- filter out the Nothings
|
|
|
|
mapMaybe sequenceA compositeObject
|
2022-03-10 18:25:25 +03:00
|
|
|
|
|
|
|
joinResults ::
|
|
|
|
forall f m.
|
|
|
|
(MonadError QErr m, Traversable f) =>
|
|
|
|
IntMap.IntMap (IntMap.IntMap JO.Value) ->
|
|
|
|
f (CompositeValue ReplacementToken) ->
|
|
|
|
m (f JO.Value)
|
|
|
|
joinResults remoteResults compositeValues = do
|
|
|
|
traverse (fmap compositeValueToJSON . traverse replaceToken) compositeValues
|
|
|
|
where
|
|
|
|
replaceToken :: ReplacementToken -> m JO.Value
|
|
|
|
replaceToken (ReplacementToken joinCallId argumentId) = do
|
|
|
|
joinCallResults <-
|
|
|
|
onNothing (IntMap.lookup joinCallId remoteResults) $
|
|
|
|
throw500 $
|
|
|
|
"couldn't find results for the join with id: "
|
|
|
|
<> tshow joinCallId
|
|
|
|
onNothing (IntMap.lookup argumentId joinCallResults) $
|
|
|
|
throw500 $
|
|
|
|
"couldn't find a value for argument id in the join results: "
|
|
|
|
<> tshow (argumentId, joinCallId)
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type CompositeObject a = OMap.InsOrdHashMap Text (CompositeValue a)
|
|
|
|
|
|
|
|
-- | A hybrid JSON value representation which captures the context of remote join field in type parameter.
|
|
|
|
data CompositeValue a
|
|
|
|
= CVOrdValue !JO.Value
|
|
|
|
| CVObject !(CompositeObject a)
|
|
|
|
| CVObjectArray ![CompositeValue a]
|
|
|
|
| CVFromRemote !a
|
|
|
|
deriving (Show, Eq, Functor, Foldable, Traversable)
|
|
|
|
|
|
|
|
compositeValueToJSON :: CompositeValue JO.Value -> JO.Value
|
|
|
|
compositeValueToJSON = \case
|
|
|
|
CVOrdValue v -> v
|
|
|
|
CVObject obj -> JO.object $ OMap.toList $ OMap.map compositeValueToJSON obj
|
|
|
|
CVObjectArray vals -> JO.array $ map compositeValueToJSON vals
|
|
|
|
CVFromRemote v -> v
|
|
|
|
|
|
|
|
-- | A token used to uniquely identify the results within a join call that are
|
|
|
|
-- associated with a particular argument.
|
|
|
|
data ReplacementToken = ReplacementToken
|
|
|
|
{ -- | Unique identifier for a remote join call.
|
|
|
|
_rtCallId :: !JoinCallId,
|
|
|
|
-- | Unique identifier for an argument to some remote join.
|
|
|
|
_rtArgumentId :: !JoinArgumentId
|
|
|
|
}
|