{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Morpheus.Error.Fragment
( cannotSpreadWithinItself,
cannotBeSpreadOnType,
)
where
import Data.Maybe (Maybe (..))
import Data.Morpheus.Error.Utils (validationErrorMessage)
import Data.Morpheus.Types.Internal.AST.Base
( FieldName,
Position,
Ref (..),
TypeName,
ValidationError (..),
msg,
msgSepBy,
)
import Data.Semigroup ((<>))
import Prelude (($), fmap, head)
cannotSpreadWithinItself :: [Ref] -> ValidationError
cannotSpreadWithinItself fragments = ValidationError text (fmap refPosition fragments)
where
text =
"Cannot spread fragment "
<> msg (refName $ head fragments)
<> " within itself via "
<> msgSepBy ", " (fmap refName fragments)
<> "."
cannotBeSpreadOnType :: Maybe FieldName -> TypeName -> Position -> [TypeName] -> ValidationError
cannotBeSpreadOnType key fragmentType position typeMembers =
validationErrorMessage
(Just position)
text
where
text =
"Fragment "
<> getName key
<> "cannot be spread here as objects of type "
<> msgSepBy ", " typeMembers
<> " can never be of type "
<> msg fragmentType
<> "."
getName (Just x) = msg x <> " "
getName Nothing = ""