graphql-engine/server/src-lib/Hasura/GraphQL/Schema/Postgres.hs
paritosh-08 40678855d0 server: add support for nested object type in action
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2788
Co-authored-by: David Overton <7734777+dmoverton@users.noreply.github.com>
GitOrigin-RevId: f8ed9741e95b6864a48af7db338f3f619617483a
2021-12-15 23:52:43 +00:00

55 lines
2.1 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.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
buildActionQueryFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (QueryRootField UnpreparedValue)]
buildActionQueryFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery ->
fmap (fmap (RFAction . AQQuery)) <$> actionExecute customTypes actionInfo
ActionMutation ActionSynchronous -> pure Nothing
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjects customTypes) actionInfo
buildActionMutationFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (MutationRootField UnpreparedValue)]
buildActionMutationFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing
ActionMutation ActionSynchronous ->
fmap (fmap (RFAction . AMSync)) <$> actionExecute customTypes actionInfo
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AMAsync)) <$> actionAsyncMutation (_actNonObjects customTypes) actionInfo
buildActionSubscriptionFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (QueryRootField UnpreparedValue)]
buildActionSubscriptionFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing
ActionMutation ActionSynchronous -> pure Nothing
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjects customTypes) actionInfo