module Hasura.GraphQL.Schema.Backend
(
BackendSchema (..),
BackendTableSelectSchema (..),
BackendLogicalModelSelectSchema (..),
BackendNativeQuerySelectSchema (..),
BackendUpdateOperatorsSchema (..),
MonadBuildSchema,
ComparisonExp,
)
where
import Data.Kind (Type)
import Data.Text.Casing (GQLNameIdentifier)
import Hasura.Function.Cache
import Hasura.GraphQL.ApolloFederation (ApolloFederationParserFunction)
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.Parser hiding (Type)
import Hasura.LogicalModel.Cache (LogicalModelInfo)
import Hasura.NativeQuery.Cache (NativeQueryInfo)
import Hasura.Prelude
import Hasura.RQL.IR
import Hasura.RQL.IR.Insert qualified as IR
import Hasura.RQL.IR.Select qualified as IR
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Column hiding (EnumValueInfo)
import Hasura.RQL.Types.Column qualified as Column
import Hasura.RQL.Types.ComputedField
import Hasura.RQL.Types.NamingCase
import Hasura.RQL.Types.Relationships.Local
import Hasura.RQL.Types.SchemaCache
import Hasura.RQL.Types.Source
import Hasura.RQL.Types.SourceCustomization (MkRootFieldName)
import Hasura.StoredProcedure.Cache (StoredProcedureInfo)
import Language.GraphQL.Draft.Syntax qualified as G
type MonadBuildSchema b r m n =
( BackendSchema b,
MonadBuildSourceSchema b r m n
)
class
(Backend b) =>
BackendSchema (b :: BackendType)
where
buildTableQueryAndSubscriptionFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
TableName b ->
TableInfo b ->
GQLNameIdentifier ->
SchemaT
r
m
( [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))],
[FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))],
Maybe (G.Name, Parser 'Output n (ApolloFederationParserFunction n))
)
buildTableStreamingSubscriptionFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
TableName b ->
TableInfo b ->
GQLNameIdentifier ->
SchemaT r m [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildTableRelayQueryFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
TableName b ->
TableInfo b ->
GQLNameIdentifier ->
NESeq (ColumnInfo b) ->
SchemaT r m [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildTableInsertMutationFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
Scenario ->
TableName b ->
TableInfo b ->
GQLNameIdentifier ->
SchemaT r m [FieldParser n (AnnotatedInsert b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildTableUpdateMutationFields ::
(MonadBuildSchema b r m n) =>
Scenario ->
TableInfo b ->
GQLNameIdentifier ->
SchemaT r m [FieldParser n (AnnotatedUpdateG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildTableDeleteMutationFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
Scenario ->
TableName b ->
TableInfo b ->
GQLNameIdentifier ->
SchemaT r m [FieldParser n (AnnDelG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildFunctionQueryFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
FunctionName b ->
FunctionInfo b ->
TableName b ->
SchemaT r m [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildFunctionRelayQueryFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
FunctionName b ->
FunctionInfo b ->
TableName b ->
NESeq (ColumnInfo b) ->
SchemaT r m [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildFunctionMutationFields ::
(MonadBuildSchema b r m n) =>
MkRootFieldName ->
FunctionName b ->
FunctionInfo b ->
TableName b ->
SchemaT r m [FieldParser n (MutationDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildNativeQueryRootFields ::
(MonadBuildSchema b r m n) =>
NativeQueryInfo b ->
SchemaT
r
m
(Maybe (FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
buildNativeQueryRootFields NativeQueryInfo b
_ = Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
r
m
(Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. Maybe a
Nothing
buildStoredProcedureRootFields ::
(MonadBuildSchema b r m n) =>
StoredProcedureInfo b ->
SchemaT
r
m
(Maybe (FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
buildStoredProcedureRootFields StoredProcedureInfo b
_ = Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
r
m
(Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(FieldParser
n
(QueryDB
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. Maybe a
Nothing
mkRelationshipParser ::
(MonadBuildSchema b r m n) =>
RelInfo b ->
SchemaT r m (Maybe (InputFieldsParser n (Maybe (IR.AnnotatedInsertField b (UnpreparedValue b)))))
mkRelationshipParser RelInfo b
_ = Maybe
(InputFieldsParser
n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
-> SchemaT
r
m
(Maybe
(InputFieldsParser
n (Maybe (AnnotatedInsertField b (UnpreparedValue b)))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(InputFieldsParser
n (Maybe (AnnotatedInsertField b (UnpreparedValue b))))
forall a. Maybe a
Nothing
relayExtension :: Maybe (XRelay b)
nodesAggExtension :: Maybe (XNodesAgg b)
streamSubscriptionExtension :: Maybe (XStreamingSubscription b)
groupByExtension :: Maybe (XGroupBy b)
groupByExtension = Maybe (XGroupBy b)
forall a. Maybe a
Nothing
columnParser ::
(MonadBuildSchema b r m n) =>
ColumnType b ->
G.Nullability ->
SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
enumParser ::
(MonadBuildSchema b r m n) =>
TableName b ->
NonEmpty (EnumValue, Column.EnumValueInfo) ->
Maybe G.Name ->
G.Nullability ->
SchemaT r m (Parser 'Both n (ScalarValue b))
possiblyNullable ::
(MonadParse m) =>
ScalarType b ->
G.Nullability ->
Parser 'Both m (ScalarValue b) ->
Parser 'Both m (ScalarValue b)
scalarSelectionArgumentsParser ::
(MonadParse n) =>
ColumnType b ->
InputFieldsParser n (Maybe (ScalarSelectionArguments b))
orderByOperators ::
SourceInfo b ->
NamingCase ->
(G.Name, NonEmpty (Definition EnumValueInfo, (BasicOrderType b, NullsOrderType b)))
comparisonExps ::
(MonadBuildSchema b r m n) =>
ColumnType b ->
SchemaT r m (Parser 'Input n [ComparisonExp b])
countTypeInput ::
(MonadParse n) =>
Maybe (Parser 'Both n (Column b, AnnRedactionExpUnpreparedValue b)) ->
InputFieldsParser n (CountDistinct -> CountType b (UnpreparedValue b))
aggregateOrderByCountType :: ScalarType b
computedField ::
(MonadBuildSchema b r m n) =>
ComputedFieldInfo b ->
TableName b ->
TableInfo b ->
SchemaT r m (Maybe (FieldParser n (AnnotatedField b)))
class (Backend b) => BackendTableSelectSchema (b :: BackendType) where
tableArguments ::
(MonadBuildSourceSchema b r m n) =>
TableInfo b ->
SchemaT r m (InputFieldsParser n (IR.SelectArgsG b (UnpreparedValue b)))
tableSelectionSet ::
(MonadBuildSourceSchema b r m n) =>
TableInfo b ->
SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
selectTable ::
(MonadBuildSourceSchema b r m n) =>
TableInfo b ->
G.Name ->
Maybe G.Description ->
SchemaT r m (Maybe (FieldParser n (SelectExp b)))
selectTableAggregate ::
(MonadBuildSourceSchema b r m n) =>
TableInfo b ->
G.Name ->
Maybe G.Description ->
SchemaT r m (Maybe (FieldParser n (AggSelectExp b)))
type ComparisonExp b = OpExpG b (UnpreparedValue b)
class (Backend b) => BackendLogicalModelSelectSchema (b :: BackendType) where
logicalModelArguments ::
(MonadBuildSourceSchema b r m n) =>
LogicalModelInfo b ->
SchemaT r m (InputFieldsParser n (IR.SelectArgsG b (UnpreparedValue b)))
logicalModelSelectionSet ::
(MonadBuildSourceSchema b r m n) =>
LogicalModelInfo b ->
SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
class (BackendLogicalModelSelectSchema b) => BackendNativeQuerySelectSchema (b :: BackendType) where
selectNativeQuery ::
(MonadBuildSourceSchema b r m n) =>
NativeQueryInfo b ->
G.Name ->
Nullable ->
Maybe G.Description ->
SchemaT r m (Maybe (FieldParser n (AnnSimpleSelectG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
selectNativeQuery NativeQueryInfo b
_ Name
_ Nullable
_ Maybe Description
_ = Maybe
(FieldParser
n
(AnnSimpleSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
r
m
(Maybe
(FieldParser
n
(AnnSimpleSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(FieldParser
n
(AnnSimpleSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. Maybe a
Nothing
selectNativeQueryObject ::
(MonadBuildSchema b r m n) =>
NativeQueryInfo b ->
G.Name ->
Maybe G.Description ->
SchemaT
r
m
(Maybe (FieldParser n (AnnObjectSelectG b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
selectNativeQueryObject NativeQueryInfo b
_ Name
_ Maybe Description
_ = Maybe
(FieldParser
n
(AnnObjectSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
-> SchemaT
r
m
(Maybe
(FieldParser
n
(AnnObjectSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe
(FieldParser
n
(AnnObjectSelectG
b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b)))
forall a. Maybe a
Nothing
class (Backend b) => (b :: BackendType) where
type UpdateOperators b :: Type -> Type
parseUpdateOperators ::
forall m n r.
(MonadBuildSchema b r m n) =>
TableInfo b ->
UpdPermInfo b ->
SchemaT r m (InputFieldsParser n (HashMap (Column b) (UpdateOperators b (UnpreparedValue b))))