mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
11a454c2d6
This commit applies ormolu to the whole Haskell code base by running `make format`. For in-flight branches, simply merging changes from `main` will result in merge conflicts. To avoid this, update your branch using the following instructions. Replace `<format-commit>` by the hash of *this* commit. $ git checkout my-feature-branch $ git merge <format-commit>^ # and resolve conflicts normally $ make format $ git commit -a -m "reformat with ormolu" $ git merge -s ours post-ormolu https://github.com/hasura/graphql-engine-mono/pull/2404 GitOrigin-RevId: 75049f5c12f430c615eafb4c6b8e83e371e01c8e
64 lines
2.5 KiB
Haskell
64 lines
2.5 KiB
Haskell
module Hasura.GraphQL.Schema.RemoteSource
|
|
( remoteSourceField,
|
|
)
|
|
where
|
|
|
|
import Hasura.GraphQL.Parser
|
|
import Hasura.GraphQL.Schema.Backend
|
|
import Hasura.GraphQL.Schema.Common
|
|
import Hasura.GraphQL.Schema.Instances ()
|
|
import Hasura.GraphQL.Schema.Select
|
|
import Hasura.GraphQL.Schema.Table
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.IR.Select qualified as IR
|
|
import Hasura.RQL.Types.Common (RelType (..))
|
|
import Hasura.RQL.Types.RemoteRelationship
|
|
import Hasura.SQL.AnyBackend
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
|
|
-- | TODO(jkachmar): Documentation.
|
|
remoteSourceField ::
|
|
forall b r m n.
|
|
MonadBuildSchema b r m n =>
|
|
AnyBackend (RemoteSourceRelationshipInfo b) ->
|
|
m [FieldParser n (AnnotatedField b)]
|
|
remoteSourceField remoteDB = dispatchAnyBackend @BackendSchema remoteDB buildField
|
|
where
|
|
buildField ::
|
|
forall src tgt.
|
|
BackendSchema tgt =>
|
|
RemoteSourceRelationshipInfo src tgt ->
|
|
m [FieldParser n (AnnotatedField src)]
|
|
buildField (RemoteSourceRelationshipInfo {..}) = do
|
|
tableInfo <- askTableInfo @tgt _rsriSource _rsriTable
|
|
fieldName <- textToName $ remoteRelationshipNameToText _rsriName
|
|
maybePerms <- tableSelectPermissions @tgt tableInfo
|
|
case maybePerms of
|
|
Nothing -> pure []
|
|
Just tablePerms -> do
|
|
parsers <- case _rsriType of
|
|
ObjRel -> do
|
|
selectionSetParser <- tableSelectionSet _rsriSource tableInfo tablePerms
|
|
pure $
|
|
pure $
|
|
subselection_ fieldName Nothing selectionSetParser <&> \fields ->
|
|
IR.SourceRelationshipObject $
|
|
IR.AnnObjectSelectG fields _rsriTable $
|
|
IR._tpFilter $
|
|
tablePermissionsInfo tablePerms
|
|
ArrRel -> do
|
|
let aggFieldName = fieldName <> $$(G.litName "_aggregate")
|
|
selectionSetParser <- selectTable _rsriSource tableInfo fieldName Nothing tablePerms
|
|
aggSelectionSetParser <- selectTableAggregate _rsriSource tableInfo aggFieldName Nothing tablePerms
|
|
pure $
|
|
catMaybes
|
|
[ Just $ selectionSetParser <&> IR.SourceRelationshipArray,
|
|
aggSelectionSetParser <&> fmap IR.SourceRelationshipArrayAggregate
|
|
]
|
|
pure $
|
|
parsers <&> fmap \select ->
|
|
IR.AFRemote $
|
|
IR.RemoteSelectSource $
|
|
mkAnyBackend @tgt $
|
|
IR.RemoteSourceSelect _rsriSource _rsriSourceConfig select _rsriMapping
|