Break up class BackendSchema in two

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4901
GitOrigin-RevId: fdef33b69626d1694dc1938bb76e001284dd1b50
This commit is contained in:
Philip Lykke Carlsen 2022-06-30 17:22:19 +02:00 committed by hasura-bot
parent c8aa0f3e42
commit 824697a1e8
14 changed files with 193 additions and 79 deletions

View File

@ -65,10 +65,7 @@ instance BackendSchema 'BigQuery where
nodesAggExtension = Just ()
streamSubscriptionExtension = Nothing
-- table arguments
tableArguments = defaultTableArgs
-- indivdual components
-- individual components
columnParser = bqColumnParser
scalarSelectionArgumentsParser = bqScalarSelectionArgumentsParser
orderByOperators _sourceInfo = bqOrderByOperators
@ -77,6 +74,12 @@ instance BackendSchema 'BigQuery where
aggregateOrderByCountType = BigQuery.IntegerScalarType
computedField = bqComputedField
instance BackendTableSelectSchema 'BigQuery where
tableArguments = defaultTableArgs
selectTable = defaultSelectTable
selectTableAggregate = defaultSelectTableAggregate
tableSelectionSet = defaultTableSelectionSet
----------------------------------------------------------------
-- Top level parsers

View File

@ -16,7 +16,7 @@ import Hasura.Backends.DataConnector.IR.Scalar.Type qualified as IR.S.T
import Hasura.Backends.DataConnector.IR.Scalar.Value qualified as IR.S.V
import Hasura.Base.Error
import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Schema.Backend (BackendSchema (..), ComparisonExp, MonadBuildSchema)
import Hasura.GraphQL.Schema.Backend (BackendSchema (..), BackendTableSelectSchema (..), ComparisonExp, MonadBuildSchema)
import Hasura.GraphQL.Schema.BoolExp qualified as GS.BE
import Hasura.GraphQL.Schema.Build qualified as GS.B
import Hasura.GraphQL.Schema.Common qualified as GS.C
@ -55,9 +55,6 @@ instance BackendSchema 'DataConnector where
nodesAggExtension = Nothing
streamSubscriptionExtension = Nothing
-- table arguments
tableArguments = tableArgs'
-- individual components
columnParser = columnParser'
scalarSelectionArgumentsParser _ = pure Nothing
@ -71,6 +68,12 @@ instance BackendSchema 'DataConnector where
computedField =
error "computedField: not implemented for the Data Connector backend."
instance BackendTableSelectSchema 'DataConnector where
tableArguments = tableArgs'
selectTable = GS.S.defaultSelectTable
selectTableAggregate = GS.S.defaultSelectTableAggregate
tableSelectionSet = GS.S.defaultTableSelectionSet
--------------------------------------------------------------------------------
experimentalBuildTableRelayQueryFields ::

View File

@ -73,8 +73,6 @@ instance BackendSchema 'MSSQL where
nodesAggExtension = Just ()
streamSubscriptionExtension = Nothing
-- table arguments
tableArguments = msTableArgs
mkRelationshipParser = msMkRelationshipParser
-- individual components
@ -86,6 +84,12 @@ instance BackendSchema 'MSSQL where
aggregateOrderByCountType = MSSQL.IntegerType
computedField = msComputedField
instance BackendTableSelectSchema 'MSSQL where
tableArguments = msTableArgs
selectTable = defaultSelectTable
selectTableAggregate = defaultSelectTableAggregate
tableSelectionSet = defaultTableSelectionSet
----------------------------------------------------------------
-- * Top level parsers

View File

