2021-02-23 20:37:27 +03:00
|
|
|
-- | Postgres-specific schema combinators. Those should be moved to
|
|
|
|
-- the corresponding instance of `BackendSchema`, when actions are
|
|
|
|
-- generalized.
|
2020-12-01 18:50:18 +03:00
|
|
|
module Hasura.GraphQL.Schema.Postgres
|
2021-02-23 20:37:27 +03:00
|
|
|
( buildActionQueryFields,
|
2021-02-14 09:07:52 +03:00
|
|
|
buildActionSubscriptionFields,
|
|
|
|
buildActionMutationFields,
|
2020-12-01 18:50:18 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
import Hasura.GraphQL.Schema.Action
|
2022-09-06 19:48:04 +03:00
|
|
|
import Hasura.GraphQL.Schema.Common
|
2022-09-06 17:18:30 +03:00
|
|
|
import Hasura.GraphQL.Schema.Parser
|
2020-12-01 18:50:18 +03:00
|
|
|
import Hasura.Prelude
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.RQL.IR
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Action
|
|
|
|
import Hasura.RQL.Types.CustomTypes
|
2022-09-06 17:18:30 +03:00
|
|
|
import Hasura.RQL.Types.Metadata.Object
|
2020-12-01 18:50:18 +03:00
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
buildActionQueryFields ::
|
2023-05-24 16:51:56 +03:00
|
|
|
(MonadBuildActionSchema r m n) =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionQueryFields customTypes actionInfo =
|
2023-05-24 16:51:56 +03:00
|
|
|
maybeToList
|
|
|
|
. applyActionOrigin actionInfo
|
2022-09-06 17:18:30 +03:00
|
|
|
<$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery ->
|
|
|
|
fmap (fmap (RFAction . AQQuery)) <$> actionExecute customTypes actionInfo
|
|
|
|
ActionMutation ActionSynchronous -> pure Nothing
|
|
|
|
ActionMutation ActionAsynchronous ->
|
|
|
|
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjectTypes customTypes) actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionMutationFields ::
|
2023-05-24 16:51:56 +03:00
|
|
|
(MonadBuildActionSchema r m n) =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (MutationRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionMutationFields customTypes actionInfo =
|
2023-05-24 16:51:56 +03:00
|
|
|
maybeToList
|
|
|
|
. applyActionOrigin actionInfo
|
2022-09-06 17:18:30 +03:00
|
|
|
<$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery -> pure Nothing
|
|
|
|
ActionMutation ActionSynchronous ->
|
|
|
|
fmap (fmap (RFAction . AMSync)) <$> actionExecute customTypes actionInfo
|
|
|
|
ActionMutation ActionAsynchronous ->
|
|
|
|
fmap (fmap (RFAction . AMAsync)) <$> actionAsyncMutation (_actInputTypes customTypes) actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionSubscriptionFields ::
|
2023-05-24 16:51:56 +03:00
|
|
|
(MonadBuildActionSchema r m n) =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionSubscriptionFields customTypes actionInfo =
|
2023-05-24 16:51:56 +03:00
|
|
|
maybeToList
|
|
|
|
. applyActionOrigin actionInfo
|
2022-09-06 17:18:30 +03:00
|
|
|
<$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery -> pure Nothing
|
|
|
|
ActionMutation ActionSynchronous -> pure Nothing
|
|
|
|
ActionMutation ActionAsynchronous ->
|
|
|
|
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjectTypes customTypes) actionInfo
|
|
|
|
|
|
|
|
applyActionOrigin ::
|
|
|
|
ActionInfo ->
|
|
|
|
Maybe (FieldParser n a) ->
|
|
|
|
Maybe (FieldParser n a)
|
|
|
|
applyActionOrigin actionInfo = fmap (setFieldParserOrigin (MOAction (_aiName actionInfo)))
|