mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
512a4dbb92
### Description This PR changes all the schema code to operate in a specific `SchemaT` monad, rather than in an arbitrary `m` monad. `SchemaT` is intended to be used opaquely with `runSourceSchema` and `runRemoteSchema`. The main goal of this is to allow a different reader context per part of the schema: this PR also minimizes the contexts. This means that we no longer require `SchemaOptions` when building remote schemas' schema, and this PR therefore removes a lot of dummy / placeholder values accordingly. ### Performance and stacking This PR has been through several iterations. #5339 was the original version, that accomplished the same thing by stacking readers on top of the stack at every remote relationship boundary. This raised performance concerns, and @0x777 confirmed with an ad-hoc test that in some extreme cases we could see up to a 10% performance impact. This version, while more verbose, allows us to unstack / re-stack the readers, and avoid that problem. #5517 adds a new benchmark set to be able to automatically measure this on every PR. ### Remaining work - [x] a comment (or perhaps even a Note?) should be added to `SchemaT` - [x] we probably want for #5517 to be merged first so that we can confirm the lack of performance penalty PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5458 GitOrigin-RevId: e06b83d90da475f745b838f1fd8f8b4d9d3f4b10
68 lines
2.6 KiB
Haskell
68 lines
2.6 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.Common
|
|
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 ->
|
|
SchemaT r 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 ->
|
|
SchemaT r 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 ->
|
|
SchemaT r 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)))
|