{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.GraphQL.Error
( GraphQLError(..)
, GraphQLErrorLoc(..)
, GraphQLException(..)
) where
import Control.Exception (Exception)
import Data.Aeson (FromJSON(..), ToJSON, Value, withObject, (.:))
import Data.Text (Text)
import GHC.Generics (Generic)
data GraphQLError = GraphQLError
{ message :: Text
, locations :: Maybe [GraphQLErrorLoc]
, path :: Maybe [Value]
} deriving (Show,Eq,Generic,ToJSON,FromJSON)
data GraphQLErrorLoc = GraphQLErrorLoc
{ errorLine :: Int
, errorCol :: Int
} deriving (Show,Eq,Generic,ToJSON)
instance FromJSON GraphQLErrorLoc where
parseJSON = withObject "GraphQLErrorLoc" $ \o ->
GraphQLErrorLoc
<$> o .: "line"
<*> o .: "column"
newtype GraphQLException = GraphQLException [GraphQLError]
deriving (Show,Exception,Eq)