server: add IR support for DB-to-DB joins

GJ IR changes cherry-picked from the original GJ branch. There is a separate (can be merged independently) PR for metadata changes (#1727) and there will be a different PR upcoming PR for execution changes.

https://github.com/hasura/graphql-engine-mono/pull/1810

Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: c31956af29dc9c9b75d002aba7d93c230697c5f4
This commit is contained in:
Evie Ciobanu 2021-07-26 16:03:51 +03:00 committed by hasura-bot
parent b8cd59551f
commit 4b0f5f09c9
24 changed files with 200 additions and 184 deletions

View File

@ -791,17 +791,6 @@ fromAnnFieldsG existingJoins stringifyNumbers (Rql.FieldName name, field) =
(\aliasedThing -> (\aliasedThing ->
JoinFieldSource (Aliased {aliasedThing, aliasedAlias = name})) JoinFieldSource (Aliased {aliasedThing, aliasedAlias = name}))
(fromArraySelectG arraySelectG) (fromArraySelectG arraySelectG)
-- this will be gone once the code which collects remote joins from the IR
-- emits a modified IR where remote relationships can't be reached
Ir.AFRemote _ ->
pure
(ExpressionFieldSource
Aliased
{ aliasedThing = BigQuery.ValueExpression (StringValue "null: remote field selected")
, aliasedAlias = name
})
-- TODO: implement this
Ir.AFDBRemote _ -> error "FIXME"
-- | Here is where we project a field as a column expression. If -- | Here is where we project a field as a column expression. If

View File

@ -77,7 +77,7 @@ bqBuildTableRelayQueryFields
-> G.Name -> G.Name
-> NESeq (ColumnInfo 'BigQuery) -> NESeq (ColumnInfo 'BigQuery)
-> SelPermInfo 'BigQuery -> SelPermInfo 'BigQuery
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
bqBuildTableRelayQueryFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms = bqBuildTableRelayQueryFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms =
pure [] pure []
@ -91,7 +91,7 @@ bqBuildTableInsertMutationFields
-> InsPermInfo 'BigQuery -> InsPermInfo 'BigQuery
-> Maybe (SelPermInfo 'BigQuery) -> Maybe (SelPermInfo 'BigQuery)
-> Maybe (UpdPermInfo 'BigQuery) -> Maybe (UpdPermInfo 'BigQuery)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
bqBuildTableInsertMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms = bqBuildTableInsertMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms =
pure [] pure []
@ -104,7 +104,7 @@ bqBuildTableUpdateMutationFields
-> G.Name -> G.Name
-> UpdPermInfo 'BigQuery -> UpdPermInfo 'BigQuery
-> Maybe (SelPermInfo 'BigQuery) -> Maybe (SelPermInfo 'BigQuery)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
bqBuildTableUpdateMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms = bqBuildTableUpdateMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms =
pure [] pure []
@ -117,7 +117,7 @@ bqBuildTableDeleteMutationFields
-> G.Name -> G.Name
-> DelPermInfo 'BigQuery -> DelPermInfo 'BigQuery
-> Maybe (SelPermInfo 'BigQuery) -> Maybe (SelPermInfo 'BigQuery)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
bqBuildTableDeleteMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms = bqBuildTableDeleteMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms =
pure [] pure []
@ -129,7 +129,7 @@ bqBuildFunctionQueryFields
-> FunctionInfo 'BigQuery -> FunctionInfo 'BigQuery
-> TableName 'BigQuery -> TableName 'BigQuery
-> SelPermInfo 'BigQuery -> SelPermInfo 'BigQuery
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
bqBuildFunctionQueryFields _ _ _ _ _ _ = bqBuildFunctionQueryFields _ _ _ _ _ _ =
pure [] pure []
@ -142,7 +142,7 @@ bqBuildFunctionRelayQueryFields
-> TableName 'BigQuery -> TableName 'BigQuery
-> NESeq (ColumnInfo 'BigQuery) -> NESeq (ColumnInfo 'BigQuery)
-> SelPermInfo 'BigQuery -> SelPermInfo 'BigQuery
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
bqBuildFunctionRelayQueryFields _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms = bqBuildFunctionRelayQueryFields _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms =
pure [] pure []
@ -154,7 +154,7 @@ bqBuildFunctionMutationFields
-> FunctionInfo 'BigQuery -> FunctionInfo 'BigQuery
-> TableName 'BigQuery -> TableName 'BigQuery
-> SelPermInfo 'BigQuery -> SelPermInfo 'BigQuery
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
bqBuildFunctionMutationFields _ _ _ _ _ _ = bqBuildFunctionMutationFields _ _ _ _ _ _ =
pure [] pure []

View File

@ -727,18 +727,6 @@ fromAnnFieldsG existingJoins stringifyNumbers (IR.FieldName name, field) =
(\aliasedThing -> (\aliasedThing ->
JoinFieldSource (Aliased {aliasedThing, aliasedAlias = name})) JoinFieldSource (Aliased {aliasedThing, aliasedAlias = name}))
(fromArraySelectG arraySelectG) (fromArraySelectG arraySelectG)
-- this will be gone once the code which collects remote joins from the IR
-- emits a modified IR where remote relationships can't be reached
IR.AFRemote _ ->
pure
(ExpressionFieldSource
Aliased
{ aliasedThing = TSQL.ValueExpression
(ODBC.TextValue "null: remote field selected")
, aliasedAlias = name
})
-- TODO: implement this
IR.AFDBRemote _ -> error "FIXME"
-- | Here is where we project a field as a column expression. If -- | Here is where we project a field as a column expression. If
-- number stringification is on, then we wrap it in a -- number stringification is on, then we wrap it in a

View File

@ -79,7 +79,7 @@ msBuildTableRelayQueryFields
-> G.Name -> G.Name
-> NESeq (ColumnInfo 'MSSQL) -> NESeq (ColumnInfo 'MSSQL)
-> SelPermInfo 'MSSQL -> SelPermInfo 'MSSQL
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
msBuildTableRelayQueryFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms = msBuildTableRelayQueryFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms =
pure [] pure []
@ -93,7 +93,7 @@ msBuildTableInsertMutationFields
-> InsPermInfo 'MSSQL -> InsPermInfo 'MSSQL
-> Maybe (SelPermInfo 'MSSQL) -> Maybe (SelPermInfo 'MSSQL)
-> Maybe (UpdPermInfo 'MSSQL) -> Maybe (UpdPermInfo 'MSSQL)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
msBuildTableInsertMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms = msBuildTableInsertMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms =
pure [] pure []
@ -106,7 +106,7 @@ msBuildTableUpdateMutationFields
-> G.Name -> G.Name
-> UpdPermInfo 'MSSQL -> UpdPermInfo 'MSSQL
-> Maybe (SelPermInfo 'MSSQL) -> Maybe (SelPermInfo 'MSSQL)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
msBuildTableUpdateMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms = msBuildTableUpdateMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms =
pure [] pure []
@ -119,7 +119,7 @@ msBuildTableDeleteMutationFields
-> G.Name -> G.Name
-> DelPermInfo 'MSSQL -> DelPermInfo 'MSSQL
-> Maybe (SelPermInfo 'MSSQL) -> Maybe (SelPermInfo 'MSSQL)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
msBuildTableDeleteMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms = msBuildTableDeleteMutationFields _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms =
pure [] pure []
@ -131,7 +131,7 @@ msBuildFunctionQueryFields
-> FunctionInfo 'MSSQL -> FunctionInfo 'MSSQL
-> TableName 'MSSQL -> TableName 'MSSQL
-> SelPermInfo 'MSSQL -> SelPermInfo 'MSSQL
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
msBuildFunctionQueryFields _ _ _ _ _ _ = msBuildFunctionQueryFields _ _ _ _ _ _ =
pure [] pure []
@ -144,7 +144,7 @@ msBuildFunctionRelayQueryFields
-> TableName 'MSSQL -> TableName 'MSSQL
-> NESeq (ColumnInfo 'MSSQL) -> NESeq (ColumnInfo 'MSSQL)
-> SelPermInfo 'MSSQL -> SelPermInfo 'MSSQL
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
msBuildFunctionRelayQueryFields _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms = msBuildFunctionRelayQueryFields _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms =
pure [] pure []
@ -156,7 +156,7 @@ msBuildFunctionMutationFields
-> FunctionInfo 'MSSQL -> FunctionInfo 'MSSQL
-> TableName 'MSSQL -> TableName 'MSSQL
-> SelPermInfo 'MSSQL -> SelPermInfo 'MSSQL
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
msBuildFunctionMutationFields _ _ _ _ _ _ = msBuildFunctionMutationFields _ _ _ _ _ _ =
pure [] pure []

View File

@ -79,7 +79,7 @@ buildTableRelayQueryFields' ::
G.Name -> G.Name ->
NESeq (ColumnInfo 'MySQL) -> NESeq (ColumnInfo 'MySQL) ->
SelPermInfo 'MySQL -> SelPermInfo 'MySQL ->
m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (QueryRootField UnpreparedValue)]
buildTableRelayQueryFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms = buildTableRelayQueryFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _pkeyColumns _selPerms =
pure [] pure []
@ -94,7 +94,7 @@ buildTableInsertMutationFields' ::
InsPermInfo 'MySQL -> InsPermInfo 'MySQL ->
Maybe (SelPermInfo 'MySQL) -> Maybe (SelPermInfo 'MySQL) ->
Maybe (UpdPermInfo 'MySQL) -> Maybe (UpdPermInfo 'MySQL) ->
m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableInsertMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms = buildTableInsertMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _insPerms _selPerms _updPerms =
pure [] pure []
@ -108,7 +108,7 @@ buildTableUpdateMutationFields' ::
G.Name -> G.Name ->
UpdPermInfo 'MySQL -> UpdPermInfo 'MySQL ->
Maybe (SelPermInfo 'MySQL) -> Maybe (SelPermInfo 'MySQL) ->
m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableUpdateMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms = buildTableUpdateMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _updPerns _selPerms =
pure [] pure []
@ -122,7 +122,7 @@ buildTableDeleteMutationFields' ::
G.Name -> G.Name ->
DelPermInfo 'MySQL -> DelPermInfo 'MySQL ->
Maybe (SelPermInfo 'MySQL) -> Maybe (SelPermInfo 'MySQL) ->
m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableDeleteMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms = buildTableDeleteMutationFields' _sourceName _sourceInfo _tableName _tableInfo _gqlName _delPerns _selPerms =
pure [] pure []
@ -135,7 +135,7 @@ buildFunctionQueryFields' ::
FunctionInfo 'MySQL -> FunctionInfo 'MySQL ->
RQL.TableName 'MySQL -> RQL.TableName 'MySQL ->
SelPermInfo 'MySQL -> SelPermInfo 'MySQL ->
m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionQueryFields' _ _ _ _ _ _ = buildFunctionQueryFields' _ _ _ _ _ _ =
pure [] pure []
@ -149,7 +149,7 @@ buildFunctionRelayQueryFields' ::
RQL.TableName 'MySQL -> RQL.TableName 'MySQL ->
NESeq (ColumnInfo 'MySQL) -> NESeq (ColumnInfo 'MySQL) ->
SelPermInfo 'MySQL -> SelPermInfo 'MySQL ->
m [(FieldParser n (QueryRootField UnpreparedValue UnpreparedValue))] m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionRelayQueryFields' _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms = buildFunctionRelayQueryFields' _sourceName _sourceInfo _functionName _functionInfo _tableName _pkeyColumns _selPerms =
pure [] pure []
@ -162,7 +162,7 @@ buildFunctionMutationFields' ::
FunctionInfo 'MySQL -> FunctionInfo 'MySQL ->
RQL.TableName 'MySQL -> RQL.TableName 'MySQL ->
SelPermInfo 'MySQL -> SelPermInfo 'MySQL ->
m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] m [FieldParser n (MutationRootField UnpreparedValue)]
buildFunctionMutationFields' _ _ _ _ _ _ = buildFunctionMutationFields' _ _ _ _ _ _ =
pure [] pure []

