diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-07-24 21:34:31 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-07-24 21:58:49 +0200 |
| commit | c60dd98fc5b5b8d3fb3d8f071db078ddb547c5cf (patch) | |
| tree | 0404597129675f53f13ad5afc5eccbb1072c24c5 /src/Language/GraphQL/Validate.hs | |
| parent | 44d506d4b57e450480cf9c476bd927a43ad9c25d (diff) | |
| download | graphql-c60dd98fc5b5b8d3fb3d8f071db078ddb547c5cf.tar.gz | |
Release 0.9.0.0
Diffstat (limited to 'src/Language/GraphQL/Validate.hs')
| -rw-r--r-- | src/Language/GraphQL/Validate.hs | 12 |
1 files changed, 10 insertions, 2 deletions
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 |
