summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2020-07-24 21:34:31 +0200
committerEugen Wissner <belka@caraus.de>2020-07-24 21:34:31 +0200
commitadeba459a20e3fa2e74d98ae7219ef3ed41e7883 (patch)
tree64dd430aed053b3cb060686ab82781cf713b60f5
parent44d506d4b57e450480cf9c476bd927a43ad9c25d (diff)
downloadgraphql-0.9.0.0.tar.gz
Release 0.9.0.0v0.9.0.0
-rw-r--r--CHANGELOG.md1
-rw-r--r--package.yaml2
-rw-r--r--src/Language/GraphQL/Validate.hs12
-rw-r--r--src/Language/GraphQL/Validate/Rules.hs6
-rw-r--r--stack.yaml2
5 files changed, 19 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f7f370..ae76a2c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ and this project adheres to
and event stream) resolvers to signalize an error. Other exceptions will
escape.
- `Test.Hspec.GraphQL` contains some test helpers.
+- `Validate` contains the validator and standard rules.
## Changed
- `Type.Out.Resolver`: Interface fields don't have resolvers, object fields
diff --git a/package.yaml b/package.yaml
index d24e4ba..dcdc6c8 100644
--- a/package.yaml
+++ b/package.yaml
@@ -1,5 +1,5 @@
name: graphql
-version: 0.8.0.0
+version: 0.9.0.0
synopsis: Haskell GraphQL implementation
description:
This package provides a rudimentary parser for the
diff --git a/src/Language/GraphQL/Validate.hs b/src/Language/GraphQL/Validate.hs
index 6df97a1..5768615 100644
--- a/src/Language/GraphQL/Validate.hs
+++ b/src/Language/GraphQL/Validate.hs
@@ -5,6 +5,7 @@
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
+-- | GraphQL validator.
module Language.GraphQL.Validate
( Error(..)
, Path(..)
@@ -29,17 +30,24 @@ data Context m = Context
type ValidateT m = Reader (Context m) (Seq Error)
+-- | If an error can be associated to a particular field in the GraphQL result,
+-- it must contain an entry with the key path that details the path of the
+-- response field which experienced the error. This allows clients to identify
+-- whether a null result is intentional or caused by a runtime error.
data Path
- = Segment Text
- | Index Int
+ = Segment Text -- ^ Field name.
+ | Index Int -- ^ List index if a field returned a list.
deriving (Eq, Show)
+-- | Validation error.
data Error = Error
{ message :: String
, locations :: [Location]
, path :: [Path]
} deriving (Eq, Show)
+-- | Validates a document and returns a list of found errors. If the returned
+-- list is empty, the document is valid.
document :: forall m. Schema m -> [Rule] -> Document -> Seq Error
document schema' rules' document' =
runReader (foldrM go Seq.empty document') context
diff --git a/src/Language/GraphQL/Validate/Rules.hs b/src/Language/GraphQL/Validate/Rules.hs
index bc754c2..a3314e7 100644
--- a/src/Language/GraphQL/Validate/Rules.hs
+++ b/src/Language/GraphQL/Validate/Rules.hs
@@ -2,6 +2,7 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. -}
+-- | This module contains default rules defined in the GraphQL specification.
module Language.GraphQL.Validate.Rules
( Rule(..)
, executableDefinitionsRule
@@ -10,14 +11,19 @@ module Language.GraphQL.Validate.Rules
import Language.GraphQL.AST.Document
+-- | 'Rule' assigns a function to each AST node that can be validated. If the
+-- validation fails, the function should return an error message, or 'Nothing'
+-- otherwise.
newtype Rule
= DefinitionRule (Definition -> Maybe String)
+-- | Default reules given in the specification.
specifiedRules :: [Rule]
specifiedRules =
[ executableDefinitionsRule
]
+-- | Definition must be OperationDefinition or FragmentDefinition.
executableDefinitionsRule :: Rule
executableDefinitionsRule = DefinitionRule go
where
diff --git a/stack.yaml b/stack.yaml
index 513705a..a494b98 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -1,4 +1,4 @@
-resolver: lts-16.5
+resolver: lts-16.6
packages:
- .