View File

@ -67,7 +67,7 @@ class PostgresSchema (pgKind :: PostgresKind) where
-> G.Name -> G.Name
-> NESeq (ColumnInfo ('Postgres pgKind)) -> NESeq (ColumnInfo ('Postgres pgKind))
-> SelPermInfo ('Postgres pgKind) -> SelPermInfo ('Postgres pgKind)
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
pgkBuildFunctionRelayQueryFields pgkBuildFunctionRelayQueryFields
:: BS.MonadBuildSchema ('Postgres pgKind) r m n :: BS.MonadBuildSchema ('Postgres pgKind) r m n
=> SourceName => SourceName
@ -77,7 +77,7 @@ class PostgresSchema (pgKind :: PostgresKind) where
-> TableName ('Postgres pgKind) -> TableName ('Postgres pgKind)
-> NESeq (ColumnInfo ('Postgres pgKind)) -> NESeq (ColumnInfo ('Postgres pgKind))
-> SelPermInfo ('Postgres pgKind) -> SelPermInfo ('Postgres pgKind)
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
pgkRelayExtension pgkRelayExtension
:: Maybe (XRelay ('Postgres pgKind)) :: Maybe (XRelay ('Postgres pgKind))
pgkNode pgkNode
@ -161,7 +161,7 @@ buildTableRelayQueryFields
-> G.Name -> G.Name
-> NESeq (ColumnInfo ('Postgres pgKind)) -> NESeq (ColumnInfo ('Postgres pgKind))
-> SelPermInfo ('Postgres pgKind) -> SelPermInfo ('Postgres pgKind)
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildTableRelayQueryFields sourceName sourceInfo tableName tableInfo gqlName pkeyColumns selPerms = do buildTableRelayQueryFields sourceName sourceInfo tableName tableInfo gqlName pkeyColumns selPerms = do
let let
mkRF = RFDB sourceName mkRF = RFDB sourceName
@ -184,7 +184,7 @@ buildFunctionRelayQueryFields
-> TableName ('Postgres pgKind) -> TableName ('Postgres pgKind)
-> NESeq (ColumnInfo ('Postgres pgKind)) -> NESeq (ColumnInfo ('Postgres pgKind))
-> SelPermInfo ('Postgres pgKind) -> SelPermInfo ('Postgres pgKind)
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionRelayQueryFields sourceName sourceInfo functionName functionInfo tableName pkeyColumns selPerms = do buildFunctionRelayQueryFields sourceName sourceInfo functionName functionInfo tableName pkeyColumns selPerms = do
funcName <- functionGraphQLName @('Postgres pgKind) functionName `onLeft` throwError funcName <- functionGraphQLName @('Postgres pgKind) functionName `onLeft` throwError
let let

View File

@ -876,10 +876,6 @@ processAnnFields sourcePrefix fieldAlias similarArrFields annFields = do
AFColumn c -> toSQLCol c AFColumn c -> toSQLCol c
-- this will be gone once the code which collects remote joins from the IR
-- emits a modified IR where remote relationships can't be reached
AFRemote _ -> pure $ S.SELit "null: remote field selected"
AFObjectRelation objSel -> withWriteObjectRelation $ do AFObjectRelation objSel -> withWriteObjectRelation $ do
let AnnRelationSelectG relName relMapping annObjSel = objSel let AnnRelationSelectG relName relMapping annObjSel = objSel
AnnObjectSelectG objAnnFields tableFrom tableFilter = annObjSel AnnObjectSelectG objAnnFields tableFrom tableFilter = annObjSel
@ -928,9 +924,6 @@ processAnnFields sourcePrefix fieldAlias similarArrFields annFields = do
, S.mkQIdenExp computedFieldSourcePrefix fieldName , S.mkQIdenExp computedFieldSourcePrefix fieldName
) )
-- TODO: implement this
AFDBRemote _ -> error "FIXME"
pure $ annRowToJson @pgKind fieldAlias fieldExps pure $ annRowToJson @pgKind fieldAlias fieldExps

View File

@ -30,8 +30,8 @@ data RoleContext a
$(deriveToJSON hasuraJSON ''RoleContext) $(deriveToJSON hasuraJSON ''RoleContext)
data GQLContext = GQLContext data GQLContext = GQLContext
{ gqlQueryParser :: ParserFn (InsOrdHashMap G.Name (IR.QueryRootField UnpreparedValue UnpreparedValue)) { gqlQueryParser :: ParserFn (InsOrdHashMap G.Name (IR.QueryRootField UnpreparedValue))
, gqlMutationParser :: Maybe (ParserFn (InsOrdHashMap G.Name (IR.MutationRootField UnpreparedValue UnpreparedValue))) , gqlMutationParser :: Maybe (ParserFn (InsOrdHashMap G.Name (IR.MutationRootField UnpreparedValue)))
} }
instance J.ToJSON GQLContext where instance J.ToJSON GQLContext where

View File

@ -131,7 +131,7 @@ getExecPlanPartial userInfo sc queryType req =
-- The graphql query is resolved into a sequence of execution operations -- The graphql query is resolved into a sequence of execution operations
data ResolvedExecutionPlan data ResolvedExecutionPlan
= QueryExecutionPlan EB.ExecutionPlan [IR.QueryRootField UnpreparedValue UnpreparedValue] DirectiveMap = QueryExecutionPlan EB.ExecutionPlan [IR.QueryRootField UnpreparedValue] DirectiveMap
-- ^ query execution; remote schemas and introspection possible -- ^ query execution; remote schemas and introspection possible
| MutationExecutionPlan EB.ExecutionPlan | MutationExecutionPlan EB.ExecutionPlan
-- ^ mutation execution; only __typename introspection supported -- ^ mutation execution; only __typename introspection supported
@ -157,7 +157,7 @@ data SubscriptionExecution
buildSubscriptionPlan buildSubscriptionPlan
:: (MonadError QErr m) :: (MonadError QErr m)
=> UserInfo => UserInfo
-> InsOrdHashMap G.Name (IR.QueryRootField UnpreparedValue UnpreparedValue) -> InsOrdHashMap G.Name (IR.QueryRootField UnpreparedValue)
-> m SubscriptionExecution -> m SubscriptionExecution
buildSubscriptionPlan userInfo rootFields = do buildSubscriptionPlan userInfo rootFields = do
(onSourceFields, noRelationActionFields) <- foldlM go (mempty, mempty) (OMap.toList rootFields) (onSourceFields, noRelationActionFields) <- foldlM go (mempty, mempty) (OMap.toList rootFields)

View File

@ -84,7 +84,7 @@ convertMutationSelectionSet env logger gqlContext SQLGenCtx{stringifyNum} userIn
(resolvedDirectives, resolvedSelSet) <- resolveVariables varDefs (fromMaybe Map.empty varValsM) directives fields (resolvedDirectives, resolvedSelSet) <- resolveVariables varDefs (fromMaybe Map.empty varValsM) directives fields
-- Parse the GraphQL query into the RQL AST -- Parse the GraphQL query into the RQL AST
(unpreparedQueries, _reusability) (unpreparedQueries, _reusability)
:: (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue UnpreparedValue), QueryReusability) :: (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue), QueryReusability)
<-(mutationParser >>> (`onLeft` reportParseErrors)) resolvedSelSet <-(mutationParser >>> (`onLeft` reportParseErrors)) resolvedSelSet
-- Process directives on the mutation -- Process directives on the mutation
@ -95,7 +95,7 @@ convertMutationSelectionSet env logger gqlContext SQLGenCtx{stringifyNum} userIn
txs <- for unpreparedQueries \case txs <- for unpreparedQueries \case
RFDB sourceName exists -> RFDB sourceName exists ->
AB.dispatchAnyBackend @BackendExecute exists AB.dispatchAnyBackend @BackendExecute exists
\(SourceConfigWith sourceConfig (MDBR db :: MutationDBRoot UnpreparedValue UnpreparedValue b)) -> do \(SourceConfigWith (sourceConfig :: SourceConfig b) (MDBR db)) -> do
let (noRelsDBAST, remoteJoins) = RJ.getRemoteJoinsMutationDB db let (noRelsDBAST, remoteJoins) = RJ.getRemoteJoinsMutationDB db
dbStepInfo <- mkDBMutationPlan @b userInfo stringifyNum sourceName sourceConfig noRelsDBAST dbStepInfo <- mkDBMutationPlan @b userInfo stringifyNum sourceName sourceConfig noRelsDBAST
pure $ ExecStepDB [] (AB.mkAnyBackend dbStepInfo) remoteJoins pure $ ExecStepDB [] (AB.mkAnyBackend dbStepInfo) remoteJoins