@ -50,7 +50,6 @@ instance BackendSchema 'MySQL where
buildFunctionRelayQueryFields = buildFunctionRelayQueryFields'
buildFunctionMutationFields = buildFunctionMutationFields'
relayExtension = Nothing
tableArguments = mysqlTableArgs
nodesAggExtension = Just ()
streamSubscriptionExtension = Nothing
columnParser = columnParser'
@ -61,6 +60,12 @@ instance BackendSchema 'MySQL where
aggregateOrderByCountType = error "aggregateOrderByCountType: MySQL backend does not support this operation yet."
computedField = error "computedField: MySQL backend does not support this operation yet."
instance BackendTableSelectSchema 'MySQL where
tableArguments = mysqlTableArgs
selectTable = defaultSelectTable
selectTableAggregate = defaultSelectTableAggregate
tableSelectionSet = defaultTableSelectionSet
mysqlTableArgs ::
forall r m n.
MonadBuildSchema 'MySQL r m n =>

View File

@ -33,6 +33,7 @@ import Hasura.Backends.Postgres.Types.Update as PGIR
import Hasura.Base.Error
import Hasura.GraphQL.Schema.Backend
( BackendSchema,
BackendTableSelectSchema,
ComparisonExp,
MonadBuildSchema,
)
@ -72,6 +73,7 @@ import Hasura.RQL.Types.Source
import Hasura.RQL.Types.SourceCustomization
import Hasura.RQL.Types.Table (RolePermInfo (..), TableInfo, UpdPermInfo)
import Hasura.SQL.Backend (BackendType (Postgres), PostgresKind (Citus, Vanilla))
import Hasura.SQL.Tag (HasTag)
import Hasura.SQL.Types
import Language.GraphQL.Draft.Syntax qualified as G
@ -119,6 +121,18 @@ instance PostgresSchema 'Citus where
-- postgres schema
instance
( PostgresSchema pgKind,
Backend ('Postgres pgKind),
HasTag ('Postgres pgKind)
) =>
BS.BackendTableSelectSchema ('Postgres pgKind)
where
tableArguments = defaultTableArgs
selectTable = defaultSelectTable
selectTableAggregate = defaultSelectTableAggregate
tableSelectionSet = defaultTableSelectionSet
instance
( Backend ('Postgres pgKind),
PostgresSchema pgKind
@ -136,8 +150,6 @@ instance
buildFunctionRelayQueryFields = pgkBuildFunctionRelayQueryFields
buildFunctionMutationFields = buildFunctionMutationFieldsPG
-- table components
tableArguments = defaultTableArgs
mkRelationshipParser = GSB.mkDefaultRelationshipParser backendInsertParser ()
-- backend extensions
@ -177,6 +189,7 @@ backendInsertParser sourceName tableInfo =
buildTableRelayQueryFields ::
forall pgKind m n r.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
SourceInfo ('Postgres pgKind) ->
TableName ('Postgres pgKind) ->
TableInfo ('Postgres pgKind) ->
@ -193,6 +206,7 @@ buildTableRelayQueryFields sourceName tableName tableInfo gqlName pkeyColumns =
pgkBuildTableUpdateMutationFields ::
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
Scenario ->
-- | The source that the table lives in
SourceInfo ('Postgres pgKind) ->
@ -219,6 +233,7 @@ pgkBuildTableUpdateMutationFields scenario sourceName tableName tableInfo gqlNam
buildFunctionRelayQueryFields ::
forall pgKind m n r.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
SourceInfo ('Postgres pgKind) ->
FunctionName ('Postgres pgKind) ->
FunctionInfo ('Postgres pgKind) ->

View File

@ -50,6 +50,7 @@ import Language.GraphQL.Draft.Syntax qualified as G
selectFunction ::
forall r m n pgKind.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
-- | source name
SourceInfo ('Postgres pgKind) ->
-- | SQL function info
@ -86,6 +87,7 @@ selectFunction sourceInfo fi@FunctionInfo {..} description = runMaybeT do
selectFunctionAggregate ::
forall r m n pgKind.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
-- | source name
SourceInfo ('Postgres pgKind) ->
-- | SQL function info
@ -131,7 +133,9 @@ selectFunctionAggregate sourceInfo fi@FunctionInfo {..} description = runMaybeT
selectFunctionConnection ::
forall pgKind r m n.
MonadBuildSchema ('Postgres pgKind) r m n =>
( MonadBuildSchema ('Postgres pgKind) r m n,
BackendTableSelectSchema ('Postgres pgKind)
) =>
-- | source name
SourceInfo ('Postgres pgKind) ->
-- | SQL function info
@ -175,6 +179,7 @@ selectFunctionConnection sourceInfo fi@FunctionInfo {..} description pkeyColumns
computedFieldPG ::
forall pgKind r m n.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
SourceInfo ('Postgres pgKind) ->
ComputedFieldInfo ('Postgres pgKind) ->
TableName ('Postgres pgKind) ->
@ -413,6 +418,7 @@ functionArgs sourceInfo functionTrackedAs (toList -> inputArgs) = do
buildFunctionQueryFieldsPG ::
forall r m n pgKind.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
SourceInfo ('Postgres pgKind) ->
FunctionName ('Postgres pgKind) ->
FunctionInfo ('Postgres pgKind) ->
@ -441,6 +447,7 @@ buildFunctionQueryFieldsPG sourceInfo functionName functionInfo tableName = do
buildFunctionMutationFieldsPG ::
forall r m n pgKind.
MonadBuildSchema ('Postgres pgKind) r m n =>
BackendTableSelectSchema ('Postgres pgKind) =>
SourceInfo ('Postgres pgKind) ->
FunctionName ('Postgres pgKind) ->
FunctionInfo ('Postgres pgKind) ->

View File

@ -25,6 +25,7 @@
module Hasura.GraphQL.Schema.Backend
( -- * Main Types
BackendSchema (..),
BackendTableSelectSchema (..),
MonadBuildSchema,
-- * Auxiliary Types
@ -89,10 +90,7 @@ type MonadBuildSchema b r m n =
--
-- See <#modelling Note BackendSchema modelling principles>.
class
( Backend b,
Eq (BooleanOperators b (UnpreparedValue b)),
Eq (FunctionArgumentExp b (UnpreparedValue b))
) =>
Backend b =>
BackendSchema (b :: BackendType)
where
-- top level parsers
@ -184,13 +182,6 @@ class
TableName b ->
m [FieldParser n (MutationDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
-- table components
tableArguments ::
MonadBuildSchema b r m n =>
SourceInfo b ->
TableInfo b ->
m (InputFieldsParser n (IR.SelectArgsG b (UnpreparedValue b)))
-- | Make a parser for relationships. Default implementaton elides
-- relationships altogether.
mkRelationshipParser ::
@ -246,6 +237,52 @@ class
TableInfo b ->
m (Maybe (FieldParser n (AnnotatedField b)))
-- | The public interface for the schema of table queries exposed by a backend.
--
-- Remote Schemas and the Relay schema are the chief backend-agnostic clients of
-- this typeclass.
--
-- Some of schema building components in the "Hasura.GraphQL.Schema" namespace
-- also make use of these methods, ensuring backends expose a consistent schema
-- regardless of the mode it's referenced.
--
-- Default implementations exist for all of these in
-- 'Hasura.GraphQL.Schema.Select'.
class Backend b => BackendTableSelectSchema (b :: BackendType) where
tableArguments ::
MonadBuildSchemaBase r m n =>
SourceInfo b ->
TableInfo b ->
m (InputFieldsParser n (IR.SelectArgsG b (UnpreparedValue b)))
tableSelectionSet ::
MonadBuildSchemaBase r m n =>
SourceInfo b ->
TableInfo b ->
m (Maybe (Parser 'Output n (AnnotatedFields b)))
selectTable ::
MonadBuildSchemaBase r m n =>
SourceInfo b ->
-- | table info
TableInfo b ->
-- | field display name
G.Name ->
-- | field description, if any
Maybe G.Description ->
m (Maybe (FieldParser n (SelectExp b)))
selectTableAggregate ::
MonadBuildSchemaBase r m n =>
SourceInfo b ->
-- | table info
TableInfo b ->
-- | field display name
G.Name ->
-- | field description, if any
Maybe G.Description ->
m (Maybe (FieldParser n (AggSelectExp b)))
type ComparisonExp b = OpExpG b (UnpreparedValue b)
-- $modelling

View File

@ -55,7 +55,7 @@ where
import Data.Has (getter)
import Data.Text.Casing qualified as C
import Data.Text.Extended
import Hasura.GraphQL.Schema.Backend (MonadBuildSchema)
import Hasura.GraphQL.Schema.Backend (BackendTableSelectSchema (..), MonadBuildSchema)
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Mutation
import Hasura.GraphQL.Schema.Parser hiding (EnumValueInfo, field)
@ -97,7 +97,9 @@ setFieldNameCase tCase tInfo crf getFieldName tableName =
-- parsers of the query root and the field parsers of the subscription root
buildTableQueryAndSubscriptionFields ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
SourceInfo b ->
TableName b ->
TableInfo b ->
@ -178,7 +180,9 @@ buildTableQueryAndSubscriptionFields sourceInfo tableName tableInfo streamSubCtx
buildTableStreamingSubscriptionFields ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
SourceInfo b ->
TableName b ->
TableInfo b ->
@ -198,6 +202,7 @@ buildTableStreamingSubscriptionFields sourceInfo tableName tableInfo tableIdenti
buildTableInsertMutationFields ::
forall b r m n.
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
(SourceInfo b -> TableInfo b -> m (InputFieldsParser n (BackendInsert b (UnpreparedValue b)))) ->
Scenario ->
SourceInfo b ->
@ -246,7 +251,9 @@ buildTableInsertMutationFields backendInsertAction scenario sourceInfo tableName
-- > ...
buildTableUpdateMutationFields ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
-- | an action that builds @BackendUpdate@ with the
-- backend-specific data needed to perform an update mutation
( TableInfo b ->
@ -285,7 +292,9 @@ buildTableUpdateMutationFields mkBackendUpdate scenario sourceInfo tableName tab
buildTableDeleteMutationFields ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
Scenario ->
SourceInfo b ->
TableName b ->

View File

@ -56,6 +56,7 @@ import Language.GraphQL.Draft.Syntax qualified as G
insertIntoTable ::
forall b r m n.
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
(SourceInfo b -> TableInfo b -> m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
Scenario ->
SourceInfo b ->
@ -101,7 +102,8 @@ insertIntoTable backendInsertAction scenario sourceInfo tableInfo fieldName desc
-- different: it only allows selecting columns from the row being inserted.
insertOneIntoTable ::
forall b r m n.
(MonadBuildSchema b r m n) =>
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
(SourceInfo b -> TableInfo b -> m (InputFieldsParser n (BackendInsert b (IR.UnpreparedValue b)))) ->
Scenario ->
-- | source of the table
@ -335,7 +337,9 @@ mkInsertObject objects tableInfo backendInsert insertPerms updatePerms =
-- to delete several rows from a DB table
deleteFromTable ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
Scenario ->
-- | table source
SourceInfo b ->
@ -369,6 +373,7 @@ deleteFromTable scenario sourceInfo tableInfo fieldName description = runMaybeT
deleteFromTableByPk ::
forall b r m n.
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
Scenario ->
-- | table source
SourceInfo b ->
@ -417,6 +422,7 @@ mkDeleteObject table columns deletePerms (whereExp, mutationOutput) =
mutationSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
SourceInfo b ->
TableInfo b ->
m (Parser 'Output n (IR.MutFldsG b (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue b)))

View File

@ -57,23 +57,25 @@ nodeInterface sourceCache = NodeInterfaceParserBuilder $ memoizeOn 'nodeInterfac
tCase <- asks getter
tables :: [Parser 'Output n (SourceName, AB.AnyBackend TableMap)] <-
catMaybes . concat <$> for (Map.toList sourceCache) \(sourceName, anySourceInfo) ->
AB.dispatchAnyBackend @BackendSchema anySourceInfo \(sourceInfo :: SourceInfo b) ->
for (Map.toList $ takeValidTables $ _siTables sourceInfo) \(tableName, tableInfo) -> runMaybeT do
tablePkeyColumns <- hoistMaybe $ tableInfo ^? tiCoreInfo . tciPrimaryKey . _Just . pkColumns
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
annotatedFieldsParser <-
MaybeT $
P.withTypenameCustomization
(mkCustomizedTypename (_scTypeNames $ _siCustomization sourceInfo) tCase)
(tableSelectionSet sourceInfo tableInfo)
pure $
annotatedFieldsParser <&> \fields ->
( sourceName,
AB.mkAnyBackend $
TableMap $
Map.singleton tableName $
NodeInfo (_siConfiguration sourceInfo) selectPermissions tablePkeyColumns fields
)
AB.dispatchAnyBackendWithTwoConstraints @BackendSchema @BackendTableSelectSchema
anySourceInfo
\(sourceInfo :: SourceInfo b) ->
for (Map.toList $ takeValidTables $ _siTables sourceInfo) \(tableName, tableInfo) -> runMaybeT do
tablePkeyColumns <- hoistMaybe $ tableInfo ^? tiCoreInfo . tciPrimaryKey . _Just . pkColumns
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
annotatedFieldsParser <-
MaybeT $
P.withTypenameCustomization
(mkCustomizedTypename (_scTypeNames $ _siCustomization sourceInfo) tCase)
(tableSelectionSet sourceInfo tableInfo)
pure $
annotatedFieldsParser <&> \fields ->
( sourceName,
AB.mkAnyBackend $
TableMap $
Map.singleton tableName $
NodeInfo (_siConfiguration sourceInfo) selectPermissions tablePkeyColumns fields
)
pure $
Map.fromListWith fuseAnyMaps
<$> P.selectionSetInterface

View File

@ -47,9 +47,11 @@ remoteRelationshipField sourceCache remoteSchemaCache = RemoteRelationshipParser
guard $ isHasuraSchema queryType
case _rfiRHS of
RFISource anyRemoteSourceFieldInfo ->
dispatchAnyBackend @BackendSchema anyRemoteSourceFieldInfo \remoteSourceFieldInfo -> do
fields <- lift $ remoteRelationshipToSourceField sourceCache remoteSourceFieldInfo
pure $ fmap (IR.RemoteSourceField . mkAnyBackend) <$> fields
dispatchAnyBackendWithTwoConstraints @BackendSchema @BackendTableSelectSchema
anyRemoteSourceFieldInfo
\remoteSourceFieldInfo -> do
fields <- lift $ remoteRelationshipToSourceField sourceCache remoteSourceFieldInfo
pure $ fmap (IR.RemoteSourceField . mkAnyBackend) <$> fields
RFISchema remoteSchema -> do
fields <- MaybeT $ remoteRelationshipToSchemaField remoteSchemaCache _rfiLHS remoteSchema
pure $ pure $ IR.RemoteSchemaField <$> fields
@ -171,7 +173,10 @@ lookupNestedFieldType parentTypeName remoteSchemaIntrospection (fieldCall :| res
-- relationship field, hence [FieldParser ...] instead of 'FieldParser'
remoteRelationshipToSourceField ::
forall r m n tgt.
(MonadBuildSchemaBase r m n, BackendSchema tgt) =>
( MonadBuildSchemaBase r m n,
BackendSchema tgt,
BackendTableSelectSchema tgt
) =>
SourceCache ->
RemoteSourceFieldInfo tgt ->
m [FieldParser n (IR.RemoteSourceSelect (IR.RemoteRelationshipField IR.UnpreparedValue) IR.UnpreparedValue tgt)]

View File

@ -7,11 +7,12 @@
-- relay-type queries. All schema with "relay" or "connection" in the name is
-- used exclusively by relay.
module Hasura.GraphQL.Schema.Select
( selectTable,
selectTableByPk,
selectTableAggregate,
( selectTableByPk,
selectTableConnection,
defaultSelectTable,
defaultSelectTableAggregate,
defaultTableArgs,
defaultTableSelectionSet,
tableAggregationFields,
tableConnectionArgs,
tableConnectionSelectionSet,
@ -21,7 +22,6 @@ module Hasura.GraphQL.Schema.Select
tableLimitArg,
tableOffsetArg,
tablePermissionsInfo,
tableSelectionSet,
tableSelectionList,
)
where
@ -87,9 +87,9 @@ import Language.GraphQL.Draft.Syntax qualified as G
-- > col1: col1_type
-- > col2: col2_type
-- > }: [table!]!
selectTable ::
defaultSelectTable ::
forall b r m n.
MonadBuildSchema b r m n =>
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
SourceInfo b ->
-- | table info
TableInfo b ->
@ -98,10 +98,10 @@ selectTable ::
-- | field description, if any
Maybe G.Description ->
m (Maybe (FieldParser n (SelectExp b)))
selectTable sourceInfo tableInfo fieldName description = runMaybeT do
defaultSelectTable sourceInfo tableInfo fieldName description = runMaybeT do
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
selectionSetParser <- MaybeT $ tableSelectionList sourceInfo tableInfo
lift $ memoizeOn 'selectTable (_siName sourceInfo, tableName, fieldName) do
lift $ memoizeOn 'defaultSelectTable (_siName sourceInfo, tableName, fieldName) do
stringifyNum <- retrieve soStringifyNum
tableArgsParser <- tableArguments sourceInfo tableInfo
pure $
@ -139,7 +139,9 @@ selectTable sourceInfo tableInfo fieldName description = runMaybeT do
-- > }: table_nameConnection!
selectTableConnection ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
SourceInfo b ->
-- | table info
TableInfo b ->
@ -189,7 +191,7 @@ selectTableConnection sourceInfo tableInfo fieldName description pkeyColumns = r
-- doesn't have select permissions for.
selectTableByPk ::
forall b r m n.
MonadBuildSchema b r m n =>
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
SourceInfo b ->
-- | table info
TableInfo b ->
@ -239,9 +241,9 @@ selectTableByPk sourceInfo tableInfo fieldName description = runMaybeT do
--
-- Returns Nothing if there's nothing that can be selected with
-- current permissions.
selectTableAggregate ::
defaultSelectTableAggregate ::
forall b r m n.
MonadBuildSchema b r m n =>
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
SourceInfo b ->
-- | table info
TableInfo b ->
@ -250,12 +252,12 @@ selectTableAggregate ::
-- | field description, if any
Maybe G.Description ->
m (Maybe (FieldParser n (AggSelectExp b)))
selectTableAggregate sourceInfo tableInfo fieldName description = runMaybeT $ do
defaultSelectTableAggregate sourceInfo tableInfo fieldName description = runMaybeT $ do
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
guard $ spiAllowAgg selectPermissions
xNodesAgg <- hoistMaybe $ nodesAggExtension @b
nodesParser <- MaybeT $ tableSelectionList sourceInfo tableInfo
lift $ memoizeOn 'selectTableAggregate (_siName sourceInfo, tableName, fieldName) do
lift $ memoizeOn 'defaultSelectTableAggregate (_siName sourceInfo, tableName, fieldName) do
stringifyNum <- retrieve soStringifyNum
tableGQLName <- getTableGQLName tableInfo
tableArgsParser <- tableArguments sourceInfo tableInfo
@ -346,13 +348,17 @@ cause errors on the client side, for the following reasons:
-- > # remote relationships
-- > remote_field: field_type
-- > }
tableSelectionSet ::
defaultTableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b,
Eq (BooleanOperators b (IR.UnpreparedValue b)),
Eq (FunctionArgumentExp b (IR.UnpreparedValue b))
) =>
SourceInfo b ->
TableInfo b ->
m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionSet sourceInfo tableInfo = runMaybeT do
defaultTableSelectionSet sourceInfo tableInfo = runMaybeT do
_selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
schemaKind <- lift $ retrieve scSchemaKind
-- If this check fails, it means we're attempting to build a Relay schema, but
@ -360,7 +366,7 @@ tableSelectionSet sourceInfo tableInfo = runMaybeT do
-- incomplete selection set, we fail early and return 'Nothing'. This check
-- must happen first, since we can't memoize a @Maybe Parser@.
guard $ isHasuraSchema schemaKind || isJust (relayExtension @b)
lift $ memoizeOn 'tableSelectionSet (sourceName, tableName) do
lift $ memoizeOn 'defaultTableSelectionSet (sourceName, tableName) do
tableGQLName <- getTableGQLName tableInfo
objectTypename <- P.mkTypename tableGQLName
let xRelay = relayExtension @b
@ -404,7 +410,7 @@ tableSelectionSet sourceInfo tableInfo = runMaybeT do
-- Just a @'nonNullableObjectList' wrapper over @'tableSelectionSet'.
-- > table_name: [table!]!
tableSelectionList ::
MonadBuildSchema b r m n =>
(MonadBuildSchemaBase r m n, BackendTableSelectSchema b) =>
SourceInfo b ->
TableInfo b ->
m (Maybe (Parser 'Output n (AnnotatedFields b)))
@ -436,7 +442,7 @@ nonNullableObjectList =
-- > }
tableConnectionSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
SourceInfo b ->
TableInfo b ->
m (Maybe (Parser 'Output n (ConnectionFields b)))
@ -926,7 +932,11 @@ tableAggregationFields sourceInfo tableInfo =
-- > field_name(arg_name: arg_type, ...): field_type
fieldSelection ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b,
Eq (BooleanOperators b (IR.UnpreparedValue b)),
Eq (FunctionArgumentExp b (IR.UnpreparedValue b))
) =>
SourceInfo b ->
TableName b ->
TableInfo b ->
@ -1075,7 +1085,11 @@ join) satisfies `p(T)`.
-- | Field parsers for a table relationship
relationshipField ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b,
Eq (BooleanOperators b (IR.UnpreparedValue b)),
Eq (FunctionArgumentExp b (IR.UnpreparedValue b))
) =>
SourceInfo b ->
TableName b ->
RelInfo b ->

View File

@ -235,7 +235,9 @@ tableStreamArguments sourceInfo tableInfo = do
-- | Field parser for a streaming subscription for a table.
selectStreamTable ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
SourceInfo b ->
-- | table info
TableInfo b ->

View File

@ -21,12 +21,11 @@ import Data.HashMap.Strict.Extended qualified as M
import Data.List.NonEmpty qualified as NE
import Data.Text.Extended (commaSeparated, dquote, (<>>))
import Hasura.Base.Error (QErr)
import Hasura.GraphQL.Schema.Backend (BackendSchema, MonadBuildSchema, columnParser)
import Hasura.GraphQL.Schema.Backend (BackendSchema (..), BackendTableSelectSchema (..), MonadBuildSchema, columnParser)
import Hasura.GraphQL.Schema.BoolExp (boolExp)
import Hasura.GraphQL.Schema.Common (Scenario (..), mapField, partialSQLExpToUnpreparedValue)
import Hasura.GraphQL.Schema.Mutation (mutationSelectionSet, primaryKeysArguments)
import Hasura.GraphQL.Schema.Parser qualified as P
import Hasura.GraphQL.Schema.Select (tableSelectionSet)
import Hasura.GraphQL.Schema.Table (getTableGQLName, tableColumns, tablePermissions, tableUpdateColumns)
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp (AnnBoolExp, annBoolExpTrue)
@ -261,7 +260,9 @@ incOp = UpdateOperator {..}
-- there are columns the user is allowed to update; otherwise returns Nothing.
updateTable ::
forall b r m n.
MonadBuildSchema b r m n =>
( MonadBuildSchema b r m n,
BackendTableSelectSchema b
) =>
-- | backend-specific data needed to perform an update mutation
P.InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) ->
Scenario ->
@ -299,6 +300,7 @@ updateTable backendUpdate scenario sourceInfo tableInfo fieldName description =
updateTableByPk ::
forall b r m n.
MonadBuildSchema b r m n =>
BackendTableSelectSchema b =>
-- | backend-specific data needed to perform an update mutation
P.InputFieldsParser n (BackendUpdate b (UnpreparedValue b)) ->
Scenario ->