graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hasura.GraphQL.Execute.Backend

Synopsis

Documentation

class (Backend b, ToTxt (MultiplexedQuery b), Show (ResolvedConnectionTemplate b), Eq (ResolvedConnectionTemplate b), Hashable (ResolvedConnectionTemplate b)) => BackendExecute (b :: BackendType) where Source #

This typeclass enacapsulates how a given backend translates a root field into an execution plan. For now, each root field maps to one execution step, but in the future, when we have a client-side dataloader, each root field might translate into a multi-step plan.

Associated Types

type PreparedQuery b :: Type Source #

type MultiplexedQuery b :: Type Source #

type ExecutionMonad b :: (Type -> Type) -> Type -> Type Source #

Methods

mkDBQueryPlan :: forall m. (MonadError QErr m, MonadQueryTags m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig b -> QueryDB b Void (UnpreparedValue b) -> [Header] -> Maybe Name -> m (DBStepInfo b) Source #

mkDBMutationPlan :: forall m. (MonadError QErr m, MonadIO m, MonadQueryTags m, MonadReader QueryTagsComment m, MonadTrace m) => Environment -> Manager -> Logger Hasura -> UserInfo -> StringifyNumbers -> SourceName -> SourceConfig b -> MutationDB b Void (UnpreparedValue b) -> [Header] -> Maybe Name -> Maybe (HashMap Name (Value Variable)) -> m (DBStepInfo b) Source #

mkLiveQuerySubscriptionPlan :: forall m. (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig b -> Maybe Name -> RootFieldMap (QueryDB b Void (UnpreparedValue b)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan b (MultiplexedQuery b)) Source #

mkDBStreamingSubscriptionPlan :: forall m. (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig b -> (RootFieldAlias, QueryDB b Void (UnpreparedValue b)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan b (MultiplexedQuery b)) Source #

mkDBQueryExplain :: forall m. MonadError QErr m => RootFieldAlias -> UserInfo -> SourceName -> SourceConfig b -> QueryDB b Void (UnpreparedValue b) -> [Header] -> Maybe Name -> m (AnyBackend DBStepInfo) Source #

mkSubscriptionExplain :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m) => SubscriptionQueryPlan b (MultiplexedQuery b) -> m SubscriptionQueryPlanExplanation Source #

mkDBRemoteRelationshipPlan Source #

Arguments

:: forall m. (MonadError QErr m, MonadQueryTags m) 
=> UserInfo 
-> SourceName 
-> SourceConfig b 
-> NonEmpty Object

List of json objects, each of which becomes a row of the table.

-> HashMap FieldName (Column b, ScalarType b)

The above objects have this schema.

-> FieldName

This is a field name from the lhs that *has* to be selected in the response along with the relationship. It is populated in processRemoteJoins_ and the function convertRemoteSourceRelationship below assumes it to be returned as either a number or a string with a number in it

-> (FieldName, SourceRelationshipSelection b Void UnpreparedValue) 
-> [Header] 
-> Maybe Name 
-> StringifyNumbers 
-> m (DBStepInfo b) 

Instances

Instances details
BackendExecute 'BigQuery Source # 
Instance details

Defined in Hasura.Backends.BigQuery.Instances.Execute

Methods

mkDBQueryPlan :: (MonadError QErr m, MonadQueryTags m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'BigQuery -> QueryDB 'BigQuery Void (UnpreparedValue 'BigQuery) -> [Header] -> Maybe Name -> m (DBStepInfo 'BigQuery) Source #

mkDBMutationPlan :: (MonadError QErr m, MonadIO m, MonadQueryTags m, MonadReader QueryTagsComment m, MonadTrace m) => Environment -> Manager -> Logger Hasura -> UserInfo -> StringifyNumbers -> SourceName -> SourceConfig 'BigQuery -> MutationDB 'BigQuery Void (UnpreparedValue 'BigQuery) -> [Header] -> Maybe Name -> Maybe (HashMap Name (Value Variable)) -> m (DBStepInfo 'BigQuery) Source #

mkLiveQuerySubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'BigQuery -> Maybe Name -> RootFieldMap (QueryDB 'BigQuery Void (UnpreparedValue 'BigQuery)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'BigQuery (MultiplexedQuery 'BigQuery)) Source #

mkDBStreamingSubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'BigQuery -> (RootFieldAlias, QueryDB 'BigQuery Void (UnpreparedValue 'BigQuery)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'BigQuery (MultiplexedQuery 'BigQuery)) Source #

mkDBQueryExplain :: MonadError QErr m => RootFieldAlias -> UserInfo -> SourceName -> SourceConfig 'BigQuery -> QueryDB 'BigQuery Void (UnpreparedValue 'BigQuery) -> [Header] -> Maybe Name -> m (AnyBackend DBStepInfo) Source #

mkSubscriptionExplain :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m) => SubscriptionQueryPlan 'BigQuery (MultiplexedQuery 'BigQuery) -> m SubscriptionQueryPlanExplanation Source #

mkDBRemoteRelationshipPlan :: (MonadError QErr m, MonadQueryTags m) => UserInfo -> SourceName -> SourceConfig 'BigQuery -> NonEmpty Object -> HashMap FieldName (Column 'BigQuery, ScalarType 'BigQuery) -> FieldName -> (FieldName, SourceRelationshipSelection 'BigQuery Void UnpreparedValue) -> [Header] -> Maybe Name -> StringifyNumbers -> m (DBStepInfo 'BigQuery) Source #

BackendExecute 'DataConnector Source # 
Instance details

Defined in Hasura.Backends.DataConnector.Adapter.Execute

Methods

mkDBQueryPlan :: (MonadError QErr m, MonadQueryTags m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'DataConnector -> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector) -> [Header] -> Maybe Name -> m (DBStepInfo 'DataConnector) Source #

mkDBMutationPlan :: (MonadError QErr m, MonadIO m, MonadQueryTags m, MonadReader QueryTagsComment m, MonadTrace m) => Environment -> Manager -> Logger Hasura -> UserInfo -> StringifyNumbers -> SourceName -> SourceConfig 'DataConnector -> MutationDB 'DataConnector Void (UnpreparedValue 'DataConnector) -> [Header] -> Maybe Name -> Maybe (HashMap Name (Value Variable)) -> m (DBStepInfo 'DataConnector) Source #

mkLiveQuerySubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'DataConnector -> Maybe Name -> RootFieldMap (QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'DataConnector (MultiplexedQuery 'DataConnector)) Source #

mkDBStreamingSubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'DataConnector -> (RootFieldAlias, QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'DataConnector (MultiplexedQuery 'DataConnector)) Source #

mkDBQueryExplain :: MonadError QErr m => RootFieldAlias -> UserInfo -> SourceName -> SourceConfig 'DataConnector -> QueryDB 'DataConnector Void (UnpreparedValue 'DataConnector) -> [Header] -> Maybe Name -> m (AnyBackend DBStepInfo) Source #

mkSubscriptionExplain :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m) => SubscriptionQueryPlan 'DataConnector (MultiplexedQuery 'DataConnector) -> m SubscriptionQueryPlanExplanation Source #

mkDBRemoteRelationshipPlan :: (MonadError QErr m, MonadQueryTags m) => UserInfo -> SourceName -> SourceConfig 'DataConnector -> NonEmpty Object -> HashMap FieldName (Column 'DataConnector, ScalarType 'DataConnector) -> FieldName -> (FieldName, SourceRelationshipSelection 'DataConnector Void UnpreparedValue) -> [Header] -> Maybe Name -> StringifyNumbers -> m (DBStepInfo 'DataConnector) Source #

BackendExecute 'MSSQL Source # 
Instance details

Defined in Hasura.Backends.MSSQL.Instances.Execute

Methods

mkDBQueryPlan :: (MonadError QErr m, MonadQueryTags m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'MSSQL -> QueryDB 'MSSQL Void (UnpreparedValue 'MSSQL) -> [Header] -> Maybe Name -> m (DBStepInfo 'MSSQL) Source #

mkDBMutationPlan :: (MonadError QErr m, MonadIO m, MonadQueryTags m, MonadReader QueryTagsComment m, MonadTrace m) => Environment -> Manager -> Logger Hasura -> UserInfo -> StringifyNumbers -> SourceName -> SourceConfig 'MSSQL -> MutationDB 'MSSQL Void (UnpreparedValue 'MSSQL) -> [Header] -> Maybe Name -> Maybe (HashMap Name (Value Variable)) -> m (DBStepInfo 'MSSQL) Source #

mkLiveQuerySubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'MSSQL -> Maybe Name -> RootFieldMap (QueryDB 'MSSQL Void (UnpreparedValue 'MSSQL)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'MSSQL (MultiplexedQuery 'MSSQL)) Source #

mkDBStreamingSubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig 'MSSQL -> (RootFieldAlias, QueryDB 'MSSQL Void (UnpreparedValue 'MSSQL)) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan 'MSSQL (MultiplexedQuery 'MSSQL)) Source #

mkDBQueryExplain :: MonadError QErr m => RootFieldAlias -> UserInfo -> SourceName -> SourceConfig 'MSSQL -> QueryDB 'MSSQL Void (UnpreparedValue 'MSSQL) -> [Header] -> Maybe Name -> m (AnyBackend DBStepInfo) Source #

mkSubscriptionExplain :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m) => SubscriptionQueryPlan 'MSSQL (MultiplexedQuery 'MSSQL) -> m SubscriptionQueryPlanExplanation Source #

mkDBRemoteRelationshipPlan :: (MonadError QErr m, MonadQueryTags m) => UserInfo -> SourceName -> SourceConfig 'MSSQL -> NonEmpty Object -> HashMap FieldName (Column 'MSSQL, ScalarType 'MSSQL) -> FieldName -> (FieldName, SourceRelationshipSelection 'MSSQL Void UnpreparedValue) -> [Header] -> Maybe Name -> StringifyNumbers -> m (DBStepInfo 'MSSQL) Source #

(Backend ('Postgres pgKind), PostgresAnnotatedFieldJSON pgKind) => BackendExecute ('Postgres pgKind) Source # 
Instance details

Defined in Hasura.Backends.Postgres.Instances.Execute

Associated Types

type PreparedQuery ('Postgres pgKind) Source #

type MultiplexedQuery ('Postgres pgKind) Source #

type ExecutionMonad ('Postgres pgKind) :: (Type -> Type) -> Type -> Type Source #

Methods

mkDBQueryPlan :: (MonadError QErr m, MonadQueryTags m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig ('Postgres pgKind) -> QueryDB ('Postgres pgKind) Void (UnpreparedValue ('Postgres pgKind)) -> [Header] -> Maybe Name -> m (DBStepInfo ('Postgres pgKind)) Source #

mkDBMutationPlan :: (MonadError QErr m, MonadIO m, MonadQueryTags m, MonadReader QueryTagsComment m, MonadTrace m) => Environment -> Manager -> Logger Hasura -> UserInfo -> StringifyNumbers -> SourceName -> SourceConfig ('Postgres pgKind) -> MutationDB ('Postgres pgKind) Void (UnpreparedValue ('Postgres pgKind)) -> [Header] -> Maybe Name -> Maybe (HashMap Name (Value Variable)) -> m (DBStepInfo ('Postgres pgKind)) Source #

mkLiveQuerySubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig ('Postgres pgKind) -> Maybe Name -> RootFieldMap (QueryDB ('Postgres pgKind) Void (UnpreparedValue ('Postgres pgKind))) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan ('Postgres pgKind) (MultiplexedQuery ('Postgres pgKind))) Source #

mkDBStreamingSubscriptionPlan :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m, MonadReader QueryTagsComment m) => UserInfo -> SourceName -> SourceConfig ('Postgres pgKind) -> (RootFieldAlias, QueryDB ('Postgres pgKind) Void (UnpreparedValue ('Postgres pgKind))) -> [Header] -> Maybe Name -> m (SubscriptionQueryPlan ('Postgres pgKind) (MultiplexedQuery ('Postgres pgKind))) Source #

mkDBQueryExplain :: MonadError QErr m => RootFieldAlias -> UserInfo -> SourceName -> SourceConfig ('Postgres pgKind) -> QueryDB ('Postgres pgKind) Void (UnpreparedValue ('Postgres pgKind)) -> [Header] -> Maybe Name -> m (AnyBackend DBStepInfo) Source #

mkSubscriptionExplain :: (MonadError QErr m, MonadIO m, MonadBaseControl IO m) => SubscriptionQueryPlan ('Postgres pgKind) (MultiplexedQuery ('Postgres pgKind)) -> m SubscriptionQueryPlanExplanation Source #

mkDBRemoteRelationshipPlan :: (MonadError QErr m, MonadQueryTags m) => UserInfo -> SourceName -> SourceConfig ('Postgres pgKind) -> NonEmpty Object -> HashMap FieldName (Column ('Postgres pgKind), ScalarType ('Postgres pgKind)) -> FieldName -> (FieldName, SourceRelationshipSelection ('Postgres pgKind) Void UnpreparedValue) -> [Header] -> Maybe Name -> StringifyNumbers -> m (DBStepInfo ('Postgres pgKind)) Source #

convertRemoteSourceRelationship Source #

Arguments

:: forall b. Backend b 
=> HashMap (Column b) (Column b)

Join columns for the relationship

-> SelectFromG b (UnpreparedValue b)

The LHS of the join, this is the expression which selects from json objects

-> Column b

This is the argument id column, that needs to be added to the response This is used by by the remote joins processing logic to convert the response from upstream to join indices

-> ColumnType b

This is the type of the argument id column

-> (FieldName, SourceRelationshipSelection b Void UnpreparedValue)

The relationship column and its name (how it should be selected in the response)

-> StringifyNumbers 
-> QueryDB b Void (UnpreparedValue b) 

This is a helper function to convert a remote source's relationship to a normal relationship to a temporary table. This function can be used to implement executeRemoteRelationship function in databases which support constructing a temporary table for a list of json objects.

withNoStatistics :: EncJSON -> ActionResult b Source #

Lift a result from the database into an ActionResult.

newtype OnBaseMonad t a Source #

Provides an abstraction over the base monad in which a computation runs.

Given a transformer t and a type a, OnBaseMonad t a represents a computation of type t m a, for any base monad m. This allows DBStepInfo to store a backend-specific computation, using a backend-specific monad transformer, on top of the base app monad, without DBStepInfo needing to know about the base monad m.

However, this kind of type erasure forces us to bundle all of the constraints on the base monad m here. The constraints here are the union of the constraints required across all backends. If it were possible to express constraint functions of the form (Type -> Type) -> Constraint at the type level, we could make the list of constraints a type family in BackendExecute, allowing each backend to specify its own specific constraints; and we could then provide the list of constraints as an additional argument to OnBaseMonad, pushing the requirement to implement the union of all constraints to the base execution functions.

All backends require MonadError QErr to report errors, and MonadIO to be able to communicate over the network. Most of them require MonadTrace to be able to create new spans as part of the execution, and several use MonadBaseControl IO to use try in their error handling.

Constructors

OnBaseMonad 

Fields

Instances

Instances details
Functor (OnBaseMonad t) Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

Methods

fmap :: (a -> b) -> OnBaseMonad t a -> OnBaseMonad t b #

(<$) :: a -> OnBaseMonad t b -> OnBaseMonad t a #

data ExplainPlan Source #

The result of an explain query: for a given root field (denoted by its name): the generated SQL query, and the detailed explanation obtained from the database (if any). We mostly use this type as an intermediary step, and immediately tranform any value we obtain into an equivalent JSON representation.

Constructors

ExplainPlan 

Instances

Instances details
ToJSON ExplainPlan Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

Generic ExplainPlan Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

Associated Types

type Rep ExplainPlan :: Type -> Type #

Show ExplainPlan Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

Eq ExplainPlan Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

type Rep ExplainPlan Source # 
Instance details

Defined in Hasura.GraphQL.Execute.Backend

type Rep ExplainPlan = D1 ('MetaData "ExplainPlan" "Hasura.GraphQL.Execute.Backend" "graphql-engine-1.0.0-inplace" 'False) (C1 ('MetaCons "ExplainPlan" 'PrefixI 'True) (S1 ('MetaSel ('Just "_fpField") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RootFieldAlias) :*: (S1 ('MetaSel ('Just "_fpSql") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "_fpPlan") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe [Text])))))

data ExecutionStep where Source #

One execution step to processing a GraphQL query (e.g. one root field).

Constructors

ExecStepDB :: ResponseHeaders -> AnyBackend DBStepInfo -> Maybe RemoteJoins -> ExecutionStep

A query to execute against the database

ExecStepAction :: ActionExecutionPlan -> ActionsInfo -> Maybe RemoteJoins -> ExecutionStep

Execute an action

ExecStepRemote :: !RemoteSchemaInfo -> !ResultCustomizer -> !GQLReqOutgoing -> Maybe RemoteJoins -> ExecutionStep

A graphql query to execute against a remote schema

ExecStepRaw :: Value -> ExecutionStep

Output a plain JSON object

ExecStepMulti :: [ExecutionStep] -> ExecutionStep 

type ExecutionPlan = RootFieldMap ExecutionStep Source #

The series of steps that need to be executed for a given query. For now, those steps are all independent. In the future, when we implement a client-side dataloader and generalized joins, this will need to be changed into an annotated tree.