mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
Replace ParseT
with Parse
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4724 GitOrigin-RevId: d742bc876ca11dbbe7e3f02bbdf9bf9c2440cbe6
This commit is contained in:
parent
8f0b3f6d06
commit
0f97c27115
@ -395,8 +395,10 @@ getResolvedExecPlan
|
|||||||
let parameterizedQueryHash = calculateParameterizedQueryHash normalizedSelectionSet
|
let parameterizedQueryHash = calculateParameterizedQueryHash normalizedSelectionSet
|
||||||
-- Process directives on the subscription
|
-- Process directives on the subscription
|
||||||
dirMap <-
|
dirMap <-
|
||||||
(`onLeft` reportParseErrors)
|
liftEither $
|
||||||
=<< runParseT (parseDirectives customDirectives (G.DLExecutable G.EDLSUBSCRIPTION) normalizedDirectives)
|
runParse (parseDirectives customDirectives (G.DLExecutable G.EDLSUBSCRIPTION) normalizedDirectives)
|
||||||
|
`onLeft` reportParseErrors
|
||||||
|
|
||||||
-- A subscription should have exactly one root field.
|
-- A subscription should have exactly one root field.
|
||||||
-- However, for testing purposes, we may allow several root fields; we check for this by
|
-- However, for testing purposes, we may allow several root fields; we check for this by
|
||||||
-- looking for directive "_multiple_top_level_fields" on the subscription. THIS IS NOT A
|
-- looking for directive "_multiple_top_level_fields" on the subscription. THIS IS NOT A
|
||||||
|
@ -112,8 +112,9 @@ convertMutationSelectionSet
|
|||||||
|
|
||||||
-- Process directives on the mutation
|
-- Process directives on the mutation
|
||||||
_dirMap <-
|
_dirMap <-
|
||||||
(`onLeft` reportParseErrors)
|
liftEither $
|
||||||
=<< runParseT (parseDirectives customDirectives (G.DLExecutable G.EDLMUTATION) resolvedDirectives)
|
runParse (parseDirectives customDirectives (G.DLExecutable G.EDLMUTATION) resolvedDirectives)
|
||||||
|
`onLeft` reportParseErrors
|
||||||
|
|
||||||
let parameterizedQueryHash = calculateParameterizedQueryHash resolvedSelSet
|
let parameterizedQueryHash = calculateParameterizedQueryHash resolvedSelSet
|
||||||
|
|
||||||
|
@ -96,8 +96,9 @@ convertQuerySelSet
|
|||||||
|
|
||||||
-- 2. Parse directives on the query
|
-- 2. Parse directives on the query
|
||||||
dirMap <-
|
dirMap <-
|
||||||
(`onLeft` reportParseErrors)
|
liftEither
|
||||||
=<< runParseT (parseDirectives customDirectives (G.DLExecutable G.EDLQUERY) normalizedDirectives)
|
(runParse (parseDirectives customDirectives (G.DLExecutable G.EDLQUERY) normalizedDirectives))
|
||||||
|
`onLeft` reportParseErrors
|
||||||
|
|
||||||
let parameterizedQueryHash = calculateParameterizedQueryHash normalizedSelectionSet
|
let parameterizedQueryHash = calculateParameterizedQueryHash normalizedSelectionSet
|
||||||
|
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
module Hasura.GraphQL.Parser.Monad
|
module Hasura.GraphQL.Parser.Monad
|
||||||
( SchemaT,
|
( SchemaT,
|
||||||
runSchemaT,
|
runSchemaT,
|
||||||
ParseT,
|
Parse,
|
||||||
runParseT,
|
runParse,
|
||||||
ParseError (..),
|
ParseError (..),
|
||||||
reportParseErrors,
|
reportParseErrors,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
import Control.Monad.Except
|
||||||
import Data.Dependent.Map (DMap)
|
import Data.Dependent.Map (DMap)
|
||||||
import Data.Dependent.Map qualified as DM
|
import Data.Dependent.Map qualified as DM
|
||||||
import Data.GADT.Compare.Extended
|
import Data.GADT.Compare.Extended
|
||||||
@ -160,25 +161,22 @@ newtype instance ParserById m '(p, a) = ParserById (p m a)
|
|||||||
-- -------------------------------------------------------------------------------------------------
|
-- -------------------------------------------------------------------------------------------------
|
||||||
-- query parsing
|
-- query parsing
|
||||||
|
|
||||||
newtype ParseT m a = ParseT
|
newtype Parse a = Parse
|
||||||
{ unParseT :: ReaderT JSONPath (ExceptT ParseError m) a
|
{ unParse :: ReaderT JSONPath (Except ParseError) a
|
||||||
}
|
}
|
||||||
deriving (Functor, Applicative, Monad)
|
deriving (Functor, Applicative, Monad)
|
||||||
|
|
||||||
runParseT ::
|
runParse ::
|
||||||
ParseT m a ->
|
Parse a ->
|
||||||
m (Either ParseError a)
|
Either ParseError a
|
||||||
runParseT =
|
runParse =
|
||||||
unParseT
|
unParse
|
||||||
>>> flip runReaderT []
|
>>> flip runReaderT []
|
||||||
>>> runExceptT
|
>>> runExcept
|
||||||
|
|
||||||
instance MonadTrans ParseT where
|
instance MonadParse Parse where
|
||||||
lift = ParseT . lift . lift
|
withPath f x = Parse $ withReaderT f $ unParse x
|
||||||
|
parseErrorWith code text = Parse $ do
|
||||||
instance Monad m => MonadParse (ParseT m) where
|
|
||||||
withPath f x = ParseT $ withReaderT f $ unParseT x
|
|
||||||
parseErrorWith code text = ParseT $ do
|
|
||||||
path <- ask
|
path <- ask
|
||||||
lift $ throwError $ ParseError {peCode = code, pePath = path, peMessage = text}
|
lift $ throwError $ ParseError {peCode = code, pePath = path, peMessage = text}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import Data.Text qualified as T
|
|||||||
import Data.Text.Extended (dquoteList, (<<>))
|
import Data.Text.Extended (dquoteList, (<<>))
|
||||||
import Hasura.Base.Error
|
import Hasura.Base.Error
|
||||||
import Hasura.GraphQL.Parser.Constants qualified as G
|
import Hasura.GraphQL.Parser.Constants qualified as G
|
||||||
import Hasura.GraphQL.Parser.Monad (ParseT, runSchemaT)
|
import Hasura.GraphQL.Parser.Monad (Parse, runSchemaT)
|
||||||
import Hasura.GraphQL.Schema.Common
|
import Hasura.GraphQL.Schema.Common
|
||||||
import Hasura.GraphQL.Schema.Remote (buildRemoteParser)
|
import Hasura.GraphQL.Schema.Remote (buildRemoteParser)
|
||||||
import Hasura.GraphQL.Transport.HTTP.Protocol
|
import Hasura.GraphQL.Transport.HTTP.Protocol
|
||||||
@ -80,7 +80,7 @@ fetchRemoteSchema env manager _rscName rsDef@ValidatedRemoteSchemaDef {..} = do
|
|||||||
void $
|
void $
|
||||||
flip runReaderT minimumValidContext $
|
flip runReaderT minimumValidContext $
|
||||||
runSchemaT $
|
runSchemaT $
|
||||||
buildRemoteParser @_ @_ @(ParseT Identity)
|
buildRemoteParser @_ @_ @Parse
|
||||||
_rscIntroOriginal
|
_rscIntroOriginal
|
||||||
_rscRemoteRelationships
|
_rscRemoteRelationships
|
||||||
_rscInfo
|
_rscInfo
|
||||||
@ -256,14 +256,14 @@ validateSchemaCustomizationsDistinct remoteSchemaCustomizer (RemoteSchemaIntrosp
|
|||||||
validateFieldMappingsAreDistinct :: G.TypeDefinition a b -> m ()
|
validateFieldMappingsAreDistinct :: G.TypeDefinition a b -> m ()
|
||||||
validateFieldMappingsAreDistinct = \case
|
validateFieldMappingsAreDistinct = \case
|
||||||
G.TypeDefinitionInterface G.InterfaceTypeDefinition {..} -> do
|
G.TypeDefinitionInterface G.InterfaceTypeDefinition {..} -> do
|
||||||
let dups = duplicates $ (customizeFieldName _itdName . G._fldName) <$> _itdFieldsDefinition
|
let dups = duplicates $ customizeFieldName _itdName . G._fldName <$> _itdFieldsDefinition
|
||||||
unless (Set.null dups) $
|
unless (Set.null dups) $
|
||||||
throwRemoteSchema $
|
throwRemoteSchema $
|
||||||
"Field name mappings for interface type " <> _itdName
|
"Field name mappings for interface type " <> _itdName
|
||||||
<<> " are not distinct; the following fields appear more than once: "
|
<<> " are not distinct; the following fields appear more than once: "
|
||||||
<> dquoteList dups
|
<> dquoteList dups
|
||||||
G.TypeDefinitionObject G.ObjectTypeDefinition {..} -> do
|
G.TypeDefinitionObject G.ObjectTypeDefinition {..} -> do
|
||||||
let dups = duplicates $ (customizeFieldName _otdName . G._fldName) <$> _otdFieldsDefinition
|
let dups = duplicates $ customizeFieldName _otdName . G._fldName <$> _otdFieldsDefinition
|
||||||
unless (Set.null dups) $
|
unless (Set.null dups) $
|
||||||
throwRemoteSchema $
|
throwRemoteSchema $
|
||||||
"Field name mappings for object type " <> _otdName
|
"Field name mappings for object type " <> _otdName
|
||||||
|
@ -260,10 +260,10 @@ buildRoleContext options sources remotes allActionInfos customTypes role remoteS
|
|||||||
SourceInfo b ->
|
SourceInfo b ->
|
||||||
ConcreteSchemaT
|
ConcreteSchemaT
|
||||||
m
|
m
|
||||||
( [FieldParser (P.ParseT Identity) (NamespacedField (QueryRootField UnpreparedValue))],
|
( [FieldParser P.Parse (NamespacedField (QueryRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (MutationRootField UnpreparedValue))],
|
[FieldParser P.Parse (NamespacedField (MutationRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (MutationRootField UnpreparedValue))],
|
[FieldParser P.Parse (NamespacedField (MutationRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (QueryRootField UnpreparedValue))]
|
[FieldParser P.Parse (NamespacedField (QueryRootField UnpreparedValue))]
|
||||||
)
|
)
|
||||||
buildSource sourceInfo@(SourceInfo _ tables functions _ _ sourceCustomization') =
|
buildSource sourceInfo@(SourceInfo _ tables functions _ _ sourceCustomization') =
|
||||||
withSourceCustomization sourceCustomization (namingConventionSupport @b) globalDefaultNC do
|
withSourceCustomization sourceCustomization (namingConventionSupport @b) globalDefaultNC do
|
||||||
@ -378,10 +378,10 @@ buildRelayRoleContext options sources allActionInfos customTypes role expFeature
|
|||||||
SourceInfo b ->
|
SourceInfo b ->
|
||||||
ConcreteSchemaT
|
ConcreteSchemaT
|
||||||
m
|
m
|
||||||
( [FieldParser (P.ParseT Identity) (NamespacedField (QueryRootField UnpreparedValue))],
|
( [FieldParser P.Parse (NamespacedField (QueryRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (MutationRootField UnpreparedValue))],
|
[FieldParser P.Parse (NamespacedField (MutationRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (MutationRootField UnpreparedValue))],
|
[FieldParser P.Parse (NamespacedField (MutationRootField UnpreparedValue))],
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (QueryRootField UnpreparedValue))]
|
[FieldParser P.Parse (NamespacedField (QueryRootField UnpreparedValue))]
|
||||||
)
|
)
|
||||||
buildSource sourceInfo@(SourceInfo _ tables functions _ _ sourceCustomization') =
|
buildSource sourceInfo@(SourceInfo _ tables functions _ _ sourceCustomization') =
|
||||||
withSourceCustomization sourceCustomization (namingConventionSupport @b) globalDefaultNC do
|
withSourceCustomization sourceCustomization (namingConventionSupport @b) globalDefaultNC do
|
||||||
@ -496,11 +496,11 @@ buildAndValidateRemoteSchemas ::
|
|||||||
MonadIO m
|
MonadIO m
|
||||||
) =>
|
) =>
|
||||||
HashMap RemoteSchemaName (RemoteSchemaCtx, MetadataObject) ->
|
HashMap RemoteSchemaName (RemoteSchemaCtx, MetadataObject) ->
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (QueryRootField UnpreparedValue))] ->
|
[FieldParser P.Parse (NamespacedField (QueryRootField UnpreparedValue))] ->
|
||||||
[FieldParser (P.ParseT Identity) (NamespacedField (MutationRootField UnpreparedValue))] ->
|
[FieldParser P.Parse (NamespacedField (MutationRootField UnpreparedValue))] ->
|
||||||
RoleName ->
|
RoleName ->
|
||||||
RemoteSchemaPermsCtx ->
|
RemoteSchemaPermsCtx ->
|
||||||
ConcreteSchemaT m ([RemoteSchemaParser (P.ParseT Identity)], HashSet InconsistentMetadata)
|
ConcreteSchemaT m ([RemoteSchemaParser P.Parse], HashSet InconsistentMetadata)
|
||||||
buildAndValidateRemoteSchemas remotes sourcesQueryFields sourcesMutationFields role remoteSchemaPermsCtx =
|
buildAndValidateRemoteSchemas remotes sourcesQueryFields sourcesMutationFields role remoteSchemaPermsCtx =
|
||||||
runWriterT $ foldlM step [] (Map.elems remotes)
|
runWriterT $ foldlM step [] (Map.elems remotes)
|
||||||
where
|
where
|
||||||
@ -551,7 +551,7 @@ buildRemoteSchemaParser ::
|
|||||||
RemoteSchemaPermsCtx ->
|
RemoteSchemaPermsCtx ->
|
||||||
RoleName ->
|
RoleName ->
|
||||||
RemoteSchemaCtx ->
|
RemoteSchemaCtx ->
|
||||||
ConcreteSchemaT m (Maybe (RemoteSchemaParser (P.ParseT Identity)))
|
ConcreteSchemaT m (Maybe (RemoteSchemaParser P.Parse))
|
||||||
buildRemoteSchemaParser remoteSchemaPermsCtx roleName context = do
|
buildRemoteSchemaParser remoteSchemaPermsCtx roleName context = do
|
||||||
let maybeIntrospection = getIntrospectionResult remoteSchemaPermsCtx roleName context
|
let maybeIntrospection = getIntrospectionResult remoteSchemaPermsCtx roleName context
|
||||||
for maybeIntrospection \introspection ->
|
for maybeIntrospection \introspection ->
|
||||||
@ -668,7 +668,7 @@ buildMutationFields scenario sourceInfo tables (takeExposedAs FEAMutation -> fun
|
|||||||
guard $
|
guard $
|
||||||
-- when function permissions are inferred, we don't expose the
|
-- when function permissions are inferred, we don't expose the
|
||||||
-- mutation functions for non-admin roles. See Note [Function Permissions]
|
-- mutation functions for non-admin roles. See Note [Function Permissions]
|
||||||
roleName == adminRoleName || roleName `Map.member` (_fiPermissions functionInfo)
|
roleName == adminRoleName || roleName `Map.member` _fiPermissions functionInfo
|
||||||
lift $ mkRFs MDBR $ buildFunctionMutationFields sourceInfo functionName functionInfo targetTableName
|
lift $ mkRFs MDBR $ buildFunctionMutationFields sourceInfo functionName functionInfo targetTableName
|
||||||
pure $ concat $ tableMutations <> catMaybes functionMutations
|
pure $ concat $ tableMutations <> catMaybes functionMutations
|
||||||
where
|
where
|
||||||
@ -835,8 +835,8 @@ mkRootFields ::
|
|||||||
SourceConfig b ->
|
SourceConfig b ->
|
||||||
Maybe QueryTagsConfig ->
|
Maybe QueryTagsConfig ->
|
||||||
(a -> db b) ->
|
(a -> db b) ->
|
||||||
m [(FieldParser n a)] ->
|
m [FieldParser n a] ->
|
||||||
m [(FieldParser n (RootField db remote action raw))]
|
m [FieldParser n (RootField db remote action raw)]
|
||||||
mkRootFields sourceName sourceConfig queryTagsConfig inj =
|
mkRootFields sourceName sourceConfig queryTagsConfig inj =
|
||||||
fmap
|
fmap
|
||||||
( map
|
( map
|
||||||
@ -855,12 +855,12 @@ mutationRoot = G._mutation_root
|
|||||||
queryRoot :: G.Name
|
queryRoot :: G.Name
|
||||||
queryRoot = G._query_root
|
queryRoot = G._query_root
|
||||||
|
|
||||||
finalizeParser :: Parser 'Output (P.ParseT Identity) a -> ParserFn a
|
finalizeParser :: Parser 'Output P.Parse a -> ParserFn a
|
||||||
finalizeParser parser = runIdentity . P.runParseT . P.runParser parser
|
finalizeParser parser = P.runParse . P.runParser parser
|
||||||
|
|
||||||
type ConcreteSchemaT m a =
|
type ConcreteSchemaT m a =
|
||||||
P.SchemaT
|
P.SchemaT
|
||||||
(P.ParseT Identity)
|
P.Parse
|
||||||
( ReaderT
|
( ReaderT
|
||||||
( SchemaOptions,
|
( SchemaOptions,
|
||||||
SchemaContext,
|
SchemaContext,
|
||||||
|
@ -206,9 +206,9 @@ buildIntrospectionSchema queryRoot' mutationRoot' subscriptionRoot' = do
|
|||||||
let -- The only directives that we currently expose over introspection are our
|
let -- The only directives that we currently expose over introspection are our
|
||||||
-- statically defined ones. So, for instance, we don't correctly expose
|
-- statically defined ones. So, for instance, we don't correctly expose
|
||||||
-- directives from remote schemas.
|
-- directives from remote schemas.
|
||||||
directives = directivesInfo @(P.ParseT Identity)
|
directives = directivesInfo @P.Parse
|
||||||
-- The __schema and __type introspection fields
|
-- The __schema and __type introspection fields
|
||||||
introspection = [schema @(P.ParseT Identity), typeIntrospection]
|
introspection = [schema @P.Parse, typeIntrospection]
|
||||||
{-# INLINE introspection #-}
|
{-# INLINE introspection #-}
|
||||||
|
|
||||||
-- Collect type information of all non-introspection fields
|
-- Collect type information of all non-introspection fields
|
||||||
|
Loading…
Reference in New Issue
Block a user