{-# LANGUAGE OverloadedStrings #-}
module Data.Morpheus.Error.Fragment
( cannotSpreadWithinItself,
cannotBeSpreadOnType,
)
where
import Data.Morpheus.Error.Utils (errorMessage)
import Data.Morpheus.Types.Internal.AST.Base
( FieldName,
GQLError (..),
GQLErrors,
Position,
Ref (..),
TypeName,
msg,
msgSepBy,
)
import Data.Semigroup ((<>))
cannotSpreadWithinItself :: [Ref] -> GQLErrors
cannotSpreadWithinItself fragments = [GQLError {message = text, locations = map refPosition fragments}]
where
text =
"Cannot spread fragment "
<> msg (refName $ head fragments)
<> " within itself via "
<> msgSepBy ", " (map refName fragments)
<> "."
cannotBeSpreadOnType :: Maybe FieldName -> TypeName -> Position -> [TypeName] -> GQLErrors
cannotBeSpreadOnType key fragmentType position typeMembers =
errorMessage
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 = ""