mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 20:41:49 +03:00
6d84d1b78f
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5740 GitOrigin-RevId: 555de02a370b1dfa9cf5e903bb5c3f4b4c3e8465
67 lines
2.5 KiB
Haskell
67 lines
2.5 KiB
Haskell
-- | Postgres-specific schema combinators. Those should be moved to
|
|
-- the corresponding instance of `BackendSchema`, when actions are
|
|
-- generalized.
|
|
module Hasura.GraphQL.Schema.Postgres
|
|
( buildActionQueryFields,
|
|
buildActionSubscriptionFields,
|
|
buildActionMutationFields,
|
|
)
|
|
where
|
|
|
|
import Hasura.GraphQL.Schema.Action
|
|
import Hasura.GraphQL.Schema.Backend (MonadBuildSchema)
|
|
import Hasura.GraphQL.Schema.Parser
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.IR
|
|
import Hasura.RQL.Types.Action
|
|
import Hasura.RQL.Types.CustomTypes
|
|
import Hasura.RQL.Types.Metadata.Object
|
|
import Hasura.SQL.Backend
|
|
|
|
buildActionQueryFields ::
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
buildActionQueryFields customTypes actionInfo =
|
|
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
|
|
|
|
buildActionMutationFields ::
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
m [FieldParser n (MutationRootField UnpreparedValue)]
|
|
buildActionMutationFields customTypes actionInfo =
|
|
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
|
|
|
|
buildActionSubscriptionFields ::
|
|
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
buildActionSubscriptionFields customTypes actionInfo =
|
|
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)))
|