View File

@ -41,7 +41,7 @@ parseGraphQLQuery
-> Maybe (HashMap G.Name J.Value) -> Maybe (HashMap G.Name J.Value)
-> [G.Directive G.Name] -> [G.Directive G.Name]
-> G.SelectionSet G.NoFragments G.Name -> G.SelectionSet G.NoFragments G.Name
-> m ( InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue) -> m ( InsOrdHashMap G.Name (QueryRootField UnpreparedValue)
, QueryReusability , QueryReusability
, [G.Directive Variable] , [G.Directive Variable]
, G.SelectionSet G.NoFragments Variable , G.SelectionSet G.NoFragments Variable
@ -69,7 +69,7 @@ convertQuerySelSet
-> [G.VariableDefinition] -> [G.VariableDefinition]
-> Maybe GH.VariableValues -> Maybe GH.VariableValues
-> SetGraphqlIntrospectionOptions -> SetGraphqlIntrospectionOptions
-> m (ExecutionPlan, [QueryRootField UnpreparedValue UnpreparedValue], G.SelectionSet G.NoFragments Variable, DirectiveMap) -> m (ExecutionPlan, [QueryRootField UnpreparedValue], G.SelectionSet G.NoFragments Variable, DirectiveMap)
convertQuerySelSet env logger gqlContext userInfo manager reqHeaders directives fields varDefs varValsM convertQuerySelSet env logger gqlContext userInfo manager reqHeaders directives fields varDefs varValsM
introspectionDisabledRoles = do introspectionDisabledRoles = do
-- Parse the GraphQL query into the RQL AST -- Parse the GraphQL query into the RQL AST
@ -86,7 +86,7 @@ convertQuerySelSet env logger gqlContext userInfo manager reqHeaders directives
executionPlan <- for unpreparedQueries \case executionPlan <- for unpreparedQueries \case
RFDB sourceName exists -> RFDB sourceName exists ->
AB.dispatchAnyBackend @BackendExecute exists AB.dispatchAnyBackend @BackendExecute exists
\(SourceConfigWith sourceConfig (QDBR db :: QueryDBRoot UnpreparedValue UnpreparedValue b)) -> do \(SourceConfigWith (sourceConfig :: (SourceConfig b)) (QDBR db)) -> do
let (noRelsDBAST, remoteJoins) = RJ.getRemoteJoins db let (noRelsDBAST, remoteJoins) = RJ.getRemoteJoins db
dbStepInfo <- mkDBQueryPlan @b userInfo sourceName sourceConfig noRelsDBAST dbStepInfo <- mkDBQueryPlan @b userInfo sourceName sourceConfig noRelsDBAST
pure $ ExecStepDB [] (AB.mkAnyBackend dbStepInfo) remoteJoins pure $ ExecStepDB [] (AB.mkAnyBackend dbStepInfo) remoteJoins

View File

@ -52,8 +52,8 @@ import Hasura.RQL.Types
-- | Collects remote joins from the AST and also adds the necessary join fields -- | Collects remote joins from the AST and also adds the necessary join fields
getRemoteJoins getRemoteJoins
:: (Backend b) :: Backend b
=> QueryDB b r (UnpreparedValue b) => QueryDB b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (QueryDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (QueryDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoins = \case getRemoteJoins = \case
QDBMultipleRows s -> first QDBMultipleRows $ getRemoteJoinsSelect s QDBMultipleRows s -> first QDBMultipleRows $ getRemoteJoinsSelect s
@ -63,32 +63,32 @@ getRemoteJoins = \case
-- | Traverse through 'AnnSimpleSel' and collect remote join fields (if any). -- | Traverse through 'AnnSimpleSel' and collect remote join fields (if any).
getRemoteJoinsSelect getRemoteJoinsSelect
:: (Backend b) :: Backend b
=> AnnSimpleSelectG b r (UnpreparedValue b) => AnnSimpleSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (AnnSimpleSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (AnnSimpleSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsSelect = getRemoteJoinsSelect =
second mapToNonEmpty . flip runState mempty . transformSelect mempty second mapToNonEmpty . flip runState mempty . transformSelect mempty
-- | Traverse through @'AnnAggregateSelect' and collect remote join fields (if any). -- | Traverse through @'AnnAggregateSelect' and collect remote join fields (if any).
getRemoteJoinsAggregateSelect getRemoteJoinsAggregateSelect
:: (Backend b) :: Backend b
=> AnnAggregateSelectG b r (UnpreparedValue b) => AnnAggregateSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (AnnAggregateSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (AnnAggregateSelectG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsAggregateSelect = getRemoteJoinsAggregateSelect =
second mapToNonEmpty . flip runState mempty . transformAggregateSelect mempty second mapToNonEmpty . flip runState mempty . transformAggregateSelect mempty
-- | Traverse through @'ConnectionSelect' and collect remote join fields (if any). -- | Traverse through @'ConnectionSelect' and collect remote join fields (if any).
getRemoteJoinsConnectionSelect getRemoteJoinsConnectionSelect
:: (Backend b) :: Backend b
=> ConnectionSelect b r (UnpreparedValue b) => ConnectionSelect b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (ConnectionSelect b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (ConnectionSelect b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsConnectionSelect = getRemoteJoinsConnectionSelect =
second mapToNonEmpty . flip runState mempty . transformConnectionSelect mempty second mapToNonEmpty . flip runState mempty . transformConnectionSelect mempty
-- | Traverse through 'MutationOutput' and collect remote join fields (if any) -- | Traverse through 'MutationOutput' and collect remote join fields (if any)
getRemoteJoinsMutationOutput getRemoteJoinsMutationOutput
:: (Backend b) :: Backend b
=> MutationOutputG b r (UnpreparedValue b) => MutationOutputG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (MutationOutputG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (MutationOutputG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsMutationOutput = getRemoteJoinsMutationOutput =
second mapToNonEmpty . flip runState mempty . transformMutationOutput mempty second mapToNonEmpty . flip runState mempty . transformMutationOutput mempty
@ -111,15 +111,15 @@ getRemoteJoinsMutationOutput =
-- local helpers -- local helpers
getRemoteJoinsAnnFields getRemoteJoinsAnnFields
:: (Backend b) :: Backend b
=> AnnFieldsG b r (UnpreparedValue b) => AnnFieldsG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (AnnFieldsG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (AnnFieldsG b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsAnnFields = getRemoteJoinsAnnFields =
second mapToNonEmpty . flip runState mempty . transformAnnFields mempty second mapToNonEmpty . flip runState mempty . transformAnnFields mempty
getRemoteJoinsMutationDB getRemoteJoinsMutationDB
:: (Backend b) :: Backend b
=> MutationDB b r (UnpreparedValue b) => MutationDB b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (MutationDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (MutationDB b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsMutationDB = \case getRemoteJoinsMutationDB = \case
MDBInsert insert -> MDBInsert insert ->
@ -145,7 +145,7 @@ getRemoteJoinsMutationDB = \case
getRemoteJoinsSyncAction getRemoteJoinsSyncAction
:: (Backend b) :: (Backend b)
=> AnnActionExecution b r (UnpreparedValue b) => AnnActionExecution b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (AnnActionExecution b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (AnnActionExecution b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsSyncAction actionExecution = getRemoteJoinsSyncAction actionExecution =
let (fields', remoteJoins) = getRemoteJoinsAnnFields $ _aaeFields actionExecution let (fields', remoteJoins) = getRemoteJoinsAnnFields $ _aaeFields actionExecution
@ -153,7 +153,7 @@ getRemoteJoinsSyncAction actionExecution =
getRemoteJoinsActionQuery getRemoteJoinsActionQuery
:: (Backend b) :: (Backend b)
=> ActionQuery b r (UnpreparedValue b) => ActionQuery b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (ActionQuery b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (ActionQuery b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsActionQuery = \case getRemoteJoinsActionQuery = \case
AQQuery sync -> AQQuery sync ->
@ -180,7 +180,7 @@ getRemoteJoinsActionQuery = \case
getRemoteJoinsActionMutation getRemoteJoinsActionMutation
:: (Backend b) :: (Backend b)
=> ActionMutation b r (UnpreparedValue b) => ActionMutation b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> (ActionMutation b (Const Void) (UnpreparedValue b), Maybe RemoteJoins) -> (ActionMutation b (Const Void) (UnpreparedValue b), Maybe RemoteJoins)
getRemoteJoinsActionMutation = \case getRemoteJoinsActionMutation = \case
AMSync sync -> first AMSync $ getRemoteJoinsSyncAction sync AMSync sync -> first AMSync $ getRemoteJoinsSyncAction sync
@ -190,7 +190,7 @@ getRemoteJoinsActionMutation = \case
transformSelect transformSelect
:: (Backend b) :: (Backend b)
=> FieldPath => FieldPath
-> AnnSimpleSelectG b r (UnpreparedValue b) -> AnnSimpleSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> State RemoteJoinMap (AnnSimpleSelectG b (Const Void) (UnpreparedValue b)) -> State RemoteJoinMap (AnnSimpleSelectG b (Const Void) (UnpreparedValue b))
transformSelect path sel = do transformSelect path sel = do
let fields = _asnFields sel let fields = _asnFields sel
@ -201,7 +201,7 @@ transformSelect path sel = do
transformAggregateSelect transformAggregateSelect
:: (Backend b) :: (Backend b)
=> FieldPath => FieldPath
-> AnnAggregateSelectG b r (UnpreparedValue b) -> AnnAggregateSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> State RemoteJoinMap (AnnAggregateSelectG b (Const Void) (UnpreparedValue b)) -> State RemoteJoinMap (AnnAggregateSelectG b (Const Void) (UnpreparedValue b))
transformAggregateSelect path sel = do transformAggregateSelect path sel = do
let aggFields = _asnFields sel let aggFields = _asnFields sel
@ -215,7 +215,7 @@ transformAggregateSelect path sel = do
transformConnectionSelect transformConnectionSelect
:: (Backend b) :: (Backend b)
=> FieldPath => FieldPath
-> ConnectionSelect b r (UnpreparedValue b) -> ConnectionSelect b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> State RemoteJoinMap (ConnectionSelect b (Const Void) (UnpreparedValue b)) -> State RemoteJoinMap (ConnectionSelect b (Const Void) (UnpreparedValue b))
transformConnectionSelect path ConnectionSelect{..} = do transformConnectionSelect path ConnectionSelect{..} = do
let connectionFields = _asnFields _csSelect let connectionFields = _asnFields _csSelect
@ -238,7 +238,7 @@ transformConnectionSelect path ConnectionSelect{..} = do
transformObjectSelect transformObjectSelect
:: (Backend b) :: (Backend b)
=> FieldPath => FieldPath
-> AnnObjectSelectG b r (UnpreparedValue b) -> AnnObjectSelectG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> State RemoteJoinMap (AnnObjectSelectG b (Const Void) (UnpreparedValue b)) -> State RemoteJoinMap (AnnObjectSelectG b (Const Void) (UnpreparedValue b))
transformObjectSelect path sel = do transformObjectSelect path sel = do
let fields = _aosFields sel let fields = _aosFields sel
@ -246,10 +246,9 @@ transformObjectSelect path sel = do
pure sel{_aosFields = transformedFields} pure sel{_aosFields = transformedFields}
transformAnnFields transformAnnFields
:: forall b r :: forall b . Backend b
. (Backend b)
=> FieldPath => FieldPath
-> AnnFieldsG b r (UnpreparedValue b) -> AnnFieldsG b (RemoteSelect UnpreparedValue) (UnpreparedValue b)
-> State RemoteJoinMap (AnnFieldsG b (Const Void) (UnpreparedValue b)) -> State RemoteJoinMap (AnnFieldsG b (Const Void) (UnpreparedValue b))
transformAnnFields path fields = do transformAnnFields path fields = do
@ -260,9 +259,14 @@ transformAnnFields path fields = do
let columnsInSelSet = HS.fromList $ map (pgiColumn . _acfInfo . snd) $ getFields _AFColumn fields let columnsInSelSet = HS.fromList $ map (pgiColumn . _acfInfo . snd) $ getFields _AFColumn fields
scalarComputedFieldsInSelSet = HS.fromList $ map ((^. _2) . snd) $ getFields _AFComputedField fields scalarComputedFieldsInSelSet = HS.fromList $ map ((^. _2) . snd) $ getFields _AFComputedField fields
remoteSelects = getFields (_AFRemote) fields
remoteSelects = getFields (_AFRemote.to getRemoteSchemaSelect) fields
getRemoteSchemaSelect = \case
RemoteSelectRemoteSchema s -> s
RemoteSelectSource _s -> error "remote source relationshsip found"
remoteJoins = remoteSelects <&> \(fieldName, remoteSelect) -> remoteJoins = remoteSelects <&> \(fieldName, remoteSelect) ->
let RemoteSelect argsMap selSet hasuraFields remoteFields rsi = remoteSelect let RemoteSchemaSelect argsMap selSet hasuraFields remoteFields rsi = remoteSelect
hasuraFieldNames = HS.map dbJoinFieldToName hasuraFields hasuraFieldNames = HS.map dbJoinFieldToName hasuraFields
-- See Note [Phantom fields in Remote Joins] -- See Note [Phantom fields in Remote Joins]
@ -291,10 +295,11 @@ transformAnnFields path fields = do
AFComputedField x n <$> case computedField of AFComputedField x n <$> case computedField of
CFSScalar cfss cbe -> pure $ CFSScalar cfss cbe CFSScalar cfss cbe -> pure $ CFSScalar cfss cbe
CFSTable jas annSel -> CFSTable jas <$> transformSelect fieldPath annSel CFSTable jas annSel -> CFSTable jas <$> transformSelect fieldPath annSel
AFRemote rs -> pure $ AFRemote rs -- we generate this so that the response has a key with the relationship,
-- without which preserving the order of fields in the final response
-- would require a lot of bookkeeping
AFRemote _rs -> pure $ AFExpression "remote relationship placeholder"
AFExpression t -> pure $ AFExpression t AFExpression t -> pure $ AFExpression t
-- TODO: implement this
AFDBRemote _ -> error "FIXME"
case NE.nonEmpty remoteJoins of case NE.nonEmpty remoteJoins of
Nothing -> pure transformedFields Nothing -> pure transformedFields

View File

@ -53,7 +53,7 @@ explainQueryField
) )
=> UserInfo => UserInfo
-> G.Name -> G.Name
-> QueryRootField UnpreparedValue UnpreparedValue -> QueryRootField UnpreparedValue
-> m EncJSON -> m EncJSON
explainQueryField userInfo fieldName rootField = do explainQueryField userInfo fieldName rootField = do
case rootField of case rootField of

View File

@ -207,9 +207,9 @@ buildRoleContext
getMutationRemotes = concatMap (concat . piMutation) getMutationRemotes = concatMap (concat . piMutation)
buildSource :: forall b. BackendSchema b => SourceInfo b -> buildSource :: forall b. BackendSchema b => SourceInfo b ->
ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue UnpreparedValue)] ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue)]
, [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue UnpreparedValue)] , [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue)]
, [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue UnpreparedValue)] , [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue)]
) )
buildSource (SourceInfo sourceName tables functions sourceConfig) = do buildSource (SourceInfo sourceName tables functions sourceConfig) = do
let validFunctions = takeValidFunctions functions let validFunctions = takeValidFunctions functions
@ -276,9 +276,9 @@ buildRelayRoleContext
where where
buildSource :: forall b. BackendSchema b => SourceInfo b -> buildSource :: forall b. BackendSchema b => SourceInfo b ->
ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue UnpreparedValue)] ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue)]
, [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue UnpreparedValue)] , [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue)]
, [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue UnpreparedValue)] , [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue)]
) )
buildSource (SourceInfo sourceName tables functions sourceConfig) = do buildSource (SourceInfo sourceName tables functions sourceConfig) = do
let validFunctions = takeValidFunctions functions let validFunctions = takeValidFunctions functions
@ -296,8 +296,8 @@ buildFullestDBSchema
-> SourceCache -> SourceCache
-> [ActionInfo] -> [ActionInfo]
-> NonObjectTypeMap -> NonObjectTypeMap
-> m ( Parser 'Output (P.ParseT Identity) (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue)) -> m ( Parser 'Output (P.ParseT Identity) (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue))
, Maybe (Parser 'Output (P.ParseT Identity) (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue UnpreparedValue))) , Maybe (Parser 'Output (P.ParseT Identity) (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue)))
) )
buildFullestDBSchema queryContext sources allActionInfos nonObjectCustomTypes = buildFullestDBSchema queryContext sources allActionInfos nonObjectCustomTypes =
runMonadSchema adminRoleName queryContext sources do runMonadSchema adminRoleName queryContext sources do
@ -317,8 +317,8 @@ buildFullestDBSchema queryContext sources allActionInfos nonObjectCustomTypes =
where where
buildSource :: forall b. BackendSchema b => SourceInfo b -> buildSource :: forall b. BackendSchema b => SourceInfo b ->
ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue UnpreparedValue)] ConcreteSchemaT m ( [FieldParser (P.ParseT Identity) (QueryRootField UnpreparedValue)]
, [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue UnpreparedValue)] , [FieldParser (P.ParseT Identity) (MutationRootField UnpreparedValue)]
) )
buildSource (SourceInfo sourceName tables functions sourceConfig) = do buildSource (SourceInfo sourceName tables functions sourceConfig) = do
let validFunctions = takeValidFunctions functions let validFunctions = takeValidFunctions functions
@ -432,7 +432,7 @@ buildQueryFields
-> SourceConfig b -> SourceConfig b
-> TableCache b -> TableCache b
-> FunctionCache b -> FunctionCache b
-> m [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [P.FieldParser n (QueryRootField UnpreparedValue)]
buildQueryFields sourceName sourceConfig tables (takeExposedAs FEAQuery -> functions) = do buildQueryFields sourceName sourceConfig tables (takeExposedAs FEAQuery -> functions) = do
roleName <- askRoleName roleName <- askRoleName
functionPermsCtx <- asks $ qcFunctionPermsContext . getter functionPermsCtx <- asks $ qcFunctionPermsContext . getter
@ -459,7 +459,7 @@ buildRelayQueryFields
-> SourceConfig b -> SourceConfig b
-> TableCache b -> TableCache b
-> FunctionCache b -> FunctionCache b
-> m [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [P.FieldParser n (QueryRootField UnpreparedValue)]
buildRelayQueryFields sourceName sourceConfig tables (takeExposedAs FEAQuery -> functions) = do buildRelayQueryFields sourceName sourceConfig tables (takeExposedAs FEAQuery -> functions) = do
tableConnectionFields <- for (Map.toList tables) \(tableName, tableInfo) -> runMaybeT do tableConnectionFields <- for (Map.toList tables) \(tableName, tableInfo) -> runMaybeT do
tableGQLName <- getTableGQLName @b tableInfo tableGQLName <- getTableGQLName @b tableInfo
@ -484,7 +484,7 @@ buildMutationFields
-> SourceConfig b -> SourceConfig b
-> TableCache b -> TableCache b
-> FunctionCache b -> FunctionCache b
-> m [P.FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [P.FieldParser n (MutationRootField UnpreparedValue)]
buildMutationFields scenario sourceName sourceConfig tables (takeExposedAs FEAMutation -> functions) = do buildMutationFields scenario sourceName sourceConfig tables (takeExposedAs FEAMutation -> functions) = do
roleName <- askRoleName roleName <- askRoleName
tableMutations <- for (Map.toList tables) \(tableName, tableInfo) -> do tableMutations <- for (Map.toList tables) \(tableName, tableInfo) -> do
@ -540,13 +540,13 @@ buildQueryParser
, MonadRole r m , MonadRole r m
, Has QueryContext r , Has QueryContext r
) )
=> [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] => [P.FieldParser n (QueryRootField UnpreparedValue)]
-> [P.FieldParser n RemoteField] -> [P.FieldParser n RemoteField]
-> [ActionInfo] -> [ActionInfo]
-> NonObjectTypeMap -> NonObjectTypeMap
-> Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue UnpreparedValue))) -> Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue)))
-> Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue)) -> Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue))
-> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue))) -> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue)))
buildQueryParser pgQueryFields remoteFields allActions nonObjectCustomTypes mutationParser subscriptionParser = do buildQueryParser pgQueryFields remoteFields allActions nonObjectCustomTypes mutationParser subscriptionParser = do
actionQueryFields <- concat <$> traverse (buildActionQueryFields nonObjectCustomTypes) allActions actionQueryFields <- concat <$> traverse (buildActionQueryFields nonObjectCustomTypes) allActions
let allQueryFields = pgQueryFields <> actionQueryFields <> map (fmap RFRemote) remoteFields let allQueryFields = pgQueryFields <> actionQueryFields <> map (fmap RFRemote) remoteFields
@ -554,10 +554,10 @@ buildQueryParser pgQueryFields remoteFields allActions nonObjectCustomTypes muta
queryWithIntrospectionHelper queryWithIntrospectionHelper
:: forall n m. (MonadSchema n m, MonadError QErr m) :: forall n m. (MonadSchema n m, MonadError QErr m)
=> [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] => [P.FieldParser n (QueryRootField UnpreparedValue)]
-> Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue UnpreparedValue))) -> Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue)))
-> Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue)) -> Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue))
-> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue))) -> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue)))
queryWithIntrospectionHelper basicQueryFP mutationP subscriptionP = do queryWithIntrospectionHelper basicQueryFP mutationP subscriptionP = do
basicQueryP <- queryRootFromFields basicQueryFP basicQueryP <- queryRootFromFields basicQueryFP
emptyIntro <- emptyIntrospection emptyIntro <- emptyIntrospection
@ -588,15 +588,15 @@ queryWithIntrospectionHelper basicQueryFP mutationP subscriptionP = do
queryRootFromFields queryRootFromFields
:: forall n m :: forall n m
. (MonadError QErr m, MonadParse n) . (MonadError QErr m, MonadParse n)
=> [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] => [P.FieldParser n (QueryRootField UnpreparedValue)]
-> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue))) -> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue)))
queryRootFromFields fps = queryRootFromFields fps =
P.safeSelectionSet queryRoot Nothing fps <&> fmap (fmap typenameToRawRF) P.safeSelectionSet queryRoot Nothing fps <&> fmap (fmap typenameToRawRF)
emptyIntrospection emptyIntrospection
:: forall m n :: forall m n
. (MonadSchema n m, MonadError QErr m) . (MonadSchema n m, MonadError QErr m)
=> m [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] => m [P.FieldParser n (QueryRootField UnpreparedValue)]
emptyIntrospection = do emptyIntrospection = do
emptyQueryP <- queryRootFromFields @n [] emptyQueryP <- queryRootFromFields @n []
introspectionTypes <- collectTypes (P.parserType emptyQueryP) introspectionTypes <- collectTypes (P.parserType emptyQueryP)
@ -630,9 +630,9 @@ buildSubscriptionParser
, MonadRole r m , MonadRole r m
, Has QueryContext r , Has QueryContext r
) )
=> [P.FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] => [P.FieldParser n (QueryRootField UnpreparedValue)]
-> [ActionInfo] -> [ActionInfo]
-> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue UnpreparedValue))) -> m (Parser 'Output n (OMap.InsOrdHashMap G.Name (QueryRootField UnpreparedValue)))
buildSubscriptionParser queryFields allActions = do buildSubscriptionParser queryFields allActions = do
actionSubscriptionFields <- concat <$> traverse buildActionSubscriptionFields allActions actionSubscriptionFields <- concat <$> traverse buildActionSubscriptionFields allActions
let subscriptionFields = queryFields <> actionSubscriptionFields let subscriptionFields = queryFields <> actionSubscriptionFields
@ -648,8 +648,8 @@ buildMutationParser
=> [P.FieldParser n RemoteField] => [P.FieldParser n RemoteField]
-> [ActionInfo] -> [ActionInfo]
-> NonObjectTypeMap -> NonObjectTypeMap
-> [P.FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> [P.FieldParser n (MutationRootField UnpreparedValue)]
-> m (Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue UnpreparedValue)))) -> m (Maybe (Parser 'Output n (OMap.InsOrdHashMap G.Name (MutationRootField UnpreparedValue))))
buildMutationParser allRemotes allActions nonObjectCustomTypes mutationFields = do buildMutationParser allRemotes allActions nonObjectCustomTypes mutationFields = do
actionParsers <- concat <$> traverse (buildActionMutationFields nonObjectCustomTypes) allActions actionParsers <- concat <$> traverse (buildActionMutationFields nonObjectCustomTypes) allActions
let mutationFieldsParser = let mutationFieldsParser =

View File

@ -47,7 +47,7 @@ actionExecute
. MonadBuildSchema ('Postgres 'Vanilla) r m n . MonadBuildSchema ('Postgres 'Vanilla) r m n
=> NonObjectTypeMap => NonObjectTypeMap
-> ActionInfo -> ActionInfo
-> m (Maybe (FieldParser n (AnnActionExecution ('Postgres 'Vanilla) UnpreparedValue (UnpreparedValue ('Postgres 'Vanilla))))) -> m (Maybe (FieldParser n (AnnActionExecution ('Postgres 'Vanilla) (RQL.RemoteSelect UnpreparedValue) (UnpreparedValue ('Postgres 'Vanilla)))))
actionExecute nonObjectTypeMap actionInfo = runMaybeT do actionExecute nonObjectTypeMap actionInfo = runMaybeT do
roleName <- askRoleName roleName <- askRoleName
guard (roleName == adminRoleName || roleName `Map.member` permissions) guard (roleName == adminRoleName || roleName `Map.member` permissions)
@ -113,7 +113,7 @@ actionAsyncQuery
:: forall r m n :: forall r m n
. MonadBuildSchema ('Postgres 'Vanilla) r m n . MonadBuildSchema ('Postgres 'Vanilla) r m n
=> ActionInfo => ActionInfo
-> m (Maybe (FieldParser n (AnnActionAsyncQuery ('Postgres 'Vanilla) UnpreparedValue (UnpreparedValue ('Postgres 'Vanilla))))) -> m (Maybe (FieldParser n (AnnActionAsyncQuery ('Postgres 'Vanilla) (RQL.RemoteSelect UnpreparedValue) (UnpreparedValue ('Postgres 'Vanilla)))))
actionAsyncQuery actionInfo = runMaybeT do actionAsyncQuery actionInfo = runMaybeT do
roleName <- askRoleName roleName <- askRoleName
guard $ roleName == adminRoleName || roleName `Map.member` permissions guard $ roleName == adminRoleName || roleName `Map.member` permissions
@ -172,7 +172,7 @@ actionOutputFields
. MonadBuildSchema ('Postgres 'Vanilla) r m n . MonadBuildSchema ('Postgres 'Vanilla) r m n
=> G.GType => G.GType
-> AnnotatedObjectType -> AnnotatedObjectType
-> m (Parser 'Output n (RQL.AnnFieldsG ('Postgres 'Vanilla) UnpreparedValue (UnpreparedValue ('Postgres 'Vanilla)))) -> m (Parser 'Output n (AnnotatedFields ('Postgres 'Vanilla)))
actionOutputFields outputType annotatedObject = do actionOutputFields outputType annotatedObject = do
let outputObject = _aotDefinition annotatedObject let outputObject = _aotDefinition annotatedObject
scalarOrEnumFields = map outputFieldParser $ toList $ _otdFields outputObject scalarOrEnumFields = map outputFieldParser $ toList $ _otdFields outputObject
@ -194,7 +194,7 @@ actionOutputFields outputType annotatedObject = do
outputFieldParser outputFieldParser
:: ObjectFieldDefinition (G.GType, AnnotatedObjectFieldType) :: ObjectFieldDefinition (G.GType, AnnotatedObjectFieldType)
-> FieldParser n (RQL.AnnFieldG ('Postgres 'Vanilla) UnpreparedValue (UnpreparedValue ('Postgres 'Vanilla))) -> FieldParser n (AnnotatedField ('Postgres 'Vanilla))
outputFieldParser (ObjectFieldDefinition name _ description (gType, objectFieldType)) = outputFieldParser (ObjectFieldDefinition name _ description (gType, objectFieldType)) =
let fieldName = unObjectFieldName name let fieldName = unObjectFieldName name
selection = P.selection_ fieldName description $ case objectFieldType of selection = P.selection_ fieldName description $ case objectFieldType of
@ -211,7 +211,7 @@ actionOutputFields outputType annotatedObject = do
relationshipFieldParser relationshipFieldParser
:: TypeRelationship (TableInfo ('Postgres 'Vanilla)) (ColumnInfo ('Postgres 'Vanilla)) :: TypeRelationship (TableInfo ('Postgres 'Vanilla)) (ColumnInfo ('Postgres 'Vanilla))
-> m (Maybe [FieldParser n (RQL.AnnFieldG ('Postgres 'Vanilla) UnpreparedValue (UnpreparedValue ('Postgres 'Vanilla)))]) -> m (Maybe [FieldParser n (AnnotatedField ('Postgres 'Vanilla))])
relationshipFieldParser (TypeRelationship relName relType sourceName tableInfo fieldMapping) = runMaybeT do relationshipFieldParser (TypeRelationship relName relType sourceName tableInfo fieldMapping) = runMaybeT do
let tableName = _tciName $ _tiCoreInfo tableInfo let tableName = _tciName $ _tiCoreInfo tableInfo
fieldName = unRelationshipName relName fieldName = unRelationshipName relName

View File

@ -72,7 +72,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> TableInfo b -> TableInfo b
-> G.Name -> G.Name
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildTableRelayQueryFields buildTableRelayQueryFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -82,7 +82,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> G.Name -> G.Name
-> NESeq (ColumnInfo b) -> NESeq (ColumnInfo b)
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildTableInsertMutationFields buildTableInsertMutationFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -93,7 +93,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> InsPermInfo b -> InsPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b) -> Maybe (UpdPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableUpdateMutationFields buildTableUpdateMutationFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -103,7 +103,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> G.Name -> G.Name
-> UpdPermInfo b -> UpdPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableDeleteMutationFields buildTableDeleteMutationFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -113,7 +113,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> G.Name -> G.Name
-> DelPermInfo b -> DelPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildFunctionQueryFields buildFunctionQueryFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -122,7 +122,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> FunctionInfo b -> FunctionInfo b
-> TableName b -> TableName b
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionRelayQueryFields buildFunctionRelayQueryFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -132,7 +132,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> TableName b -> TableName b
-> NESeq (ColumnInfo b) -> NESeq (ColumnInfo b)
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionMutationFields buildFunctionMutationFields
:: MonadBuildSchema b r m n :: MonadBuildSchema b r m n
=> SourceName => SourceName
@ -141,7 +141,7 @@ class Backend b => BackendSchema (b :: BackendType) where
-> FunctionInfo b -> FunctionInfo b
-> TableName b -> TableName b
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
-- table components -- table components
tableArguments tableArguments

View File

@ -30,7 +30,7 @@ buildTableQueryFields
-> TableInfo b -> TableInfo b
-> G.Name -> G.Name
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildTableQueryFields sourceName sourceInfo tableName tableInfo gqlName selPerms = do buildTableQueryFields sourceName sourceInfo tableName tableInfo gqlName selPerms = do
let let
mkRF = RFDB sourceName mkRF = RFDB sourceName
@ -64,7 +64,7 @@ buildTableInsertMutationFields
-> InsPermInfo b -> InsPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> Maybe (UpdPermInfo b) -> Maybe (UpdPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableInsertMutationFields sourceName sourceInfo tableName tableInfo gqlName insPerms mSelPerms mUpdPerms = do buildTableInsertMutationFields sourceName sourceInfo tableName tableInfo gqlName insPerms mSelPerms mUpdPerms = do
let let
mkRF = RFDB sourceName mkRF = RFDB sourceName
@ -96,7 +96,7 @@ buildTableUpdateMutationFields
-> G.Name -> G.Name
-> UpdPermInfo b -> UpdPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableUpdateMutationFields sourceName sourceInfo tableName tableInfo gqlName updPerms mSelPerms = do buildTableUpdateMutationFields sourceName sourceInfo tableName tableInfo gqlName updPerms mSelPerms = do
let let
mkRF = RFDB sourceName mkRF = RFDB sourceName
@ -127,7 +127,7 @@ buildTableDeleteMutationFields
-> G.Name -> G.Name
-> DelPermInfo b -> DelPermInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildTableDeleteMutationFields sourceName sourceInfo tableName tableInfo gqlName delPerms mSelPerms = do buildTableDeleteMutationFields sourceName sourceInfo tableName tableInfo gqlName delPerms mSelPerms = do
let let
mkRF = RFDB sourceName mkRF = RFDB sourceName
@ -157,7 +157,7 @@ buildFunctionQueryFields
-> FunctionInfo b -> FunctionInfo b
-> TableName b -> TableName b
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildFunctionQueryFields sourceName sourceInfo functionName functionInfo tableName selPerms = do buildFunctionQueryFields sourceName sourceInfo functionName functionInfo tableName selPerms = do
funcName <- functionGraphQLName @b functionName `onLeft` throwError funcName <- functionGraphQLName @b functionName `onLeft` throwError
let let
@ -188,7 +188,7 @@ buildFunctionMutationFields
-> FunctionInfo b -> FunctionInfo b
-> TableName b -> TableName b
-> SelPermInfo b -> SelPermInfo b
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildFunctionMutationFields sourceName sourceInfo functionName functionInfo tableName selPerms = do buildFunctionMutationFields sourceName sourceInfo functionName functionInfo tableName selPerms = do
funcName <- functionGraphQLName @b functionName `onLeft` throwError funcName <- functionGraphQLName @b functionName `onLeft` throwError
let let

View File

@ -21,13 +21,15 @@ import Hasura.GraphQL.Parser (UnpreparedValue)
import Hasura.RQL.Types import Hasura.RQL.Types
type SelectExp b = IR.AnnSimpleSelectG b UnpreparedValue (UnpreparedValue b) type SelectExp b = IR.AnnSimpleSelectG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type AggSelectExp b = IR.AnnAggregateSelectG b UnpreparedValue (UnpreparedValue b) type AggSelectExp b = IR.AnnAggregateSelectG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type ConnectionSelectExp b = IR.ConnectionSelect b UnpreparedValue (UnpreparedValue b) type ConnectionSelectExp b = IR.ConnectionSelect b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type SelectArgs b = IR.SelectArgsG b (UnpreparedValue b) type SelectArgs b = IR.SelectArgsG b (UnpreparedValue b)
type TablePerms b = IR.TablePermG b (UnpreparedValue b) type TablePerms b = IR.TablePermG b (UnpreparedValue b)
type AnnotatedFields b = IR.AnnFieldsG b UnpreparedValue (UnpreparedValue b) type AnnotatedFields b = IR.AnnFieldsG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type AnnotatedField b = IR.AnnFieldG b UnpreparedValue (UnpreparedValue b) type AnnotatedField b = IR.AnnFieldG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type ConnectionFields b = IR.ConnectionFields b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
type EdgeFields b = IR.EdgeFields b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
data QueryContext = data QueryContext =
QueryContext QueryContext

View File

@ -22,6 +22,7 @@ import qualified Hasura.GraphQL.Parser as P
import qualified Hasura.RQL.IR.Delete as IR import qualified Hasura.RQL.IR.Delete as IR
import qualified Hasura.RQL.IR.Insert as IR import qualified Hasura.RQL.IR.Insert as IR
import qualified Hasura.RQL.IR.Returning as IR import qualified Hasura.RQL.IR.Returning as IR
import qualified Hasura.RQL.IR.Select as IR
import qualified Hasura.RQL.IR.Update as IR import qualified Hasura.RQL.IR.Update as IR
import Hasura.GraphQL.Parser (FieldParser, InputFieldsParser, Kind (..), Parser, import Hasura.GraphQL.Parser (FieldParser, InputFieldsParser, Kind (..), Parser,
@ -48,7 +49,7 @@ insertIntoTable
-> InsPermInfo b -- ^ insert permissions of the table -> InsPermInfo b -- ^ insert permissions of the table
-> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any) -> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any)
-> Maybe (UpdPermInfo b) -- ^ update permissions of the table (if any) -> Maybe (UpdPermInfo b) -- ^ update permissions of the table (if any)
-> m (FieldParser n (IR.AnnInsert b UnpreparedValue (UnpreparedValue b))) -> m (FieldParser n (IR.AnnInsert b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)))
insertIntoTable sourceName tableInfo fieldName description insertPerms selectPerms updatePerms = do insertIntoTable sourceName tableInfo fieldName description insertPerms selectPerms updatePerms = do
let columns = tableColumns tableInfo let columns = tableColumns tableInfo
selectionParser <- mutationSelectionSet sourceName tableInfo selectPerms selectionParser <- mutationSelectionSet sourceName tableInfo selectPerms
@ -86,7 +87,7 @@ insertOneIntoTable
-> InsPermInfo b -- ^ insert permissions of the table -> InsPermInfo b -- ^ insert permissions of the table
-> SelPermInfo b -- ^ select permissions of the table -> SelPermInfo b -- ^ select permissions of the table
-> Maybe (UpdPermInfo b) -- ^ update permissions of the table (if any) -> Maybe (UpdPermInfo b) -- ^ update permissions of the table (if any)
-> m (FieldParser n (IR.AnnInsert b UnpreparedValue (UnpreparedValue b))) -> m (FieldParser n (IR.AnnInsert b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)))
insertOneIntoTable sourceName tableInfo fieldName description insertPerms selectPerms updatePerms = do insertOneIntoTable sourceName tableInfo fieldName description insertPerms selectPerms updatePerms = do
let columns = tableColumns tableInfo let columns = tableColumns tableInfo
selectionParser <- tableSelectionSet sourceName tableInfo selectPerms selectionParser <- tableSelectionSet sourceName tableInfo selectPerms
@ -298,7 +299,7 @@ updateTable
-> Maybe G.Description -- ^ field description, if any -> Maybe G.Description -- ^ field description, if any
-> UpdPermInfo b -- ^ update permissions of the table -> UpdPermInfo b -- ^ update permissions of the table
-> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any) -> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any)
-> m (Maybe (FieldParser n (IR.AnnUpdG b UnpreparedValue (UnpreparedValue b)))) -> m (Maybe (FieldParser n (IR.AnnUpdG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b))))
updateTable sourceName tableInfo fieldName description updatePerms selectPerms = runMaybeT $ do updateTable sourceName tableInfo fieldName description updatePerms selectPerms = runMaybeT $ do
let whereName = $$(G.litName "where") let whereName = $$(G.litName "where")
whereDesc = "filter the rows which have to be updated" whereDesc = "filter the rows which have to be updated"
@ -324,7 +325,7 @@ updateTableByPk
-> Maybe G.Description -- ^ field description, if any -> Maybe G.Description -- ^ field description, if any
-> UpdPermInfo b -- ^ update permissions of the table -> UpdPermInfo b -- ^ update permissions of the table
-> SelPermInfo b -- ^ select permissions of the table -> SelPermInfo b -- ^ select permissions of the table
-> m (Maybe (FieldParser n (IR.AnnUpdG b UnpreparedValue (UnpreparedValue b)))) -> m (Maybe (FieldParser n (IR.AnnUpdG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b))))
updateTableByPk sourceName tableInfo fieldName description updatePerms selectPerms = runMaybeT $ do updateTableByPk sourceName tableInfo fieldName description updatePerms selectPerms = runMaybeT $ do
tableGQLName <- getTableGQLName tableInfo tableGQLName <- getTableGQLName tableInfo
let columns = tableColumns tableInfo let columns = tableColumns tableInfo
@ -350,9 +351,9 @@ mkUpdateObject
-> ( ( [(Column b, IR.UpdOpExpG (UnpreparedValue b))] -> ( ( [(Column b, IR.UpdOpExpG (UnpreparedValue b))]
, AnnBoolExp b (UnpreparedValue b) , AnnBoolExp b (UnpreparedValue b)
) )
, IR.MutationOutputG b UnpreparedValue (UnpreparedValue b) , IR.MutationOutputG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
) )
-> IR.AnnUpdG b UnpreparedValue (UnpreparedValue b) -> IR.AnnUpdG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
mkUpdateObject table columns updatePerms ((opExps, whereExp), mutationOutput) = mkUpdateObject table columns updatePerms ((opExps, whereExp), mutationOutput) =
IR.AnnUpd { IR.uqp1Table = table IR.AnnUpd { IR.uqp1Table = table
, IR.uqp1OpExps = opExps , IR.uqp1OpExps = opExps
@ -379,7 +380,7 @@ deleteFromTable
-> Maybe G.Description -- ^ field description, if any -> Maybe G.Description -- ^ field description, if any
-> DelPermInfo b -- ^ delete permissions of the table -> DelPermInfo b -- ^ delete permissions of the table
-> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any) -> Maybe (SelPermInfo b) -- ^ select permissions of the table (if any)
-> m (FieldParser n (IR.AnnDelG b UnpreparedValue (UnpreparedValue b))) -> m (FieldParser n (IR.AnnDelG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)))
deleteFromTable sourceName tableInfo fieldName description deletePerms selectPerms = do deleteFromTable sourceName tableInfo fieldName description deletePerms selectPerms = do
let whereName = $$(G.litName "where") let whereName = $$(G.litName "where")
whereDesc = "filter the rows which have to be deleted" whereDesc = "filter the rows which have to be deleted"
@ -401,7 +402,7 @@ deleteFromTableByPk
-> Maybe G.Description -- ^ field description, if any -> Maybe G.Description -- ^ field description, if any
-> DelPermInfo b -- ^ delete permissions of the table -> DelPermInfo b -- ^ delete permissions of the table
-> SelPermInfo b -- ^ select permissions of the table -> SelPermInfo b -- ^ select permissions of the table
-> m (Maybe (FieldParser n (IR.AnnDelG b UnpreparedValue (UnpreparedValue b)))) -> m (Maybe (FieldParser n (IR.AnnDelG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b))))
deleteFromTableByPk sourceName tableInfo fieldName description deletePerms selectPerms = runMaybeT $ do deleteFromTableByPk sourceName tableInfo fieldName description deletePerms selectPerms = runMaybeT $ do
let columns = tableColumns tableInfo let columns = tableColumns tableInfo
pkArgs <- MaybeT $ primaryKeysArguments tableInfo selectPerms pkArgs <- MaybeT $ primaryKeysArguments tableInfo selectPerms
@ -414,8 +415,8 @@ mkDeleteObject
=> TableName b => TableName b
-> [ColumnInfo b] -> [ColumnInfo b]
-> DelPermInfo b -> DelPermInfo b
-> (AnnBoolExp b (UnpreparedValue b), IR.MutationOutputG b UnpreparedValue (UnpreparedValue b)) -> (AnnBoolExp b (UnpreparedValue b), IR.MutationOutputG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b))
-> IR.AnnDelG b UnpreparedValue (UnpreparedValue b) -> IR.AnnDelG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)
mkDeleteObject table columns deletePerms (whereExp, mutationOutput) = mkDeleteObject table columns deletePerms (whereExp, mutationOutput) =
IR.AnnDel { IR.dqp1Table = table IR.AnnDel { IR.dqp1Table = table
, IR.dqp1Where = (permissionFilter, whereExp) , IR.dqp1Where = (permissionFilter, whereExp)
@ -436,7 +437,7 @@ mutationSelectionSet
=> SourceName => SourceName
-> TableInfo b -> TableInfo b
-> Maybe (SelPermInfo b) -> Maybe (SelPermInfo b)
-> m (Parser 'Output n (IR.MutFldsG b UnpreparedValue (UnpreparedValue b))) -> m (Parser 'Output n (IR.MutFldsG b (IR.RemoteSelect UnpreparedValue) (UnpreparedValue b)))
mutationSelectionSet sourceName tableInfo selectPerms = mutationSelectionSet sourceName tableInfo selectPerms =
memoizeOn 'mutationSelectionSet (sourceName, tableName) do memoizeOn 'mutationSelectionSet (sourceName, tableName) do
tableGQLName <- getTableGQLName tableInfo tableGQLName <- getTableGQLName tableInfo

View File

@ -20,7 +20,7 @@ buildActionQueryFields
:: MonadBuildSchema ('Postgres 'Vanilla) r m n :: MonadBuildSchema ('Postgres 'Vanilla) r m n
=> NonObjectTypeMap => NonObjectTypeMap
-> ActionInfo -> ActionInfo
-> m [FieldParser n (QueryRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (QueryRootField UnpreparedValue)]
buildActionQueryFields nonObjectCustomTypes actionInfo = buildActionQueryFields nonObjectCustomTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> ActionQuery ->
@ -33,7 +33,7 @@ buildActionMutationFields
:: MonadBuildSchema ('Postgres 'Vanilla) r m n :: MonadBuildSchema ('Postgres 'Vanilla) r m n
=> NonObjectTypeMap => NonObjectTypeMap
-> ActionInfo -> ActionInfo
-> m [FieldParser n (MutationRootField UnpreparedValue UnpreparedValue)] -> m [FieldParser n (MutationRootField UnpreparedValue)]
buildActionMutationFields nonObjectCustomTypes actionInfo = buildActionMutationFields nonObjectCustomTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing ActionQuery -> pure Nothing
@ -45,8 +45,7 @@ buildActionMutationFields nonObjectCustomTypes actionInfo =
buildActionSubscriptionFields buildActionSubscriptionFields
:: MonadBuildSchema ('Postgres 'Vanilla) r m n :: MonadBuildSchema ('Postgres 'Vanilla) r m n
=> ActionInfo => ActionInfo
-> m [FieldParser n (QueryRootField UnpreparedValue -> m [FieldParser n (QueryRootField UnpreparedValue)]
UnpreparedValue)]
buildActionSubscriptionFields actionInfo = buildActionSubscriptionFields actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing ActionQuery -> pure Nothing

View File

@ -398,7 +398,7 @@ tableConnectionSelectionSet
=> SourceName => SourceName
-> TableInfo b -> TableInfo b
-> SelPermInfo b -> SelPermInfo b
-> m (Parser 'Output n (IR.ConnectionFields b UnpreparedValue (UnpreparedValue b))) -> m (Parser 'Output n (ConnectionFields b))
tableConnectionSelectionSet sourceName tableInfo selectPermissions = memoizeOn 'tableConnectionSelectionSet (sourceName, tableName) do tableConnectionSelectionSet sourceName tableInfo selectPermissions = memoizeOn 'tableConnectionSelectionSet (sourceName, tableName) do
tableGQLName <- getTableGQLName tableInfo tableGQLName <- getTableGQLName tableInfo
edgesParser <- tableEdgesSelectionSet tableGQLName edgesParser <- tableEdgesSelectionSet tableGQLName
@ -432,7 +432,7 @@ tableConnectionSelectionSet sourceName tableInfo selectPermissions = memoizeOn '
<&> parsedSelectionsToFields IR.PageInfoTypename <&> parsedSelectionsToFields IR.PageInfoTypename
tableEdgesSelectionSet tableEdgesSelectionSet
:: G.Name -> m (Parser 'Output n (IR.EdgeFields b UnpreparedValue (UnpreparedValue b))) :: G.Name -> m (Parser 'Output n (EdgeFields b))
tableEdgesSelectionSet tableGQLName = do tableEdgesSelectionSet tableGQLName = do
edgeNodeParser <- P.nonNullableParser <$> tableSelectionSet sourceName tableInfo selectPermissions edgeNodeParser <- P.nonNullableParser <$> tableSelectionSet sourceName tableInfo selectPermissions
let edgesType = tableGQLName <> $$(G.litName "Edge") let edgesType = tableGQLName <> $$(G.litName "Edge")
@ -1155,7 +1155,7 @@ remoteRelationshipField remoteFieldInfo = runMaybeT do
`P.bindField` \G.Field{ G._fArguments = args, G._fSelectionSet = selSet } -> do `P.bindField` \G.Field{ G._fArguments = args, G._fSelectionSet = selSet } -> do
let remoteArgs = let remoteArgs =
Map.toList args <&> \(argName, argVal) -> IR.RemoteFieldArgument argName $ P.GraphQLValue $ argVal Map.toList args <&> \(argName, argVal) -> IR.RemoteFieldArgument argName $ P.GraphQLValue $ argVal
pure $ IR.AFRemote $ IR.RemoteSelect pure $ IR.AFRemote $ IR.RemoteSelectRemoteSchema $ IR.RemoteSchemaSelect
{ _rselArgs = remoteArgs { _rselArgs = remoteArgs
, _rselSelection = selSet , _rselSelection = selSet
, _rselHasuraFields = _rfiHasuraFields remoteSchema , _rselHasuraFields = _rfiHasuraFields remoteSchema
@ -1410,7 +1410,7 @@ nodePG = memoizeOn 'nodePG () do
nodeField nodeField
:: forall m n r :: forall m n r
. MonadBuildSchema ('Postgres 'Vanilla) r m n . MonadBuildSchema ('Postgres 'Vanilla) r m n
=> m (P.FieldParser n (IR.QueryRootField UnpreparedValue UnpreparedValue)) => m (P.FieldParser n (IR.QueryRootField UnpreparedValue))
nodeField = do nodeField = do
let idDescription = G.Description "A globally unique id" let idDescription = G.Description "A globally unique id"
idArgument = P.field $$(G.litName "id") (Just idDescription) P.identifier idArgument = P.field $$(G.litName "id") (Just idDescription) P.identifier

View File

@ -167,7 +167,7 @@ runSessVarPred = filterSessionVariables . unSessVarPred
-- | Filter out only those session variables used by the query AST provided -- | Filter out only those session variables used by the query AST provided
filterVariablesFromQuery filterVariablesFromQuery
:: Backend backend :: Backend backend
=> [RootField (QueryDBRoot UnpreparedValue UnpreparedValue) RemoteField (ActionQuery backend UnpreparedValue (UnpreparedValue backend)) d] => [RootField (QueryDBRoot (RemoteSelect UnpreparedValue) UnpreparedValue) RemoteField (ActionQuery backend (RemoteSelect UnpreparedValue) (UnpreparedValue backend)) d]
-> SessVarPred -> SessVarPred
filterVariablesFromQuery query = fold $ rootToSessVarPreds =<< query filterVariablesFromQuery query = fold $ rootToSessVarPreds =<< query
where where

View File

@ -72,7 +72,14 @@ data ActionMutation (b :: BackendType) (r :: BackendType -> Type) v
newtype QueryDBRoot r v b = QDBR (QueryDB b r (v b)) newtype QueryDBRoot r v b = QDBR (QueryDB b r (v b))
newtype MutationDBRoot r v b = MDBR (MutationDB b r (v b)) newtype MutationDBRoot r v b = MDBR (MutationDB b r (v b))
-- | Represents a query root field to an action
type QueryActionRoot v
= ActionQuery ('Postgres 'Vanilla) (RemoteSelect v) (v ('Postgres 'Vanilla))
type QueryRootField r v = RootField (QueryDBRoot r v) RQL.RemoteField (ActionQuery ('Postgres 'Vanilla) r (v ('Postgres 'Vanilla))) JO.Value -- | Represents a mutation root field to an action
type MutationRootField r v = RootField (MutationDBRoot r v) RQL.RemoteField (ActionMutation ('Postgres 'Vanilla) r (v ('Postgres 'Vanilla))) JO.Value type MutationActionRoot v
type SubscriptionRootField r v = RootField (QueryDBRoot r v) Void Void Void = ActionMutation ('Postgres 'Vanilla) (RemoteSelect v) (v ('Postgres 'Vanilla))
type QueryRootField v = RootField (QueryDBRoot (RemoteSelect v) v) RQL.RemoteField (QueryActionRoot v) JO.Value
type MutationRootField v = RootField (MutationDBRoot (RemoteSelect v) v) RQL.RemoteField (MutationActionRoot v) JO.Value
type SubscriptionRootField v = RootField (QueryDBRoot (RemoteSelect v) v) Void Void Void

View File

@ -188,8 +188,11 @@ data AnnFieldG (b :: BackendType) (r :: BackendType -> Type) v
| AFObjectRelation !(ObjectRelationSelectG b r v) | AFObjectRelation !(ObjectRelationSelectG b r v)
| AFArrayRelation !(ArraySelectG b r v) | AFArrayRelation !(ArraySelectG b r v)
| AFComputedField !(XComputedField b) !ComputedFieldName !(ComputedFieldSelect b r v) | AFComputedField !(XComputedField b) !ComputedFieldName !(ComputedFieldSelect b r v)
| AFRemote !(RemoteSelect b) -- | A relationship to a remote source/remote schema. Its kind is
| AFDBRemote !(AB.AnyBackend (DBRemoteSelect b r)) -- (r :: BackendType -> Type) so that AFRemote can capture something
-- that is specific to the backend AnnFieldG. See RemoteSelect. When
-- remote joins are extracted from the structure, 'r' becomes 'Const Void'
| AFRemote !(r b)
| AFNodeId !(XRelay b) !(TableName b) !(PrimaryKeyColumns b) | AFNodeId !(XRelay b) !(TableName b) !(PrimaryKeyColumns b)
| AFExpression !Text | AFExpression !Text
deriving (Functor, Foldable, Traversable) deriving (Functor, Foldable, Traversable)
@ -361,7 +364,7 @@ type ArraySelect b = ArraySelectG b (Const Void) (SQLExpression b)
type ArraySelectFieldsG b r v = Fields (ArraySelectG b r v) type ArraySelectFieldsG b r v = Fields (ArraySelectG b r v)
-- Remote schema relationship -- Remote schema relationships
data RemoteFieldArgument data RemoteFieldArgument
= RemoteFieldArgument = RemoteFieldArgument
@ -369,8 +372,8 @@ data RemoteFieldArgument
, _rfaValue :: !(InputValue RemoteSchemaVariable) , _rfaValue :: !(InputValue RemoteSchemaVariable)
} deriving (Eq,Show) } deriving (Eq,Show)
data RemoteSelect (b :: BackendType) data RemoteSchemaSelect (b :: BackendType)
= RemoteSelect = RemoteSchemaSelect
{ _rselArgs :: ![RemoteFieldArgument] { _rselArgs :: ![RemoteFieldArgument]
, _rselSelection :: !(G.SelectionSet G.NoFragments RemoteSchemaVariable) , _rselSelection :: !(G.SelectionSet G.NoFragments RemoteSchemaVariable)
, _rselHasuraFields :: !(HashSet (DBJoinField b)) , _rselHasuraFields :: !(HashSet (DBJoinField b))
@ -378,16 +381,45 @@ data RemoteSelect (b :: BackendType)
, _rselRemoteSchema :: !RemoteSchemaInfo , _rselRemoteSchema :: !RemoteSchemaInfo
} }
-- | Captures the selection set of a remote source relationship.
data SourceRelationshipSelection
(b :: BackendType)
(r :: BackendType -> Type)
(vf :: BackendType -> Type)
= SourceRelationshipObject !(AnnObjectSelectG b r (vf b))
| SourceRelationshipArray !(AnnSimpleSelectG b r (vf b))
| SourceRelationshipArrayAggregate !(AnnAggregateSelectG b r (vf b))
-- Remote db relationship -- | A relationship to a remote source. 'vf' (could use a better name) is
-- analogous to 'v' in other IR types such as 'AnnFieldG'. vf's kind is
data DBRemoteSelect (src :: BackendType) (r :: BackendType -> Type) (tgt :: BackendType) -- (BackendType -> Type) instead of v's 'Type' so that 'v' of 'AnnFieldG' can
= DBRemoteSelect -- be specific to the backend that it captures ('b' of an AnnFieldG changes as
{ _dbrselHasuraColumns :: ![(ColumnInfo src, ColumnInfo tgt)] -- we walk down the IR branches which capture relationships to other databases)
, _dbrselTargetQuery :: !(QueryDB tgt r (r tgt)) data RemoteSourceSelect
, _dbrselTargetConfig :: !(SourceConfig tgt) (src :: BackendType)
} (vf :: BackendType -> Type)
(tgt :: BackendType)
= RemoteSourceSelect
{ _rssSourceName :: !SourceName
, _rssSourceConfig :: !(SourceConfig tgt)
, _rssSelection :: !(SourceRelationshipSelection tgt (RemoteSelect vf) vf)
, _rssJoinMapping :: !(HM.HashMap FieldName (ColumnInfo src, ScalarType tgt, Column tgt))
-- ^ Additional information about the source's join columns:
-- (ColumnInfo src) so that we can add the join column to the AST
-- (ScalarType tgt) so that the remote can interpret the join values coming
-- from src
-- (Column tgt) so that an appropriate join condition / IN clause can be built
-- by the remote
}
-- | A remote relationship to either a remote schema or a remote source.
-- See RemoteSourceSelect for explanation on 'vf'.
data RemoteSelect
(vf :: BackendType -> Type)
(src :: BackendType)
= RemoteSelectRemoteSchema !(RemoteSchemaSelect src)
-- ^ AnyBackend is used here to capture a relationship to an arbitrary target
| RemoteSelectSource !(AB.AnyBackend (RemoteSourceSelect src vf))
-- Permissions -- Permissions