Safe Haskell | None |
---|---|
Language | Haskell2010 |
Execution of GraphQL queries over HTTP transport
Synopsis
- data QueryCacheKey = QueryCacheKey {}
- type CacheStoreResponse = Either CacheStoreFailure CacheStoreSuccess
- data CacheStoreSuccess
- data CacheStoreFailure
- class Monad m => MonadExecuteQuery m where
- cacheLookup :: [RemoteSchemaInfo] -> [ActionsInfo] -> QueryCacheKey -> Maybe CachedDirective -> TraceT (ExceptT QErr m) (ResponseHeaders, Maybe EncJSON)
- cacheStore :: QueryCacheKey -> Maybe CachedDirective -> EncJSON -> TraceT (ExceptT QErr m) CacheStoreResponse
- data AnnotatedResponsePart = AnnotatedResponsePart {
- arpTimeIO :: DiffTime
- arpLocality :: Locality
- arpResponse :: EncJSON
- arpHeaders :: ResponseHeaders
- data AnnotatedResponse = AnnotatedResponse {}
- buildResponseFromParts :: MonadError QErr m => QueryType -> Either (Either GQExecError QErr) (RootFieldMap AnnotatedResponsePart) -> ResponseHeaders -> m AnnotatedResponse
- buildResponse :: MonadError QErr m => QueryType -> Either (Either GQExecError QErr) a -> (a -> AnnotatedResponse) -> m AnnotatedResponse
- newtype SessVarPred = SessVarPred {
- unSessVarPred :: Maybe (SessionVariable -> SessionVariableValue -> Bool)
- keepAllSessionVariables :: 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, MonadReader ExecutionCtx m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage (MetadataStorageT m), MonadQueryTags m, HasResourceLimits m) => Environment -> Logger Hasura -> RequestId -> UserInfo -> IpAddress -> [Header] -> GraphQLQueryType -> GQLReqUnparsed -> m (GQLQueryOperationSuccessLog, HttpResponse (Maybe GQResponse, EncJSON))
- coalescePostgresMutations :: ExecutionPlan -> Maybe (SourceConfig ('Postgres 'Vanilla), InsOrdHashMap RootFieldAlias (DBStepInfo ('Postgres 'Vanilla)))
- data GraphQLResponse
- = GraphQLResponseErrors [Value]
- | GraphQLResponseData Value
- decodeGraphQLResponse :: ByteString -> Either Text GraphQLResponse
- 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, MonadReader ExecutionCtx m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadTrace m, MonadExecuteQuery m, HttpLog m, MonadMetadataStorage (MetadataStorageT m), MonadQueryTags m, HasResourceLimits m) => Environment -> Logger Hasura -> RequestId -> ResponseInternalErrorsConfig -> UserInfo -> IpAddress -> [Header] -> GraphQLQueryType -> GQLBatchedReqs (GQLReq GQLQueryText) -> m (HttpLogMetadata m, HttpResponse EncJSON)
Documentation
data QueryCacheKey Source #
Instances
ToJSON QueryCacheKey Source # | |
Defined in Hasura.GraphQL.Transport.HTTP toJSON :: QueryCacheKey -> Value toEncoding :: QueryCacheKey -> Encoding toJSONList :: [QueryCacheKey] -> Value toEncodingList :: [QueryCacheKey] -> Encoding |
data CacheStoreSuccess Source #
Instances
Eq CacheStoreSuccess Source # | |
Defined in Hasura.GraphQL.Transport.HTTP (==) :: CacheStoreSuccess -> CacheStoreSuccess -> Bool # (/=) :: CacheStoreSuccess -> CacheStoreSuccess -> Bool # | |
Show CacheStoreSuccess Source # | |
Defined in Hasura.GraphQL.Transport.HTTP showsPrec :: Int -> CacheStoreSuccess -> ShowS # show :: CacheStoreSuccess -> String # showList :: [CacheStoreSuccess] -> ShowS # |
data CacheStoreFailure Source #
Instances
Eq CacheStoreFailure Source # | |
Defined in Hasura.GraphQL.Transport.HTTP (==) :: CacheStoreFailure -> CacheStoreFailure -> Bool # (/=) :: CacheStoreFailure -> CacheStoreFailure -> Bool # | |
Show CacheStoreFailure Source # | |
Defined in Hasura.GraphQL.Transport.HTTP showsPrec :: Int -> CacheStoreFailure -> ShowS # show :: CacheStoreFailure -> String # showList :: [CacheStoreFailure] -> ShowS # |
class Monad m => MonadExecuteQuery m where Source #
Nothing
:: [RemoteSchemaInfo] | Used to check if the elaborated query supports caching |
-> [ActionsInfo] | Used to check if actions query supports caching (unsupported if |
-> QueryCacheKey | Key that uniquely identifies the result of a query execution |
-> Maybe CachedDirective | Cached Directive from GraphQL query AST |
-> TraceT (ExceptT QErr m) (ResponseHeaders, Maybe EncJSON) | HTTP headers to be sent back to the caller for this GraphQL request, containing e.g. time-to-live information, and a cached value if found and within time-to-live. So a return value (non-empty-ttl-headers, Nothing) represents that we don't have a server-side cache of the query, but that the client should store it locally. The value ([], Just json) represents that the client should not store the response locally, but we do have a server-side cache value that can be used to avoid query execution. |
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) => [RemoteSchemaInfo] -> [ActionsInfo] -> QueryCacheKey -> Maybe CachedDirective -> TraceT (ExceptT QErr m) (ResponseHeaders, Maybe EncJSON) Source #
:: QueryCacheKey | Key under which to store the result of a query execution |
-> Maybe CachedDirective | Cached Directive from GraphQL query AST |
-> EncJSON | Result of a query execution |
-> TraceT (ExceptT QErr m) CacheStoreResponse | Always succeeds |
Store a json response for a query that we've executed in the cache. Note
that, as part of this, cacheStore
has to decide whether the response is
cacheable. A very similar decision is also made in cacheLookup
, since it
has to construct corresponding cache-enabling headers that are sent to the
client. But note that the HTTP headers influence client-side caching,
whereas cacheStore
changes the server-side cache.
default cacheStore :: (m ~ t n, MonadTrans t, MonadExecuteQuery n) => QueryCacheKey -> Maybe CachedDirective -> EncJSON -> TraceT (ExceptT QErr m) CacheStoreResponse 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.
AnnotatedResponsePart | |
|
data AnnotatedResponse Source #
A full response, annotated with timing metadata.
buildResponseFromParts :: MonadError QErr m => QueryType -> Either (Either GQExecError QErr) (RootFieldMap AnnotatedResponsePart) -> ResponseHeaders -> m AnnotatedResponse Source #
Merge response parts into a full response.
buildResponse :: MonadError QErr m => QueryType -> Either (Either GQExecError QErr) a -> (a -> AnnotatedResponse) -> m AnnotatedResponse Source #
newtype 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
Semigroup SessVarPred Source # | |
Defined in Hasura.GraphQL.Transport.HTTP (<>) :: SessVarPred -> SessVarPred -> SessVarPred # sconcat :: NonEmpty SessVarPred -> SessVarPred # stimes :: Integral b => b -> SessVarPred -> SessVarPred # | |
Monoid SessVarPred Source # | |
Defined in Hasura.GraphQL.Transport.HTTP mempty :: SessVarPred # mappend :: SessVarPred -> SessVarPred -> SessVarPred # mconcat :: [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, MonadReader ExecutionCtx m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadTrace m, MonadExecuteQuery m, MonadMetadataStorage (MetadataStorageT m), MonadQueryTags m, HasResourceLimits m) => Environment -> Logger Hasura -> 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), InsOrdHashMap RootFieldAlias (DBStepInfo ('Postgres 'Vanilla))) Source #
data GraphQLResponse Source #
decodeGraphQLResponse :: ByteString -> Either Text GraphQLResponse 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, MonadReader ExecutionCtx m, MonadGQLExecutionCheck m, MonadQueryLog m, MonadTrace m, MonadExecuteQuery m, HttpLog m, MonadMetadataStorage (MetadataStorageT m), MonadQueryTags m, HasResourceLimits m) | |
=> Environment | |
-> Logger Hasura | |
-> RequestId | |
-> ResponseInternalErrorsConfig | |
-> UserInfo | |
-> IpAddress | |
-> [Header] | |
-> GraphQLQueryType | |
-> GQLBatchedReqs (GQLReq GQLQueryText) | the batched request with unparsed GraphQL query |
-> m (HttpLogMetadata m, HttpResponse EncJSON) |
Run (execute) a batched GraphQL query (see GQLBatchedReqs
).