{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Morpheus.Error.Fragment
( cannotSpreadWithinItself,
cannotBeSpreadOnType,
)
where
import Data.Morpheus.Types.Internal.AST.Base
( Position,
Ref (..),
)
import Data.Morpheus.Types.Internal.AST.Error
( GQLError,
at,
atPositions,
manyMsg,
msg,
)
import Data.Morpheus.Types.Internal.AST.Name
( FragmentName,
TypeName,
)
import Relude
cannotSpreadWithinItself :: NonEmpty (Ref FragmentName) -> GQLError
cannotSpreadWithinItself :: NonEmpty (Ref FragmentName) -> GQLError
cannotSpreadWithinItself (Ref FragmentName
fr :| [Ref FragmentName]
frs) =
( GQLError
"Cannot spread fragment "
forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg (forall name. Ref name -> name
refName Ref FragmentName
fr)
forall a. Semigroup a => a -> a -> a
<> GQLError
" within itself via "
forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) a. (Foldable t, Msg a) => t a -> GQLError
manyMsg (forall name. Ref name -> name
refName forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Ref FragmentName
fr forall a. a -> [a] -> [a]
: [Ref FragmentName]
frs))
forall a. Semigroup a => a -> a -> a
<> GQLError
"."
)
forall (t :: * -> *).
Foldable t =>
GQLError -> t Position -> GQLError
`atPositions` forall a b. (a -> b) -> [a] -> [b]
map forall name. Ref name -> Position
refPosition (Ref FragmentName
fr forall a. a -> [a] -> [a]
: [Ref FragmentName]
frs)
cannotBeSpreadOnType :: Maybe FragmentName -> TypeName -> Position -> [TypeName] -> GQLError
cannotBeSpreadOnType :: Maybe FragmentName
-> TypeName -> Position -> [TypeName] -> GQLError
cannotBeSpreadOnType Maybe FragmentName
key TypeName
fragmentType Position
position [TypeName]
typeMembers =
( GQLError
"Fragment "
forall a. Semigroup a => a -> a -> a
<> forall {a}. Msg a => Maybe a -> GQLError
getName Maybe FragmentName
key
forall a. Semigroup a => a -> a -> a
<> GQLError
"cannot be spread here as objects of type "
forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) a. (Foldable t, Msg a) => t a -> GQLError
manyMsg [TypeName]
typeMembers
forall a. Semigroup a => a -> a -> a
<> GQLError
" can never be of type "
forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg TypeName
fragmentType
forall a. Semigroup a => a -> a -> a
<> GQLError
"."
)
GQLError -> Position -> GQLError
`at` Position
position
where
getName :: Maybe a -> GQLError
getName (Just a
x) = forall a. Msg a => a -> GQLError
msg a
x forall a. Semigroup a => a -> a -> a
<> GQLError
" "
getName Maybe a
Nothing = GQLError
""