Safe Haskell | None |
---|---|
Language | Haskell2010 |
Contains everything you need to write handlers for your GraphQL schema.
Synopsis
- type OperationResolverConstraint m fields typeName interfaces = (RunFields m (RunFieldsType m fields), HasObjectDefinition (Object typeName interfaces fields), Monad m)
- class HasResolver m a where
- data Result a = Result [ResolverError] a
- data a :<> b = a :<> b
- data ResolverError
- returns :: Applicative f => a -> f (HandlerResult a)
- handlerError :: Applicative f => Text -> f (HandlerResult a)
- resolveOperation :: forall m fields typeName interfaces. OperationResolverConstraint m fields typeName interfaces => Handler m (Object typeName interfaces fields) -> SelectionSetByType Value -> m (Result Object)
- unionValue :: forall (object :: Type) (union :: Type) m (name :: Symbol) interfaces fields. (Monad m, Object name interfaces fields ~ object, KnownSymbol name) => TypeIndex m object union -> m (DynamicUnionValue union m)
Documentation
type OperationResolverConstraint m fields typeName interfaces = (RunFields m (RunFieldsType m fields), HasObjectDefinition (Object typeName interfaces fields), Monad m) Source #
class HasResolver m a where Source #
Instances
Applicative m => HasResolver m Bool Source # | |
Applicative m => HasResolver m Text Source # | |
Applicative m => HasResolver m Double Source # | |
Applicative m => HasResolver m Int32 Source # | |
(HasResolver m hg, Monad m) => HasResolver m (Maybe hg :: Type) Source # | |
(Monad m, Applicative m, HasResolver m hg) => HasResolver m (List hg :: Type) Source # | |
(Monad m, KnownSymbol unionName, RunUnion m (Union unionName objects) objects) => HasResolver m (Union unionName objects :: Type) Source # | |
(Applicative m, GraphQLEnum enum) => HasResolver m (Enum ksN enum :: Type) Source # | |
(RunFields m (RunFieldsType m fields), HasObjectDefinition (Object typeName interfaces fields), Monad m) => HasResolver m (Object typeName interfaces fields :: Type) Source # | |
Result [ResolverError] a |
data a :<> b infixr 8 Source #
Object field separation operator.
Use this to provide handlers for fields of an object.
Say you had the following GraphQL type with "foo" and "bar" fields, e.g.
type MyObject { foo: Int! bar: String! }
You could provide handlers for it like this:
>>>
:m +System.Environment
>>>
let fooHandler = pure 42
>>>
let barHandler = System.Environment.getProgName
>>>
let myObjectHandler = pure $ fooHandler :<> barHandler :<> ()
a :<> b infixr 8 |
data ResolverError Source #
SchemaError SchemaError | There was a problem in the schema. Server-side problem. |
FieldNotFoundError Name | Couldn't find the requested field in the object. A client-side problem. |
ValueMissing Name | No value provided for name, and no default specified. Client-side problem. |
InvalidValue Name Text | Could not translate value into Haskell. Probably a client-side problem. |
ValidationError ValidationErrors | Found validation errors when we tried to merge fields. |
SubSelectionOnLeaf (SelectionSetByType Value) | Tried to get subselection of leaf field. |
MissingSelectionSet | Tried to treat an object as a leaf. |
HandlerError Text | Error from handler |
Instances
Eq ResolverError Source # | |
Defined in GraphQL.Internal.Resolver (==) :: ResolverError -> ResolverError -> Bool # (/=) :: ResolverError -> ResolverError -> Bool # | |
Show ResolverError Source # | |
Defined in GraphQL.Internal.Resolver showsPrec :: Int -> ResolverError -> ShowS # show :: ResolverError -> String # showList :: [ResolverError] -> ShowS # | |
GraphQLError ResolverError Source # | |
Defined in GraphQL.Internal.Resolver formatError :: ResolverError -> Text Source # toError :: ResolverError -> Error Source # |
returns :: Applicative f => a -> f (HandlerResult a) Source #
returns
is a convenience function for a Handler that is
returning the expected value.
handlerError :: Applicative f => Text -> f (HandlerResult a) Source #
handlerError
is a convenience function for a Handler that has
encountered an error and is unable to return the expected value.
resolveOperation :: forall m fields typeName interfaces. OperationResolverConstraint m fields typeName interfaces => Handler m (Object typeName interfaces fields) -> SelectionSetByType Value -> m (Result Object) Source #
unionValue :: forall (object :: Type) (union :: Type) m (name :: Symbol) interfaces fields. (Monad m, Object name interfaces fields ~ object, KnownSymbol name) => TypeIndex m object union -> m (DynamicUnionValue union m) Source #
Translate a Handler
into a DynamicUnionValue type required by
Union
handlers. This is dynamic, but nevertheless type-safe
because we can only tag with types that are part of the union.
Use e.g. like "unionValue @Cat" if you have an object like this:
>>>
type Cat = API.Object "Cat" '[] '[API.Field "name" Text]
and then use `unionValue @Cat (pure (pure Felix))`. See `examples/UnionExample.hs` for more code.