Maintainer | Brandon Chinn <[email protected]> |
---|---|
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Data.GraphQL.Monad
Description
Defines the MonadGraphQLQuery
type class to query GraphQL APIs.
Also provides the GraphQLQueryT
monad transformer that can be
added to a transformer stack to implement the type class, and the
runQuerySafeIO
function to manually implement it yourself.
Synopsis
- class Monad m => MonadGraphQLQuery (m :: Type -> Type) where
- runQuerySafe :: forall query (schema :: Schema). (GraphQLQuery query, schema ~ ResultSchema query) => query -> m (GraphQLResult (Object schema))
- runQuery :: forall m query (schema :: Schema). (MonadIO m, MonadGraphQLQuery m, GraphQLQuery query, schema ~ ResultSchema query) => query -> m (Object schema)
- runQuerySafeIO :: forall query (schema :: Schema). (GraphQLQuery query, schema ~ ResultSchema query) => GraphQLManager -> query -> IO (GraphQLResult (Object schema))
- data GraphQLSettings = GraphQLSettings {
- managerSettings :: ManagerSettings
- url :: String
- modifyReq :: Request -> Request
- defaultGraphQLSettings :: GraphQLSettings
- data GraphQLManager
- initGraphQLManager :: GraphQLSettings -> IO GraphQLManager
- data GraphQLQueryT (m :: Type -> Type) a
- runGraphQLQueryT :: MonadIO m => GraphQLSettings -> GraphQLQueryT m a -> m a
MonadGraphQLQuery API
class Monad m => MonadGraphQLQuery (m :: Type -> Type) where Source #
A type class for monads that can run GraphQL queries.
Methods
runQuerySafe :: forall query (schema :: Schema). (GraphQLQuery query, schema ~ ResultSchema query) => query -> m (GraphQLResult (Object schema)) Source #
Run the given query and return the GraphQLResult
.
Instances
runQuery :: forall m query (schema :: Schema). (MonadIO m, MonadGraphQLQuery m, GraphQLQuery query, schema ~ ResultSchema query) => query -> m (Object schema) Source #
Run the given query and returns the result, erroring if the query returned errors.
runQuerySafeIO :: forall query (schema :: Schema). (GraphQLQuery query, schema ~ ResultSchema query) => GraphQLManager -> query -> IO (GraphQLResult (Object schema)) Source #
Execute a GraphQL query with the given GraphQLManager
.
GraphQLSettings
data GraphQLSettings Source #
The settings for initializing a GraphQLManager
.
Constructors
GraphQLSettings | |
Fields
|
defaultGraphQLSettings :: GraphQLSettings Source #
Default settings for GraphQLSettings
. Requires url
field to be overridden.
Example usage:
>>>
defaultGraphQLSettings
... { url = "https://api.github.com/graphql" ... , modifyReq = \\req -> req ... { requestHeaders = ... (hAuthorization, "bearer my_github_token") : requestHeaders req ... } ... }
GraphQLManager
data GraphQLManager Source #
The manager for running GraphQL queries.
GraphQLQueryT
data GraphQLQueryT (m :: Type -> Type) a Source #
The monad transformer type that can be used to run GraphQL queries.
newtype MyMonad a = MyMonad { unMyMonad :: GraphQLQueryT IO a } runMyMonad :: MyMonad a -> IO a runMyMonad = runGraphQLQueryT graphQLSettings . unMyMonad where graphQLSettings = defaultGraphQLSettings{url = "https://api.github.com/graphql"}
Instances
runGraphQLQueryT :: MonadIO m => GraphQLSettings -> GraphQLQueryT m a -> m a Source #
Run the GraphQLQueryT monad transformer.