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-09-24 01:56:37 +03:00
|
|
|
( buildActionQueryFields,
|
|
|
|
buildActionSubscriptionFields,
|
|
|
|
buildActionMutationFields,
|
|
|
|
)
|
|
|
|
where
|
2020-12-01 18:50:18 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.Action
|
|
|
|
import Hasura.GraphQL.Schema.Backend (MonadBuildSchema)
|
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
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
|
|
|
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
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.SQL.Backend
|
2020-12-01 18:50:18 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
buildActionQueryFields ::
|
|
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-09-24 01:56:37 +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 =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> 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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
buildActionMutationFields ::
|
|
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-09-24 01:56:37 +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 =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> 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
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
buildActionSubscriptionFields ::
|
|
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-09-24 01:56:37 +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 =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> 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)))
|