{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Morpheus.Error.Document.Interface
( unknownInterface,
ImplementsError (..),
partialImplements,
)
where
import Data.Morpheus.Types.Internal.AST.Error
( GQLError,
msg,
)
import Data.Morpheus.Types.Internal.AST.Name
( TypeName,
)
import Data.Morpheus.Types.Internal.AST.Type (TypeRef)
import Data.Morpheus.Types.Internal.Validation.SchemaValidator
( Field (..),
InterfaceName (..),
ON_INTERFACE,
TypeEntity (..),
renderField,
)
import Relude
unknownInterface :: TypeName -> GQLError
unknownInterface :: TypeName -> GQLError
unknownInterface TypeName
name = GQLError
"Unknown Interface " forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg TypeName
name forall a. Semigroup a => a -> a -> a
<> GQLError
"."
data ImplementsError
= UnexpectedType
{ ImplementsError -> TypeRef
expectedType :: TypeRef,
ImplementsError -> TypeRef
foundType :: TypeRef
}
| Missing
partialImplements :: Field ON_INTERFACE -> ImplementsError -> GQLError
partialImplements :: Field ON_INTERFACE -> ImplementsError -> GQLError
partialImplements (Field FieldName
fieldName Maybe FieldName
argName (TypeEntity (OnInterface TypeName
interfaceName) TypeName
typename)) ImplementsError
errorType =
GQLError
"Interface field "
forall a. Semigroup a => a -> a -> a
<> forall b a. b -> (a -> b) -> Maybe a -> b
maybe GQLError
"" (forall a b. a -> b -> a
const GQLError
"argument ") Maybe FieldName
argName
forall a. Semigroup a => a -> a -> a
<> TypeName -> FieldName -> Maybe FieldName -> GQLError
renderField TypeName
interfaceName FieldName
fieldName Maybe FieldName
argName
forall a. Semigroup a => a -> a -> a
<> GQLError -> GQLError -> ImplementsError -> GQLError
detailedMessageGen
(TypeName -> FieldName -> Maybe FieldName -> GQLError
renderField TypeName
typename FieldName
fieldName Maybe FieldName
argName)
(forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. Msg a => a -> GQLError
msg TypeName
typename) (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ TypeName -> FieldName -> Maybe FieldName -> GQLError
renderField TypeName
typename FieldName
fieldName forall a. Maybe a
Nothing) Maybe FieldName
argName)
ImplementsError
errorType
detailedMessageGen :: GQLError -> GQLError -> ImplementsError -> GQLError
detailedMessageGen :: GQLError -> GQLError -> ImplementsError -> GQLError
detailedMessageGen GQLError
pl1 GQLError
_ UnexpectedType {TypeRef
expectedType :: TypeRef
expectedType :: ImplementsError -> TypeRef
expectedType, TypeRef
foundType :: TypeRef
foundType :: ImplementsError -> TypeRef
foundType} =
GQLError
" expects type "
forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg TypeRef
expectedType
forall a. Semigroup a => a -> a -> a
<> GQLError
" but "
forall a. Semigroup a => a -> a -> a
<> GQLError
pl1
forall a. Semigroup a => a -> a -> a
<> GQLError
" is type "
forall a. Semigroup a => a -> a -> a
<> forall a. Msg a => a -> GQLError
msg TypeRef
foundType
forall a. Semigroup a => a -> a -> a
<> GQLError
"."
detailedMessageGen GQLError
_ GQLError
pl2 ImplementsError
Missing = GQLError
" expected but " forall a. Semigroup a => a -> a -> a
<> GQLError
pl2 forall a. Semigroup a => a -> a -> a
<> GQLError
" does not provide it."