{-# LANGUAGE PatternSynonyms #-}
module Hasura.GraphQL.Schema.Parser
(
FieldParser,
pattern P.FieldParser,
InputFieldsParser,
pattern P.InputFieldsParser,
InputObjectInfo,
pattern P.InputObjectInfo,
Parser,
pattern P.Parser,
Schema,
pattern P.Schema,
ConflictingDefinitions,
pattern P.ConflictingDefinitions,
Definition,
pattern P.Definition,
Type,
TypeInfo,
Directive,
pattern P.Directive,
DirectiveInfo,
pattern P.DirectiveInfo,
FieldInfo,
pattern P.FieldInfo,
InputFieldInfo,
pattern P.InputFieldInfo,
HasTypeDefinitions,
SomeDefinitionTypeInfo,
pattern P.SomeDefinitionTypeInfo,
TypeDefinitionsWrapper,
pattern TypeDefinitionsWrapper,
P.ParseErrorCode (..),
toQErr,
module Hasura.GraphQL.Parser,
Memoize.MonadMemoize,
memoizeOn,
memoize,
)
where
import Control.Monad.Error.Class
import Control.Monad.Memoize qualified as Memoize
import Data.Typeable
import Hasura.Base.Error
import Hasura.Base.ErrorMessage (ErrorMessage (fromErrorMessage))
import Hasura.GraphQL.Parser hiding
( ConflictingDefinitions (..),
Definition,
Directive,
DirectiveInfo,
FieldInfo,
FieldParser,
HasTypeDefinitions,
InputFieldInfo,
InputFieldsParser,
InputObjectInfo,
ParseErrorCode (..),
Parser,
Schema,
SomeDefinitionTypeInfo,
Type,
TypeDefinitionsWrapper,
TypeInfo,
)
import Hasura.GraphQL.Parser qualified as P
import Hasura.Prelude
import Hasura.RQL.Types.Metadata.Object
import Language.Haskell.TH qualified as TH
type FieldParser = P.FieldParser MetadataObjId
type Parser = P.Parser MetadataObjId
type Schema = P.Schema MetadataObjId
type ConflictingDefinitions = P.ConflictingDefinitions MetadataObjId
type Type = P.Type MetadataObjId
type TypeInfo = P.TypeInfo MetadataObjId
type InputFieldsParser = P.InputFieldsParser MetadataObjId
type InputObjectInfo = P.InputObjectInfo MetadataObjId
type Definition = P.Definition MetadataObjId
type Directive = P.Directive MetadataObjId
type DirectiveInfo = P.DirectiveInfo MetadataObjId
type FieldInfo = P.FieldInfo MetadataObjId
type InputFieldInfo = P.InputFieldInfo MetadataObjId
type HasTypeDefinitions = P.HasTypeDefinitions MetadataObjId
type SomeDefinitionTypeInfo = P.SomeDefinitionTypeInfo MetadataObjId
type TypeDefinitionsWrapper = P.TypeDefinitionsWrapper MetadataObjId
pattern TypeDefinitionsWrapper :: () => forall a. (HasTypeDefinitions a) => a -> TypeDefinitionsWrapper
pattern $mTypeDefinitionsWrapper :: forall {r}.
TypeDefinitionsWrapper
-> (forall {a}. HasTypeDefinitions a => a -> r)
-> ((# #) -> r)
-> r
$bTypeDefinitionsWrapper :: forall a. HasTypeDefinitions a => a -> TypeDefinitionsWrapper
TypeDefinitionsWrapper typeDef = P.TypeDefinitionsWrapper typeDef
toQErr :: (MonadError QErr m) => Either ParseError a -> m a
toQErr :: forall (m :: * -> *) a.
MonadError QErr m =>
Either ParseError a -> m a
toQErr = (ParseError -> m a) -> (a -> m a) -> Either ParseError a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (QErr -> m a
forall a. QErr -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (QErr -> m a) -> (ParseError -> QErr) -> ParseError -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseError -> QErr
parseErrorToQErr) a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
where
parseErrorToQErr :: ParseError -> QErr
parseErrorToQErr :: ParseError -> QErr
parseErrorToQErr ParseError {JSONPath
pePath :: JSONPath
pePath :: ParseError -> JSONPath
pePath, ErrorMessage
peMessage :: ErrorMessage
peMessage :: ParseError -> ErrorMessage
peMessage, ParseErrorCode
peCode :: ParseErrorCode
peCode :: ParseError -> ParseErrorCode
peCode} =
(Code -> Text -> QErr
err400 (ParseErrorCode -> Code
parseErrorCodeToCode ParseErrorCode
peCode) (ErrorMessage -> Text
fromErrorMessage ErrorMessage
peMessage)) {qePath :: JSONPath
qePath = JSONPath
pePath}
parseErrorCodeToCode :: P.ParseErrorCode -> Code
parseErrorCodeToCode :: ParseErrorCode -> Code
parseErrorCodeToCode ParseErrorCode
P.ValidationFailed = Code
ValidationFailed
parseErrorCodeToCode ParseErrorCode
P.ParseFailed = Code
ParseFailed
parseErrorCodeToCode ParseErrorCode
P.ConflictingDefinitionsError = Code
Unexpected
parseErrorCodeToCode ParseErrorCode
P.NotSupported = Code
NotSupported
memoizeOn ::
(Memoize.MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n, Typeable b) =>
TH.Name ->
a ->
m (p n b) ->
m (p n b)
memoizeOn :: forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
Typeable b) =>
Name -> a -> m (p n b) -> m (p n b)
memoizeOn = Name -> a -> m (p n b) -> m (p n b)
forall a p.
(Ord a, Typeable a, Typeable p) =>
Name -> a -> m p -> m p
forall (m :: * -> *) a p.
(MonadMemoize m, Ord a, Typeable a, Typeable p) =>
Name -> a -> m p -> m p
Memoize.memoizeOn
memoize ::
(Memoize.MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n, Typeable b) =>
TH.Name ->
(a -> m (p n b)) ->
(a -> m (p n b))
memoize :: forall (m :: * -> *) a (p :: (* -> *) -> * -> *) (n :: * -> *) b.
(MonadMemoize m, Ord a, Typeable a, Typeable p, MonadParse n,
Typeable b) =>
Name -> (a -> m (p n b)) -> a -> m (p n b)
memoize = Name -> (a -> m (p n b)) -> a -> m (p n b)
forall (m :: * -> *) a p.
(MonadMemoize m, Ord a, Typeable a, Typeable p) =>
Name -> (a -> m p) -> a -> m p
Memoize.memoize