Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interface for GraphQL API.
Note: This module is highly subject to change. We're still figuring where to draw the lines and what to expose.
Synopsis
- interpretQuery :: forall api m fields typeName interfaces. (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) => Handler m api -> Text -> Maybe Name -> VariableValues -> m Response
- interpretAnonymousQuery :: forall api m fields typeName interfaces. (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) => Handler m api -> Text -> m Response
- data Response
- makeSchema :: forall api. HasObjectDefinition api => Either QueryError Schema
- compileQuery :: Schema -> Text -> Either QueryError (QueryDocument VariableValue)
- executeQuery :: forall api m fields typeName interfaces. (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) => Handler m api -> QueryDocument VariableValue -> Maybe Name -> VariableValues -> m Response
- data QueryError
- data Schema
- type VariableValues = Map Variable Value
- type Value = Value' ConstScalar
Running queries
:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) | |
=> Handler m api | Handler for the query. This links the query to the code you've written to handle it. |
-> Text | The text of a query document. Will be parsed and then executed. |
-> Maybe Name | An optional name for the operation within document to run. If |
-> VariableValues | Values for variables defined in the query document. A map of |
-> m Response | The outcome of running the query. |
Interpet a GraphQL query.
Compiles then executes a GraphQL query.
interpretAnonymousQuery Source #
:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) | |
=> Handler m api | Handler for the anonymous query. |
-> Text | The text of the anonymous query. Should defined only a single, unnamed query operation. |
-> m Response | The result of running the query. |
Interpret an anonymous GraphQL query.
Anonymous queries have no name and take no variables.
GraphQL response.
A GraphQL response must:
- be a map
- have a "data" key iff the operation executed
- have an "errors" key iff the operation encountered errors
- not include "data" if operation failed before execution (e.g. syntax errors, validation errors, missing info)
- not have keys other than "data", "errors", and "extensions"
Other interesting things:
- Doesn't have to be JSON, but does have to have maps, strings, lists, and null
- Can also support bool, int, enum, and float
- Value of "extensions" must be a map
"data" must be null if an error was encountered during execution that prevented a valid response.
"errors"
- must be a non-empty list
- each error is a map with "message", optionally "locations" key with list of locations
- locations are maps with 1-indexed "line" and "column" keys.
Preparing queries then running them
makeSchema :: forall api. HasObjectDefinition api => Either QueryError Schema Source #
Create a GraphQL schema.
compileQuery :: Schema -> Text -> Either QueryError (QueryDocument VariableValue) Source #
Turn some text into a valid query document.
:: (Object typeName interfaces fields ~ api, OperationResolverConstraint m fields typeName interfaces) | |
=> Handler m api | Handler for the query. This links the query to the code you've written to handle it. |
-> QueryDocument VariableValue | A validated query document. Build one with |
-> Maybe Name | An optional name. If |
-> VariableValues | Values for variables defined in the query document. A map of |
-> m Response | The outcome of running the query. |
Execute a GraphQL query.
data QueryError Source #
Errors that can happen while processing a query document.
Instances
Eq QueryError Source # | |
Defined in GraphQL (==) :: QueryError -> QueryError -> Bool # (/=) :: QueryError -> QueryError -> Bool # | |
Show QueryError Source # | |
Defined in GraphQL showsPrec :: Int -> QueryError -> ShowS # show :: QueryError -> String # showList :: [QueryError] -> ShowS # | |
GraphQLError QueryError Source # | |
Defined in GraphQL formatError :: QueryError -> Text Source # toError :: QueryError -> Error Source # |
An entire GraphQL schema.
This is very much a work in progress. Currently, the only thing we provide is a dictionary mapping type names to their definitions.
type VariableValues = Map Variable Value Source #
A map of variables to their values.
In GraphQL the variable values are not part of the query itself, they are
instead passed in through a separate channel. Create a VariableValues
from this other channel and pass it to substituteVariables
.
GraphQL allows the values of variables to be specified, but doesn't provide a way for doing so in the language.
type Value = Value' ConstScalar Source #
A GraphQL value which contains no variables.