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
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
import Hasura.GraphQL.Context
|
2021-02-23 20:37:27 +03:00
|
|
|
import Hasura.GraphQL.Parser hiding (EnumValueInfo, field)
|
2021-02-03 19:17:20 +03:00
|
|
|
import Hasura.GraphQL.Schema.Action
|
2021-02-23 20:37:27 +03:00
|
|
|
import Hasura.GraphQL.Schema.Backend (MonadBuildSchema)
|
2020-12-01 18:50:18 +03:00
|
|
|
import Hasura.RQL.Types
|
2021-02-03 19:17:20 +03:00
|
|
|
|
2021-02-14 09:07:52 +03:00
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
buildActionQueryFields
|
|
|
|
:: MonadBuildSchema 'Postgres r m n
|
|
|
|
=> NonObjectTypeMap
|
2021-02-14 09:07:52 +03:00
|
|
|
-> ActionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
-> m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
|
|
buildActionQueryFields nonObjectCustomTypes actionInfo =
|
|
|
|
maybeToList <$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery ->
|
2021-02-09 22:29:12 +03:00
|
|
|
fmap (fmap (RFAction . AQQuery)) <$> actionExecute nonObjectCustomTypes actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
ActionMutation ActionSynchronous -> pure Nothing
|
|
|
|
ActionMutation ActionAsynchronous ->
|
2021-02-09 22:29:12 +03:00
|
|
|
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionMutationFields
|
|
|
|
:: MonadBuildSchema 'Postgres r m n
|
|
|
|
=> NonObjectTypeMap
|
2021-02-14 09:07:52 +03:00
|
|
|
-> ActionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
-> m [FieldParser n (MutationRootField UnpreparedValue)]
|
|
|
|
buildActionMutationFields nonObjectCustomTypes actionInfo =
|
|
|
|
maybeToList <$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery -> pure Nothing
|
|
|
|
ActionMutation ActionSynchronous ->
|
2021-02-09 22:29:12 +03:00
|
|
|
fmap (fmap (RFAction . AMSync)) <$> actionExecute nonObjectCustomTypes actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
ActionMutation ActionAsynchronous ->
|
2021-02-09 22:29:12 +03:00
|
|
|
fmap (fmap (RFAction . AMAsync)) <$> actionAsyncMutation nonObjectCustomTypes actionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionSubscriptionFields
|
|
|
|
:: MonadBuildSchema 'Postgres r m n
|
2021-02-14 09:07:52 +03:00
|
|
|
=> ActionInfo
|
2021-02-03 19:17:20 +03:00
|
|
|
-> m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
|
|
buildActionSubscriptionFields actionInfo =
|
|
|
|
maybeToList <$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery -> pure Nothing
|
|
|
|
ActionMutation ActionSynchronous -> pure Nothing
|
|
|
|
ActionMutation ActionAsynchronous ->
|
2021-02-09 22:29:12 +03:00
|
|
|
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery actionInfo
|