Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Execution of GraphQL queries over HTTP transport
Synopsis
- newtype ResponseCacher = ResponseCacher {
- runStoreResponse :: forall m. (MonadTrace m, MonadIO m) => EncJSON -> m (Either QErr CacheStoreResponse)
- data CacheStoreResponse
- data CacheResult
- class Monad m => MonadExecuteQuery m where
- cacheLookup :: ExecutionPlan -> [QueryRootField UnpreparedValue] -> Maybe CachedDirective -> GQLReqParsed -> UserInfo -> [Header] -> m (Either QErr (ResponseHeaders, CacheResult))
- data AnnotatedResponsePart = AnnotatedResponsePart {}
- data SessVarPred
- runSessVarPred :: SessVarPred -> SessionVariables -> SessionVariables
- filterVariablesFromQuery :: [RootField (QueryDBRoot (RemoteRelationshipField UnpreparedValue) UnpreparedValue) (RemoteSchemaRootField (RemoteRelationshipField UnpreparedValue) RemoteSchemaVariable) (ActionQuery (RemoteRelationshipField UnpreparedValue)) d] -> SessVarPred
- runGQ :: forall m. (MonadIO m, MonadBaseControl IO m, MonadError QErr m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadExecutionLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage m, MonadQueryTags m, HasResourceLimits m, ProvidesNetwork m) => Environment -> SQLGenCtx -> SchemaCache -> AllowListStatus -> ReadOnlyMode -> PrometheusMetrics -> Logger Hasura -> Maybe (CredentialCache AgentLicenseKey) -> RequestId -> UserInfo -> IpAddress -> [Header] -> GraphQLQueryType -> GQLReqUnparsed -> m (GQLQueryOperationSuccessLog, HttpResponse (Maybe GQResponse, EncJSON))
- coalescePostgresMutations :: ExecutionPlan -> Maybe (SourceConfig ('Postgres 'Vanilla), ResolvedConnectionTemplate ('Postgres 'Vanilla), InsOrdHashMap RootFieldAlias (DBStepInfo ('Postgres 'Vanilla)))
- extractFieldFromResponse :: forall m. Monad m => RootFieldAlias -> ResultCustomizer -> ByteString -> ExceptT (Either GQExecError QErr) m Value
- buildRaw :: Applicative m => Value -> m AnnotatedResponsePart
- encodeAnnotatedResponseParts :: RootFieldMap AnnotatedResponsePart -> EncJSON
- encodeEncJSONResults :: RootFieldMap EncJSON -> EncJSON
- runGQBatched :: forall m. (MonadIO m, MonadBaseControl IO m, MonadError QErr m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadExecutionLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage m, MonadQueryTags m, HasResourceLimits m, ProvidesNetwork m) => Environment -> SQLGenCtx -> SchemaCache -> AllowListStatus -> ReadOnlyMode -> PrometheusMetrics -> Logger Hasura -> Maybe (CredentialCache AgentLicenseKey) -> RequestId -> ResponseInternalErrorsConfig -> UserInfo -> IpAddress -> [Header] -> GraphQLQueryType -> GQLBatchedReqs (GQLReq GQLQueryText) -> m (HttpLogGraphQLInfo, HttpResponse EncJSON)
Documentation
newtype ResponseCacher Source #
Encapsulates a function that stores a query response in the cache.
cacheLookup
decides when such an invitation to store is generated.
ResponseCacher | |
|
data CacheStoreResponse Source #
CacheStoreSuccess | Cache storage is unconditional, just not always available. |
CacheStoreLimitReached | |
CacheStoreNotEnoughCapacity | |
CacheStoreBackendError String |
data CacheResult Source #
ResponseCached EncJSON | We have a cached response for this query |
ResponseUncached (Maybe ResponseCacher) | We don't have a cached response. The |
class Monad m => MonadExecuteQuery m where Source #
Nothing
:: ExecutionPlan | How we _would've_ executed the query. Ideally we'd use this as a caching key, but it's not serializable... [cont'd] |
-> [QueryRootField UnpreparedValue] | Somewhat less processed plan of how we _would've_ executed the query. |
-> Maybe CachedDirective | `@cached` directive from the query AST |
-> GQLReqParsed |
|
-> UserInfo | ... and the |
-> [Header] | Used for remote schemas and actions |
-> m (Either QErr (ResponseHeaders, CacheResult)) | Non-empty response headers instruct the client to store the response locally. |
This method does two things: it looks up a query result in the server-side cache, if a cache is used, and it additionally returns HTTP headers that can instruct a client how long a response can be cached locally (i.e. client-side).
default cacheLookup :: (m ~ t n, MonadTrans t, MonadExecuteQuery n) => ExecutionPlan -> [QueryRootField UnpreparedValue] -> Maybe CachedDirective -> GQLReqParsed -> UserInfo -> [Header] -> m (Either QErr (ResponseHeaders, CacheResult)) Source #
Instances
data AnnotatedResponsePart Source #
A partial response, e.g. from a remote schema call or postgres postgres query, which we'll assemble into the final response for the client. It is annotated with timing metadata.
data SessVarPred Source #
A predicate on session variables. The Monoid
instance makes it simple
to combine several predicates disjunctively.
| The definition includes Maybe
which allows us to short-circuit calls like mempty <> m
and m <> mempty
, which
otherwise might build up long repeated chains of calls to _ _ -> False
.
Instances
Monoid SessVarPred Source # | |
Defined in Hasura.GraphQL.Transport.HTTP mempty :: SessVarPred # mappend :: SessVarPred -> SessVarPred -> SessVarPred # mconcat :: [SessVarPred] -> SessVarPred # | |
Semigroup SessVarPred Source # | |
Defined in Hasura.GraphQL.Transport.HTTP (<>) :: SessVarPred -> SessVarPred -> SessVarPred # sconcat :: NonEmpty SessVarPred -> SessVarPred # stimes :: Integral b => b -> SessVarPred -> SessVarPred # |
filterVariablesFromQuery :: [RootField (QueryDBRoot (RemoteRelationshipField UnpreparedValue) UnpreparedValue) (RemoteSchemaRootField (RemoteRelationshipField UnpreparedValue) RemoteSchemaVariable) (ActionQuery (RemoteRelationshipField UnpreparedValue)) d] -> SessVarPred Source #
Filter out only those session variables used by the query AST provided
runGQ :: forall m. (MonadIO m, MonadBaseControl IO m, MonadError QErr m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadExecutionLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage m, MonadQueryTags m, HasResourceLimits m, ProvidesNetwork m) => Environment -> SQLGenCtx -> SchemaCache -> AllowListStatus -> ReadOnlyMode -> PrometheusMetrics -> Logger Hasura -> Maybe (CredentialCache AgentLicenseKey) -> RequestId -> UserInfo -> IpAddress -> [Header] -> GraphQLQueryType -> GQLReqUnparsed -> m (GQLQueryOperationSuccessLog, HttpResponse (Maybe GQResponse, EncJSON)) Source #
Run (execute) a single GraphQL query
coalescePostgresMutations :: ExecutionPlan -> Maybe (SourceConfig ('Postgres 'Vanilla), ResolvedConnectionTemplate ('Postgres 'Vanilla), InsOrdHashMap RootFieldAlias (DBStepInfo ('Postgres 'Vanilla))) Source #
extractFieldFromResponse :: forall m. Monad m => RootFieldAlias -> ResultCustomizer -> ByteString -> ExceptT (Either GQExecError QErr) m Value Source #
buildRaw :: Applicative m => Value -> m AnnotatedResponsePart Source #
:: forall m. (MonadIO m, MonadBaseControl IO m, MonadError QErr m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadExecutionLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage m, MonadQueryTags m, HasResourceLimits m, ProvidesNetwork m) | |
=> Environment | |
-> SQLGenCtx | |
-> SchemaCache | |
-> AllowListStatus | |
-> ReadOnlyMode | |
-> PrometheusMetrics | |
-> Logger Hasura | |
-> Maybe (CredentialCache AgentLicenseKey) | |
-> RequestId | |
-> ResponseInternalErrorsConfig | |
-> UserInfo | |
-> IpAddress | |
-> [Header] | |
-> GraphQLQueryType | |
-> GQLBatchedReqs (GQLReq GQLQueryText) | the batched request with unparsed GraphQL query |
-> m (HttpLogGraphQLInfo, HttpResponse EncJSON) |
Run (execute) a batched GraphQL query (see GQLBatchedReqs
).