diff options
| author | Matthías Páll Gissurarson <mpg@mpg.is> | 2016-03-12 00:59:51 +0100 |
|---|---|---|
| committer | Matthías Páll Gissurarson <mpg@mpg.is> | 2016-03-14 01:01:24 +0100 |
| commit | d1953891029a71115ee572b7b3798072cbaf2ea8 (patch) | |
| tree | c964aade8d6aeaff61f2bb8e6057079e7e5d5913 /Data/GraphQL/Execute.hs | |
| parent | b74278cd19d900d1397e35b85f7b80d70cd574f2 (diff) | |
| download | graphql-d1953891029a71115ee572b7b3798072cbaf2ea8.tar.gz | |
Added exception handling with Alternative constraint according to spec.
Diffstat (limited to 'Data/GraphQL/Execute.hs')
| -rw-r--r-- | Data/GraphQL/Execute.hs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Data/GraphQL/Execute.hs b/Data/GraphQL/Execute.hs index 47d1d03..e5998e9 100644 --- a/Data/GraphQL/Execute.hs +++ b/Data/GraphQL/Execute.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} module Data.GraphQL.Execute (execute) where #if !MIN_VERSION_base(4,8,0) @@ -13,10 +14,19 @@ import Data.GraphQL.AST import Data.GraphQL.Schema (Schema(..)) import qualified Data.GraphQL.Schema as Schema -execute - :: Alternative f - => Schema.Schema f -> Schema.Subs -> Document -> f Aeson.Value -execute (Schema resolvs) subs = Schema.resolvers resolvs . rootFields subs +import Data.GraphQL.Error + +{- | Takes a schema, a substitution and a GraphQL document. + The substition is applied to the document using rootFields, and + the schema's resolvers are applied to the resulting fields. + Returns the result of the query against the schema wrapped in a + "data" field, or errors wrapped in a "errors field". +-} +execute :: Alternative m + => Schema.Schema m -> Schema.Subs -> Document -> m Aeson.Value +execute (Schema resolvs) subs doc = runCollectErrs res + where res = Schema.resolvers resolvs $ rootFields subs doc + rootFields :: Schema.Subs -> Document -> [Field] rootFields subs (Document [DefinitionOperation (Query (Node _varDefs _ _ sels))]) = |
