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