2023-06-02 13:36:06 +03:00
|
|
|
{-# LANGUAGE TemplateHaskellQuotes #-}
|
|
|
|
|
2023-04-13 19:10:38 +03:00
|
|
|
-- | Schema parsers for native queries.
|
2023-05-10 18:13:56 +03:00
|
|
|
module Hasura.NativeQuery.Schema
|
|
|
|
( defaultSelectNativeQuery,
|
|
|
|
defaultSelectNativeQueryObject,
|
|
|
|
defaultBuildNativeQueryRootFields,
|
|
|
|
)
|
|
|
|
where
|
2023-01-19 14:25:52 +03:00
|
|
|
|
|
|
|
import Data.Has (Has (getter))
|
2023-04-26 18:42:13 +03:00
|
|
|
import Data.HashMap.Strict qualified as HashMap
|
2023-07-04 20:19:44 +03:00
|
|
|
import Data.HashMap.Strict.InsOrd qualified as InsOrdHashMap
|
|
|
|
import Data.Set qualified as S
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.GraphQL.Schema.Backend
|
2023-04-19 12:03:36 +03:00
|
|
|
( BackendLogicalModelSelectSchema (..),
|
2023-07-04 20:19:44 +03:00
|
|
|
BackendNativeQuerySelectSchema (..),
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendTableSelectSchema (..),
|
2023-01-19 14:25:52 +03:00
|
|
|
MonadBuildSchema,
|
2023-08-10 17:21:34 +03:00
|
|
|
tableSelectionSet,
|
2023-01-19 14:25:52 +03:00
|
|
|
)
|
|
|
|
import Hasura.GraphQL.Schema.Common
|
2023-07-04 20:19:44 +03:00
|
|
|
( AnnotatedField,
|
|
|
|
AnnotatedFields,
|
|
|
|
SchemaT,
|
|
|
|
askNativeQueryInfo,
|
2023-08-10 17:21:34 +03:00
|
|
|
askTableInfo,
|
2023-07-04 20:19:44 +03:00
|
|
|
parsedSelectionsToFields,
|
2023-01-19 14:25:52 +03:00
|
|
|
retrieve,
|
2023-08-10 17:21:34 +03:00
|
|
|
scRole,
|
|
|
|
tablePermissionsInfo,
|
2023-07-04 20:19:44 +03:00
|
|
|
textToName,
|
2023-01-19 14:25:52 +03:00
|
|
|
)
|
|
|
|
import Hasura.GraphQL.Schema.Parser qualified as P
|
2023-08-10 17:21:34 +03:00
|
|
|
import Hasura.GraphQL.Schema.Table (tableSelectPermissions)
|
2023-07-04 20:19:44 +03:00
|
|
|
import Hasura.LogicalModel.Cache (LogicalModelInfo (..))
|
|
|
|
import Hasura.LogicalModel.Schema (buildLogicalModelIR, buildLogicalModelPermissions, logicalModelFieldParsers, logicalModelSelectionList)
|
2023-05-03 12:59:21 +03:00
|
|
|
import Hasura.LogicalModelResolver.Schema (argumentsSchema)
|
2023-04-13 19:10:38 +03:00
|
|
|
import Hasura.NativeQuery.Cache (NativeQueryInfo (..))
|
|
|
|
import Hasura.NativeQuery.IR (NativeQuery (..))
|
2023-05-02 15:54:30 +03:00
|
|
|
import Hasura.NativeQuery.Metadata (ArgumentName (..), InterpolatedQuery (..))
|
2023-04-13 19:10:38 +03:00
|
|
|
import Hasura.NativeQuery.Types (NullableScalarType (..), getNativeQueryName)
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR.Root (RemoteRelationshipField)
|
2023-01-27 17:36:35 +03:00
|
|
|
import Hasura.RQL.IR.Select (QueryDB (QDBMultipleRows))
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.RQL.IR.Select qualified as IR
|
2023-05-31 18:41:24 +03:00
|
|
|
import Hasura.RQL.IR.Value (Provenance (FreshVar), UnpreparedValue (UVParameter))
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.RQL.Types.Column qualified as Column
|
2023-07-04 20:19:44 +03:00
|
|
|
import Hasura.RQL.Types.Common (RelType (..), relNameToTxt)
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.RQL.Types.Metadata.Object qualified as MO
|
2023-07-04 20:19:44 +03:00
|
|
|
import Hasura.RQL.Types.Relationships.Local (Nullable (..), RelInfo (..), RelTarget (..))
|
2023-04-24 18:17:15 +03:00
|
|
|
import Hasura.RQL.Types.Schema.Options qualified as Options
|
2023-01-19 14:25:52 +03:00
|
|
|
import Hasura.RQL.Types.Source
|
|
|
|
( SourceInfo (_siCustomization, _siName),
|
|
|
|
)
|
|
|
|
import Hasura.RQL.Types.SourceCustomization
|
|
|
|
( ResolvedSourceCustomization (_rscNamingConvention),
|
|
|
|
)
|
|
|
|
import Hasura.SQL.AnyBackend (mkAnyBackend)
|
|
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
|
|
|
2023-05-10 18:13:56 +03:00
|
|
|
defaultSelectNativeQueryObject ::
|
2023-01-19 14:25:52 +03:00
|
|
|
forall b r m n.
|
|
|
|
( MonadBuildSchema b r m n,
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendNativeQuerySelectSchema b,
|
|
|
|
BackendTableSelectSchema b
|
2023-01-19 14:25:52 +03:00
|
|
|
) =>
|
2023-05-10 18:13:56 +03:00
|
|
|
-- native query info
|
2023-04-13 19:10:38 +03:00
|
|
|
NativeQueryInfo b ->
|
2023-05-10 18:13:56 +03:00
|
|
|
-- field name
|
|
|
|
G.Name ->
|
|
|
|
-- field description, if any
|
|
|
|
Maybe G.Description ->
|
2023-01-19 14:25:52 +03:00
|
|
|
SchemaT
|
|
|
|
r
|
|
|
|
m
|
2023-05-10 18:13:56 +03:00
|
|
|
(Maybe (P.FieldParser n (IR.AnnObjectSelectG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
|
2023-07-04 20:19:44 +03:00
|
|
|
defaultSelectNativeQueryObject nqi@NativeQueryInfo {..} fieldName description = runMaybeT $ do
|
2023-05-10 18:13:56 +03:00
|
|
|
nativeQueryArgsParser <-
|
|
|
|
nativeQueryArgumentsSchema @b @r @m @n fieldName _nqiArguments
|
|
|
|
|
|
|
|
sourceInfo :: SourceInfo b <- asks getter
|
|
|
|
|
|
|
|
let sourceName = _siName sourceInfo
|
|
|
|
|
|
|
|
logicalModelPermissions <-
|
2023-05-24 16:51:56 +03:00
|
|
|
MaybeT
|
|
|
|
$ buildLogicalModelPermissions @b @r @m @n _nqiReturns
|
2023-05-10 18:13:56 +03:00
|
|
|
|
2023-07-04 20:19:44 +03:00
|
|
|
-- if we have any relationships, we use a Native Query rather than Logical
|
|
|
|
-- Model parser
|
|
|
|
let hasExtraFields = not (null _nqiRelationships)
|
|
|
|
|
2023-05-15 11:10:59 +03:00
|
|
|
selectionSetParser <-
|
2023-07-04 20:19:44 +03:00
|
|
|
if hasExtraFields
|
|
|
|
then MaybeT $ nativeQuerySelectionSet nqi
|
|
|
|
else MaybeT $ logicalModelSelectionSet _nqiReturns
|
2023-05-10 18:13:56 +03:00
|
|
|
|
|
|
|
let sourceObj =
|
|
|
|
MO.MOSourceObjId
|
|
|
|
sourceName
|
|
|
|
(mkAnyBackend $ MO.SMONativeQuery @b _nqiRootFieldName)
|
|
|
|
|
2023-06-02 13:36:06 +03:00
|
|
|
lift $ P.memoizeOn 'defaultSelectNativeQueryObject (sourceName, fieldName) do
|
|
|
|
pure
|
|
|
|
$ P.setFieldParserOrigin sourceObj
|
|
|
|
$ P.subselection
|
|
|
|
fieldName
|
|
|
|
description
|
|
|
|
nativeQueryArgsParser
|
|
|
|
selectionSetParser
|
|
|
|
<&> \(nqArgs, fields) ->
|
|
|
|
IR.AnnObjectSelectG
|
|
|
|
fields
|
|
|
|
( IR.FromNativeQuery
|
|
|
|
NativeQuery
|
|
|
|
{ nqRootFieldName = _nqiRootFieldName,
|
|
|
|
nqInterpolatedQuery = interpolatedQuery _nqiCode nqArgs,
|
|
|
|
nqLogicalModel = buildLogicalModelIR _nqiReturns
|
|
|
|
}
|
|
|
|
)
|
|
|
|
(IR._tpFilter logicalModelPermissions)
|
2023-04-04 15:45:20 +03:00
|
|
|
|
2023-07-04 20:19:44 +03:00
|
|
|
nativeQuerySelectionList ::
|
2023-08-10 17:21:34 +03:00
|
|
|
(MonadBuildSchema b r m n, BackendNativeQuerySelectSchema b, BackendTableSelectSchema b) =>
|
2023-07-04 20:19:44 +03:00
|
|
|
Nullable ->
|
|
|
|
NativeQueryInfo b ->
|
|
|
|
SchemaT r m (Maybe (P.Parser 'P.Output n (AnnotatedFields b)))
|
|
|
|
nativeQuerySelectionList nullability nativeQuery =
|
|
|
|
fmap nullabilityModifier <$> nativeQuerySelectionSet nativeQuery
|
|
|
|
where
|
|
|
|
nullabilityModifier =
|
|
|
|
case nullability of
|
|
|
|
Nullable -> nullableObjectList
|
|
|
|
NotNullable -> nonNullableObjectList
|
|
|
|
|
|
|
|
-- \| Converts an output type parser from object_type to [object_type!]!
|
|
|
|
nonNullableObjectList :: P.Parser 'P.Output m a -> P.Parser 'P.Output m a
|
|
|
|
nonNullableObjectList =
|
|
|
|
P.nonNullableParser . P.multiple . P.nonNullableParser
|
|
|
|
|
|
|
|
-- \| Converts an output type parser from object_type to [object_type!]
|
|
|
|
nullableObjectList :: P.Parser 'P.Output m a -> P.Parser 'P.Output m a
|
|
|
|
nullableObjectList =
|
|
|
|
P.multiple . P.nonNullableParser
|
|
|
|
|
2023-05-10 18:13:56 +03:00
|
|
|
-- | select a native query - implementation is the same for root fields and
|
|
|
|
-- array relationships
|
|
|
|
defaultSelectNativeQuery ::
|
|
|
|
forall b r m n.
|
|
|
|
( MonadBuildSchema b r m n,
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendNativeQuerySelectSchema b,
|
|
|
|
BackendTableSelectSchema b
|
2023-05-10 18:13:56 +03:00
|
|
|
) =>
|
|
|
|
-- native query info
|
|
|
|
NativeQueryInfo b ->
|
|
|
|
-- field name
|
|
|
|
G.Name ->
|
2023-05-31 03:14:16 +03:00
|
|
|
-- are fields nullable?
|
|
|
|
Nullable ->
|
2023-05-10 18:13:56 +03:00
|
|
|
-- field description, if any
|
|
|
|
Maybe G.Description ->
|
|
|
|
SchemaT
|
|
|
|
r
|
|
|
|
m
|
|
|
|
(Maybe (P.FieldParser n (IR.AnnSimpleSelectG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
|
2023-07-04 20:19:44 +03:00
|
|
|
defaultSelectNativeQuery nqi@NativeQueryInfo {..} fieldName nullability description = runMaybeT $ do
|
2023-04-13 19:10:38 +03:00
|
|
|
nativeQueryArgsParser <-
|
|
|
|
nativeQueryArgumentsSchema @b @r @m @n fieldName _nqiArguments
|
2023-02-15 20:55:06 +03:00
|
|
|
|
2023-01-19 14:25:52 +03:00
|
|
|
sourceInfo :: SourceInfo b <- asks getter
|
2023-02-15 20:55:06 +03:00
|
|
|
|
2023-01-19 14:25:52 +03:00
|
|
|
let sourceName = _siName sourceInfo
|
|
|
|
tCase = _rscNamingConvention $ _siCustomization sourceInfo
|
2023-02-15 20:55:06 +03:00
|
|
|
|
2023-01-19 14:25:52 +03:00
|
|
|
stringifyNumbers <- retrieve Options.soStringifyNumbers
|
|
|
|
|
2023-04-19 12:03:36 +03:00
|
|
|
logicalModelPermissions <-
|
2023-05-24 16:51:56 +03:00
|
|
|
MaybeT
|
|
|
|
$ buildLogicalModelPermissions @b @r @m @n _nqiReturns
|
2023-04-04 15:45:20 +03:00
|
|
|
|
2023-07-04 20:19:44 +03:00
|
|
|
-- if we have any relationships, we use a Native Query rather than Logical
|
|
|
|
-- Model parser
|
|
|
|
let hasExtraFields = not (null _nqiRelationships)
|
|
|
|
|
|
|
|
selectionListParser <-
|
|
|
|
if hasExtraFields
|
|
|
|
then MaybeT $ nativeQuerySelectionList nullability nqi
|
|
|
|
else MaybeT $ logicalModelSelectionList nullability _nqiReturns
|
|
|
|
|
|
|
|
logicalModelsArgsParser <- lift $ logicalModelArguments @b @r @m @n _nqiReturns
|
2023-02-03 14:15:08 +03:00
|
|
|
|
2023-04-04 15:45:20 +03:00
|
|
|
let sourceObj =
|
|
|
|
MO.MOSourceObjId
|
|
|
|
sourceName
|
2023-04-13 19:10:38 +03:00
|
|
|
(mkAnyBackend $ MO.SMONativeQuery @b _nqiRootFieldName)
|
2023-03-31 18:33:32 +03:00
|
|
|
|
2023-05-24 16:51:56 +03:00
|
|
|
pure
|
|
|
|
$ P.setFieldParserOrigin sourceObj
|
|
|
|
$ P.subselection
|
|
|
|
fieldName
|
|
|
|
description
|
|
|
|
( (,)
|
|
|
|
<$> logicalModelsArgsParser
|
|
|
|
<*> nativeQueryArgsParser
|
|
|
|
)
|
|
|
|
selectionListParser
|
|
|
|
<&> \((lmArgs, nqArgs), fields) ->
|
|
|
|
IR.AnnSelectG
|
|
|
|
{ IR._asnFields = fields,
|
|
|
|
IR._asnFrom =
|
|
|
|
IR.FromNativeQuery
|
|
|
|
NativeQuery
|
|
|
|
{ nqRootFieldName = _nqiRootFieldName,
|
|
|
|
nqInterpolatedQuery = interpolatedQuery _nqiCode nqArgs,
|
|
|
|
nqLogicalModel = buildLogicalModelIR _nqiReturns
|
|
|
|
},
|
|
|
|
IR._asnPerm = logicalModelPermissions,
|
|
|
|
IR._asnArgs = lmArgs,
|
|
|
|
IR._asnStrfyNum = stringifyNumbers,
|
|
|
|
IR._asnNamingConvention = Just tCase
|
|
|
|
}
|
2023-05-10 18:13:56 +03:00
|
|
|
|
|
|
|
defaultBuildNativeQueryRootFields ::
|
|
|
|
forall b r m n.
|
|
|
|
( MonadBuildSchema b r m n,
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendNativeQuerySelectSchema b,
|
|
|
|
BackendTableSelectSchema b
|
2023-05-10 18:13:56 +03:00
|
|
|
) =>
|
|
|
|
NativeQueryInfo b ->
|
|
|
|
SchemaT
|
|
|
|
r
|
|
|
|
m
|
|
|
|
(Maybe (P.FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
|
|
|
|
defaultBuildNativeQueryRootFields nqi@NativeQueryInfo {..} = do
|
|
|
|
let fieldName = getNativeQueryName _nqiRootFieldName
|
|
|
|
description = G.Description <$> _nqiDescription
|
2023-05-31 03:14:16 +03:00
|
|
|
(fmap . fmap . fmap) QDBMultipleRows (defaultSelectNativeQuery nqi fieldName NotNullable description)
|
2023-01-19 14:25:52 +03:00
|
|
|
|
2023-04-13 19:10:38 +03:00
|
|
|
nativeQueryArgumentsSchema ::
|
2023-01-19 14:25:52 +03:00
|
|
|
forall b r m n.
|
2023-05-24 16:51:56 +03:00
|
|
|
(MonadBuildSchema b r m n) =>
|
2023-01-19 14:25:52 +03:00
|
|
|
G.Name ->
|
2023-05-02 15:54:30 +03:00
|
|
|
HashMap ArgumentName (NullableScalarType b) ->
|
|
|
|
MaybeT (SchemaT r m) (P.InputFieldsParser n (HashMap ArgumentName (Column.ColumnValue b)))
|
2023-05-03 12:59:21 +03:00
|
|
|
nativeQueryArgumentsSchema = argumentsSchema "Native Query"
|
2023-05-10 18:13:56 +03:00
|
|
|
|
|
|
|
-- | swap the template names in our query for unprepared values
|
|
|
|
interpolatedQuery ::
|
|
|
|
InterpolatedQuery ArgumentName ->
|
|
|
|
HashMap ArgumentName (Column.ColumnValue b) ->
|
|
|
|
InterpolatedQuery (UnpreparedValue b)
|
|
|
|
interpolatedQuery nqiCode nqArgs =
|
2023-05-24 16:51:56 +03:00
|
|
|
InterpolatedQuery
|
|
|
|
$ (fmap . fmap)
|
2023-05-31 18:41:24 +03:00
|
|
|
( \var -> case HashMap.lookup var nqArgs of
|
|
|
|
Just arg -> UVParameter FreshVar arg
|
2023-05-10 18:13:56 +03:00
|
|
|
Nothing ->
|
|
|
|
-- the `nativeQueryArgsParser` will already have checked
|
|
|
|
-- we have all the args the query needs so this _should
|
|
|
|
-- not_ happen
|
|
|
|
error $ "No native query arg passed for " <> show var
|
|
|
|
)
|
|
|
|
(getInterpolatedQuery nqiCode)
|
2023-07-04 20:19:44 +03:00
|
|
|
|
|
|
|
-- these functions become specific to the suppliers of the types
|
|
|
|
-- again, as they must
|
|
|
|
-- a) get the field parsers for the Logical Model
|
|
|
|
-- b) add any parsers for relationships etc
|
|
|
|
nativeQuerySelectionSet ::
|
|
|
|
forall b r m n.
|
|
|
|
( MonadBuildSchema b r m n,
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendNativeQuerySelectSchema b,
|
|
|
|
BackendTableSelectSchema b
|
2023-07-04 20:19:44 +03:00
|
|
|
) =>
|
|
|
|
NativeQueryInfo b ->
|
|
|
|
SchemaT r m (Maybe (P.Parser 'P.Output n (AnnotatedFields b)))
|
|
|
|
nativeQuerySelectionSet nativeQuery = runMaybeT do
|
|
|
|
let logicalModel = _nqiReturns nativeQuery
|
|
|
|
description = G.Description <$> _lmiDescription logicalModel
|
|
|
|
|
|
|
|
-- what name shall we call the selection set? (and thus, it's type in GraphQL
|
|
|
|
-- schema?)
|
|
|
|
let typeName = getNativeQueryName (_nqiRootFieldName nativeQuery)
|
|
|
|
|
|
|
|
-- What interfaces does this type implement?
|
|
|
|
let implementsInterfaces = []
|
|
|
|
|
|
|
|
lift $ P.memoizeOn 'nativeQuerySelectionSet typeName do
|
|
|
|
-- list of relationship names to allow as Logimo fields
|
|
|
|
let knownRelNames = S.fromList $ InsOrdHashMap.keys $ _nqiRelationships nativeQuery
|
|
|
|
|
|
|
|
-- a pile 'o' parsers
|
|
|
|
logicalModelFields <- logicalModelFieldParsers knownRelNames logicalModel
|
|
|
|
|
|
|
|
relationshipFields <- catMaybes <$> traverse nativeQueryRelationshipField (InsOrdHashMap.elems $ _nqiRelationships nativeQuery)
|
|
|
|
|
|
|
|
let parsers = relationshipFields <> logicalModelFields
|
|
|
|
|
|
|
|
pure
|
|
|
|
$ P.selectionSetObject typeName description parsers implementsInterfaces
|
|
|
|
<&> parsedSelectionsToFields IR.AFExpression
|
|
|
|
|
|
|
|
-- | Field parsers for a logical model object relationship
|
|
|
|
nativeQueryRelationshipField ::
|
|
|
|
forall b r m n.
|
|
|
|
( BackendNativeQuerySelectSchema b,
|
2023-08-10 17:21:34 +03:00
|
|
|
BackendTableSelectSchema b,
|
2023-07-04 20:19:44 +03:00
|
|
|
MonadBuildSchema b r m n
|
|
|
|
) =>
|
|
|
|
RelInfo b ->
|
|
|
|
SchemaT r m (Maybe (P.FieldParser n (AnnotatedField b)))
|
|
|
|
nativeQueryRelationshipField ri | riType ri == ObjRel = runMaybeT do
|
2023-08-10 17:21:34 +03:00
|
|
|
relFieldName <- lift $ textToName $ relNameToTxt $ riName ri
|
|
|
|
|
2023-07-04 20:19:44 +03:00
|
|
|
case riTarget ri of
|
|
|
|
RelTargetNativeQuery nativeQueryName -> do
|
|
|
|
nativeQueryInfo <- askNativeQueryInfo nativeQueryName
|
|
|
|
|
|
|
|
let objectRelDesc = Just $ G.Description "An object relationship"
|
|
|
|
|
|
|
|
nativeQueryParser <-
|
|
|
|
MaybeT $ selectNativeQueryObject nativeQueryInfo relFieldName objectRelDesc
|
|
|
|
|
|
|
|
-- this only affects the generated GraphQL type
|
|
|
|
let nullability = Nullable
|
|
|
|
|
|
|
|
pure
|
|
|
|
$ nativeQueryParser
|
|
|
|
<&> \selectExp ->
|
|
|
|
IR.AFObjectRelation (IR.AnnRelationSelectG (riName ri) (riMapping ri) nullability selectExp)
|
2023-08-10 17:21:34 +03:00
|
|
|
RelTargetTable otherTableName -> do
|
|
|
|
let desc = Just $ G.Description "An object relationship"
|
|
|
|
roleName <- retrieve scRole
|
|
|
|
otherTableInfo <- lift $ askTableInfo otherTableName
|
|
|
|
remotePerms <- hoistMaybe $ tableSelectPermissions roleName otherTableInfo
|
|
|
|
selectionSetParser <- MaybeT $ tableSelectionSet otherTableInfo
|
|
|
|
pure
|
|
|
|
$ P.subselection_ relFieldName desc selectionSetParser
|
|
|
|
<&> \fields ->
|
|
|
|
IR.AFObjectRelation
|
|
|
|
$ IR.AnnRelationSelectG (riName ri) (riMapping ri) Nullable
|
|
|
|
$ IR.AnnObjectSelectG fields (IR.FromTable otherTableName)
|
|
|
|
$ IR._tpFilter
|
|
|
|
$ tablePermissionsInfo remotePerms
|
2023-08-14 15:33:50 +03:00
|
|
|
nativeQueryRelationshipField ri = do
|
|
|
|
relFieldName <- lift $ textToName $ relNameToTxt $ riName ri
|
2023-07-04 20:19:44 +03:00
|
|
|
case riTarget ri of
|
2023-08-14 15:33:50 +03:00
|
|
|
RelTargetNativeQuery nativeQueryName -> runMaybeT $ do
|
2023-07-04 20:19:44 +03:00
|
|
|
nativeQueryInfo <- askNativeQueryInfo nativeQueryName
|
|
|
|
|
|
|
|
let objectRelDesc = Just $ G.Description "An array relationship"
|
|
|
|
arrayNullability = Nullable
|
|
|
|
innerNullability = Nullable
|
|
|
|
|
|
|
|
nativeQueryParser <-
|
|
|
|
MaybeT $ selectNativeQuery nativeQueryInfo relFieldName arrayNullability objectRelDesc
|
2023-08-14 15:33:50 +03:00
|
|
|
|
2023-07-04 20:19:44 +03:00
|
|
|
pure
|
|
|
|
$ nativeQueryParser
|
|
|
|
<&> \selectExp ->
|
|
|
|
IR.AFArrayRelation
|
|
|
|
$ IR.ASSimple
|
|
|
|
$ IR.AnnRelationSelectG (riName ri) (riMapping ri) innerNullability selectExp
|
2023-08-14 15:33:50 +03:00
|
|
|
RelTargetTable otherTableName -> runMaybeT $ do
|
|
|
|
let arrayRelDesc = Just $ G.Description "An array relationship"
|
|
|
|
|
|
|
|
otherTableInfo <- lift $ askTableInfo otherTableName
|
|
|
|
otherTableParser <- MaybeT $ selectTable otherTableInfo relFieldName arrayRelDesc
|
|
|
|
let arrayRelField =
|
|
|
|
otherTableParser <&> \selectExp ->
|
|
|
|
IR.AFArrayRelation
|
|
|
|
$ IR.ASSimple
|
|
|
|
$ IR.AnnRelationSelectG (riName ri) (riMapping ri) Nullable
|
|
|
|
$ selectExp
|
|
|
|
pure arrayRelField
|