Add Union and Interface type definitions
This commit is contained in:
@ -9,6 +9,7 @@ module Language.GraphQL.Execute
|
||||
|
||||
import qualified Data.Aeson as Aeson
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import Data.Sequence (Seq(..))
|
||||
import Data.Text (Text)
|
||||
import Language.GraphQL.AST.Document
|
||||
import qualified Language.GraphQL.AST.Core as AST.Core
|
||||
@ -29,7 +30,7 @@ execute :: (Monad m, VariableValue a)
|
||||
-> HashMap.HashMap Name a -- ^ Variable substitution function.
|
||||
-> Document -- @GraphQL@ document.
|
||||
-> m Aeson.Value
|
||||
execute schema = document schema Nothing
|
||||
execute schema = executeRequest schema Nothing
|
||||
|
||||
-- | The substitution is applied to the document, and the resolvers are applied
|
||||
-- to the resulting fields. The operation name can be used if the document
|
||||
@ -43,36 +44,34 @@ executeWithName :: (Monad m, VariableValue a)
|
||||
-> HashMap.HashMap Name a -- ^ Variable substitution function.
|
||||
-> Document -- ^ @GraphQL@ Document.
|
||||
-> m Aeson.Value
|
||||
executeWithName schema operationName = document schema (Just operationName)
|
||||
executeWithName schema operationName =
|
||||
executeRequest schema (Just operationName)
|
||||
|
||||
document :: (Monad m, VariableValue a)
|
||||
executeRequest :: (Monad m, VariableValue a)
|
||||
=> Schema m
|
||||
-> Maybe Text
|
||||
-> HashMap.HashMap Name a
|
||||
-> Document
|
||||
-> m Aeson.Value
|
||||
document schema operationName subs document' =
|
||||
case Transform.document schema operationName subs document' of
|
||||
executeRequest schema operationName subs document =
|
||||
case Transform.document schema operationName subs document of
|
||||
Left queryError -> pure $ singleError $ Transform.queryError queryError
|
||||
Right (Transform.Document operation') -> operation schema operation'
|
||||
Right (Transform.Document rootObjectType operation)
|
||||
| (AST.Core.Query _ fields) <- operation ->
|
||||
executeOperation rootObjectType fields
|
||||
| (AST.Core.Mutation _ fields) <- operation ->
|
||||
executeOperation rootObjectType fields
|
||||
|
||||
operation :: Monad m
|
||||
=> Schema m
|
||||
-> AST.Core.Operation
|
||||
-- This is actually executeMutation, but we don't distinguish between queries
|
||||
-- and mutations yet.
|
||||
executeOperation :: Monad m
|
||||
=> Out.ObjectType m
|
||||
-> Seq AST.Core.Selection
|
||||
-> m Aeson.Value
|
||||
operation = schemaOperation
|
||||
executeOperation (Out.ObjectType _ _ _ objectFields) fields
|
||||
= runCollectErrs
|
||||
$ flip Schema.resolve fields
|
||||
$ fmap getResolver
|
||||
$ objectFields
|
||||
where
|
||||
resolve queryFields = runCollectErrs
|
||||
. flip Schema.resolve queryFields
|
||||
. fmap getResolver
|
||||
. fields
|
||||
fields (Out.ObjectType _ _ objectFields) = objectFields
|
||||
lookupError = pure
|
||||
$ singleError "Root operation type couldn't be found in the schema."
|
||||
schemaOperation Schema {query} (AST.Core.Query _ fields') =
|
||||
resolve fields' query
|
||||
schemaOperation Schema {mutation = Just mutation} (AST.Core.Mutation _ fields') =
|
||||
resolve fields' mutation
|
||||
schemaOperation Schema {mutation = Nothing} (AST.Core.Mutation _ _) =
|
||||
lookupError
|
||||
getResolver (Out.Field _ _ _ resolver) = resolver
|
||||
|
Reference in New Issue
Block a user