{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Hasura.Backends.DataConnector.Adapter.Schema () where

--------------------------------------------------------------------------------

import Control.Lens ((^.))
import Data.Aeson qualified as J
import Data.Has
import Data.HashMap.Strict.Extended qualified as HashMap
import Data.List.NonEmpty qualified as NE
import Data.Scientific (fromFloatDigits)
import Data.Sequence qualified as Seq
import Data.Text.Casing (GQLNameIdentifier, fromAutogeneratedName, fromCustomName)
import Data.Text.Extended (toTxt, (<<>), (<>>))
import Data.Traversable (mapAccumL)
import Hasura.Backends.DataConnector.API qualified as API
import Hasura.Backends.DataConnector.Adapter.Backend (CustomBooleanOperator (..), columnTypeToScalarType, lookupGraphQLType)
import Hasura.Backends.DataConnector.Adapter.Types qualified as DC
import Hasura.Backends.DataConnector.Adapter.Types.Mutations qualified as DC
import Hasura.Base.Error
import Hasura.Function.Cache qualified as RQL
import Hasura.GraphQL.Parser.Class
import Hasura.GraphQL.Schema.Backend (BackendSchema (..), BackendTableSelectSchema (..), BackendUpdateOperatorsSchema (..), ComparisonExp, MonadBuildSchema)
import Hasura.GraphQL.Schema.BoolExp qualified as GS.BE
import Hasura.GraphQL.Schema.Build qualified as GS.B
import Hasura.GraphQL.Schema.Common qualified as GS.C
import Hasura.GraphQL.Schema.Parser qualified as P
import Hasura.GraphQL.Schema.Select qualified as GS.S
import Hasura.GraphQL.Schema.Table qualified as GS.T
import Hasura.GraphQL.Schema.Typename qualified as GS.N
import Hasura.GraphQL.Schema.Update qualified as GS.U
import Hasura.GraphQL.Schema.Update.Batch qualified as GS.U.B
import Hasura.Name qualified as Name
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp qualified as IR
import Hasura.RQL.IR.Delete qualified as IR
import Hasura.RQL.IR.Insert qualified as IR
import Hasura.RQL.IR.Root qualified as IR
import Hasura.RQL.IR.Select qualified as IR
import Hasura.RQL.IR.Update qualified as IR
import Hasura.RQL.IR.Value qualified as IR
import Hasura.RQL.Types.Backend qualified as RQL
import Hasura.RQL.Types.BackendType (BackendType (..))
import Hasura.RQL.Types.Column qualified as RQL
import Hasura.RQL.Types.Common qualified as RQL
import Hasura.RQL.Types.ComputedField as RQL
import Hasura.RQL.Types.NamingCase
import Hasura.RQL.Types.Schema.Options qualified as Options
import Hasura.RQL.Types.Source qualified as RQL
import Hasura.RQL.Types.SourceCustomization qualified as RQL
import Hasura.Table.Cache qualified as RQL
import Language.GraphQL.Draft.Syntax qualified as GQL
import Witch qualified

--------------------------------------------------------------------------------

instance BackendSchema 'DataConnector where
  -- top level parsers
  buildTableQueryAndSubscriptionFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     ([FieldParser
         n
         (QueryDB
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))],
      [FieldParser
         n
         (QueryDB
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))],
      Maybe (Name, Parser 'Output n (ApolloFederationParserFunction n)))
buildTableQueryAndSubscriptionFields = MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     ([FieldParser
         n
         (QueryDB
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))],
      [FieldParser
         n
         (QueryDB
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))],
      Maybe (Name, Parser 'Output n (ApolloFederationParserFunction n)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b,
 BackendTableSelectSchema b) =>
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 (Name, Parser 'Output n (ApolloFederationParserFunction n)))
GS.B.buildTableQueryAndSubscriptionFields

  buildTableRelayQueryFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> NESeq (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableRelayQueryFields = MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> NESeq (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall r (m :: * -> *) (n :: * -> *) a.
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> NESeq (ColumnInfo 'DataConnector)
-> SchemaT r m [FieldParser n a]
experimentalBuildTableRelayQueryFields

  buildFunctionQueryFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> FunctionName 'DataConnector
-> FunctionInfo 'DataConnector
-> TableName 'DataConnector
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildFunctionQueryFields = MkRootFieldName
-> FunctionName 'DataConnector
-> FunctionInfo 'DataConnector
-> TableName 'DataConnector
-> SchemaT
     r
     m
     [FieldParser
        MetadataObjId
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
MkRootFieldName
-> FunctionName
-> FunctionInfo 'DataConnector
-> TableName
-> SchemaT
     r
     m
     [FieldParser
        MetadataObjId
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall r (m :: * -> *) (n :: * -> *).
(MonadError QErr m, MonadMemoize m, MonadParse n,
 Has (SourceInfo 'DataConnector) r, Has SchemaContext r,
 Has SchemaOptions r) =>
MkRootFieldName
-> FunctionName
-> FunctionInfo 'DataConnector
-> TableName
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildFunctionQueryFields'
  buildFunctionRelayQueryFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> FunctionName 'DataConnector
-> FunctionInfo 'DataConnector
-> TableName 'DataConnector
-> NESeq (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildFunctionRelayQueryFields MkRootFieldName
_ FunctionName 'DataConnector
_ FunctionInfo 'DataConnector
_ TableName 'DataConnector
_ NESeq (ColumnInfo 'DataConnector)
_ = [FieldParser
   n
   (QueryDB
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  buildFunctionMutationFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> FunctionName 'DataConnector
-> FunctionInfo 'DataConnector
-> TableName 'DataConnector
-> SchemaT
     r
     m
     [FieldParser
        n
        (MutationDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildFunctionMutationFields MkRootFieldName
_ FunctionName 'DataConnector
_ FunctionInfo 'DataConnector
_ TableName 'DataConnector
_ = [FieldParser
   n
   (MutationDB
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (MutationDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
  buildTableInsertMutationFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableInsertMutationFields = MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableInsertMutationFields'
  buildTableUpdateMutationFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableUpdateMutationFields = Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableUpdateMutationFields'
  buildTableDeleteMutationFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableDeleteMutationFields = MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableDeleteMutationFields'
  buildTableStreamingSubscriptionFields :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableStreamingSubscriptionFields MkRootFieldName
_ TableName 'DataConnector
_ TableInfo 'DataConnector
_ GQLNameIdentifier
_ = [FieldParser
   n
   (QueryDB
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

  -- backend extensions
  relayExtension :: Maybe (XRelay 'DataConnector)
relayExtension = Maybe Void
Maybe (XRelay 'DataConnector)
forall a. Maybe a
Nothing
  nodesAggExtension :: Maybe (XNodesAgg 'DataConnector)
nodesAggExtension = () -> Maybe ()
forall a. a -> Maybe a
Just ()
  streamSubscriptionExtension :: Maybe (XStreamingSubscription 'DataConnector)
streamSubscriptionExtension = Maybe Void
Maybe (XStreamingSubscription 'DataConnector)
forall a. Maybe a
Nothing

  -- individual components
  columnParser :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser = ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser'
  enumParser :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
enumParser = TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
forall (m :: * -> *) r (n :: * -> *).
MonadError QErr m =>
TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
enumParser'
  possiblyNullable :: forall (m :: * -> *).
MonadParse m =>
ScalarType 'DataConnector
-> Nullability
-> Parser 'Both m (ScalarValue 'DataConnector)
-> Parser 'Both m (ScalarValue 'DataConnector)
possiblyNullable = ScalarType 'DataConnector
-> Nullability -> Parser 'Both m Value -> Parser 'Both m Value
ScalarType 'DataConnector
-> Nullability
-> Parser MetadataObjId 'Both m (ScalarValue 'DataConnector)
-> Parser MetadataObjId 'Both m (ScalarValue 'DataConnector)
forall (m :: * -> *).
MonadParse m =>
ScalarType 'DataConnector
-> Nullability -> Parser 'Both m Value -> Parser 'Both m Value
possiblyNullable'
  scalarSelectionArgumentsParser :: forall (n :: * -> *).
MonadParse n =>
ColumnType 'DataConnector
-> InputFieldsParser
     n (Maybe (ScalarSelectionArguments 'DataConnector))
scalarSelectionArgumentsParser ColumnType 'DataConnector
_ = Maybe Void -> InputFieldsParser MetadataObjId n (Maybe Void)
forall a. a -> InputFieldsParser MetadataObjId n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Void
forall a. Maybe a
Nothing
  orderByOperators :: SourceInfo 'DataConnector
-> NamingCase
-> (Name,
    NonEmpty
      (Definition EnumValueInfo,
       (BasicOrderType 'DataConnector, NullsOrderType 'DataConnector)))
orderByOperators = SourceInfo 'DataConnector
-> NamingCase
-> (Name,
    NonEmpty
      (Definition EnumValueInfo,
       (BasicOrderType 'DataConnector, NullsOrderType 'DataConnector)))
orderByOperators'
  comparisonExps :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
comparisonExps = ColumnType 'DataConnector
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
comparisonExps'

  countTypeInput :: forall (n :: * -> *).
MonadParse n =>
Maybe
  (Parser
     'Both
     n
     (Column 'DataConnector,
      AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct
      -> CountType 'DataConnector (UnpreparedValue 'DataConnector))
countTypeInput = Maybe
  (Parser
     MetadataObjId
     'Both
     n
     (Column 'DataConnector,
      AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (CountDistinct
      -> CountType 'DataConnector (UnpreparedValue 'DataConnector))
Maybe
  (Parser
     'Both
     n
     (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
forall (n :: * -> *).
MonadParse n =>
Maybe
  (Parser
     'Both
     n
     (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
countTypeInput'

  -- aggregateOrderByCountType is only used when generating Relay schemas, and Data Connector backends do not yet support Relay
  -- If/when we want to support this we would need to add something to Capabilities to tell HGE what (integer-like) scalar
  -- type should be used to represent the result of a count aggregate in relay order-by queries.
  aggregateOrderByCountType :: ScalarType 'DataConnector
aggregateOrderByCountType =
    [Char] -> ScalarType
forall a. HasCallStack => [Char] -> a
error [Char]
"aggregateOrderByCountType: not implemented for Data Connector backend"

  computedField :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ComputedFieldInfo 'DataConnector
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (FieldParser n (AnnotatedField 'DataConnector)))
computedField =
    [Char]
-> ComputedFieldInfo 'DataConnector
-> TableName
-> TableInfo 'DataConnector
-> SchemaT
     r
     m
     (Maybe
        (FieldParser MetadataObjId n (AnnotatedField 'DataConnector)))
forall a. HasCallStack => [Char] -> a
error [Char]
"computedField: not implemented for the Data Connector backend."

instance BackendTableSelectSchema 'DataConnector where
  tableArguments :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
tableArguments = TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
tableArgs'
  selectTable :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> Name
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
selectTable = TableInfo 'DataConnector
-> Name
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> Name
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp b)))
GS.S.defaultSelectTable
  selectTableAggregate :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> Name
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (AggSelectExp 'DataConnector)))
selectTableAggregate = TableInfo 'DataConnector
-> Name
-> Maybe Description
-> SchemaT
     r m (Maybe (FieldParser n (AggSelectExp 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> Name
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (AggSelectExp b)))
GS.S.defaultSelectTableAggregate
  tableSelectionSet :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
tableSelectionSet = TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(AggregationPredicatesSchema b, BackendTableSelectSchema b,
 Eq (AnnBoolExp b (UnpreparedValue b)), MonadBuildSchema b r m n) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
GS.S.defaultTableSelectionSet

instance BackendUpdateOperatorsSchema 'DataConnector where
  type UpdateOperators 'DataConnector = DC.UpdateOperator

  parseUpdateOperators :: forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> UpdPermInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperators 'DataConnector (UnpreparedValue 'DataConnector))))
parseUpdateOperators = TableInfo 'DataConnector
-> UpdPermInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperator (UnpreparedValue 'DataConnector))))
TableInfo 'DataConnector
-> UpdPermInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperators 'DataConnector (UnpreparedValue 'DataConnector))))
forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> UpdPermInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperator (UnpreparedValue 'DataConnector))))
parseUpdateOperators'

--------------------------------------------------------------------------------

buildFunctionQueryFields' ::
  forall r m n.
  ( MonadError QErr m,
    P.MonadMemoize m,
    MonadParse n,
    Has (RQL.SourceInfo 'DataConnector) r,
    Has GS.C.SchemaContext r,
    Has Options.SchemaOptions r
  ) =>
  RQL.MkRootFieldName ->
  DC.FunctionName ->
  RQL.FunctionInfo 'DataConnector ->
  DC.TableName ->
  GS.C.SchemaT
    r
    m
    [ P.FieldParser
        n
        ( IR.QueryDB
            'DataConnector
            (IR.RemoteRelationshipField IR.UnpreparedValue)
            (IR.UnpreparedValue 'DataConnector)
        )
    ]
buildFunctionQueryFields' :: forall r (m :: * -> *) (n :: * -> *).
(MonadError QErr m, MonadMemoize m, MonadParse n,
 Has (SourceInfo 'DataConnector) r, Has SchemaContext r,
 Has SchemaOptions r) =>
MkRootFieldName
-> FunctionName
-> FunctionInfo 'DataConnector
-> TableName
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildFunctionQueryFields' MkRootFieldName
mkRootFieldName FunctionName
functionName FunctionInfo 'DataConnector
functionInfo TableName
tableName = do
  let -- Implementation modified from buildFunctionQueryFieldsPG
      funcDesc :: Maybe Description
funcDesc =
        Description -> Maybe Description
forall a. a -> Maybe a
Just
          (Description -> Maybe Description)
-> (Text -> Description) -> Text -> Maybe Description
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Description
GQL.Description
          (Text -> Maybe Description) -> Text -> Maybe Description
forall a b. (a -> b) -> a -> b
$ (Text -> Maybe Text -> Text) -> Maybe Text -> Text -> Text
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe (FunctionInfo 'DataConnector -> Maybe Text
forall (b :: BackendType). FunctionInfo b -> Maybe Text
RQL._fiComment FunctionInfo 'DataConnector
functionInfo Maybe Text -> Maybe Text -> Maybe Text
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FunctionInfo 'DataConnector -> Maybe Text
forall (b :: BackendType). FunctionInfo b -> Maybe Text
RQL._fiDescription FunctionInfo 'DataConnector
functionInfo)
          (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text
"execute function "
          Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FunctionName
functionName
          FunctionName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" which returns "
          Text -> TableName -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName
tableName

      queryResultType :: SelectExp 'DataConnector
-> QueryDB
     'DataConnector
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue 'DataConnector)
queryResultType =
        case FunctionInfo 'DataConnector -> JsonAggSelect
forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
RQL._fiJsonAggSelect FunctionInfo 'DataConnector
functionInfo of
          JsonAggSelect
RQL.JASMultipleRows -> SelectExp 'DataConnector
-> QueryDB
     'DataConnector
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue 'DataConnector)
forall (b :: BackendType) r v.
AnnSimpleSelectG b r v -> QueryDB b r v
IR.QDBMultipleRows
          JsonAggSelect
RQL.JASSingleObject -> SelectExp 'DataConnector
-> QueryDB
     'DataConnector
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue 'DataConnector)
forall (b :: BackendType) r v.
AnnSimpleSelectG b r v -> QueryDB b r v
IR.QDBSingleRow

  [Maybe
   (FieldParser
      n
      (QueryDB
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector)))]
-> [FieldParser
      n
      (QueryDB
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
    ([Maybe
    (FieldParser
       n
       (QueryDB
          'DataConnector
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue 'DataConnector)))]
 -> [FieldParser
       n
       (QueryDB
          'DataConnector
          (RemoteRelationshipField UnpreparedValue)
          (UnpreparedValue 'DataConnector))])
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (QueryDB
              'DataConnector
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue 'DataConnector)))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (QueryDB
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SchemaT
   r
   m
   (Maybe
      (FieldParser
         n
         (QueryDB
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))))]
-> SchemaT
     r
     m
     [Maybe
        (FieldParser
           n
           (QueryDB
              'DataConnector
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue 'DataConnector)))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA
      [ (SelectExp 'DataConnector
 -> QueryDB
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              'DataConnector
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue 'DataConnector))))
forall (n :: * -> *) (m :: * -> *) a b.
(Functor n, Functor m) =>
(a -> b)
-> m (Maybe (FieldParser n a)) -> m (Maybe (FieldParser n b))
GS.C.optionalFieldParser SelectExp 'DataConnector
-> QueryDB
     'DataConnector
     (RemoteRelationshipField UnpreparedValue)
     (UnpreparedValue 'DataConnector)
queryResultType (SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
 -> SchemaT
      r
      m
      (Maybe
         (FieldParser
            n
            (QueryDB
               'DataConnector
               (RemoteRelationshipField UnpreparedValue)
               (UnpreparedValue 'DataConnector)))))
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (QueryDB
              'DataConnector
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue 'DataConnector))))
forall a b. (a -> b) -> a -> b
$ MkRootFieldName
-> FunctionInfo 'DataConnector
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> FunctionInfo 'DataConnector
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
selectFunction MkRootFieldName
mkRootFieldName FunctionInfo 'DataConnector
functionInfo Maybe Description
funcDesc
      -- TODO: Aggregations are not currently supported.
      -- See: GS.C.optionalFieldParser (QDBAggregation) $ selectFunctionAggregate mkRootFieldName functionInfo funcAggDesc
      ]

-- | User-defined function (AKA custom function) -- Modified from PG variant.
selectFunction ::
  forall r m n.
  ( MonadBuildSchema 'DataConnector r m n
  ) =>
  RQL.MkRootFieldName ->
  -- | SQL function info
  RQL.FunctionInfo 'DataConnector -> -- TODO: The function return type should have already been resolved by this point - Into TableName

  -- | field description, if any
  Maybe GQL.Description ->
  GS.C.SchemaT r m (Maybe (P.FieldParser n (GS.C.SelectExp 'DataConnector)))
selectFunction :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> FunctionInfo 'DataConnector
-> Maybe Description
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
selectFunction MkRootFieldName
mkRootFieldName fi :: FunctionInfo 'DataConnector
fi@RQL.FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument 'DataConnector)
Name
SystemDefined
JsonAggSelect
TableName 'DataConnector
FunctionName 'DataConnector
FunctionExposedAs
FunctionVolatility
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiSQLName :: FunctionName 'DataConnector
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument 'DataConnector)
_fiReturnType :: TableName 'DataConnector
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
..} Maybe Description
description = MaybeT (SchemaT r m) (FieldParser n (SelectExp 'DataConnector))
-> SchemaT r m (Maybe (FieldParser n (SelectExp 'DataConnector)))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT do
  SourceInfo 'DataConnector
sourceInfo :: RQL.SourceInfo 'DataConnector <- (r -> SourceInfo 'DataConnector)
-> MaybeT (SchemaT r m) (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  RoleName
roleName <- (SchemaContext -> RoleName) -> MaybeT (SchemaT r m) RoleName
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
GS.C.retrieve SchemaContext -> RoleName
GS.C.scRole
  let customization :: ResolvedSourceCustomization
customization = SourceInfo 'DataConnector -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
RQL._siCustomization SourceInfo 'DataConnector
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
RQL._rscNamingConvention ResolvedSourceCustomization
customization
  TableInfo 'DataConnector
tableInfo <- SchemaT r m (TableInfo 'DataConnector)
-> MaybeT (SchemaT r m) (TableInfo 'DataConnector)
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SchemaT r m (TableInfo 'DataConnector)
 -> MaybeT (SchemaT r m) (TableInfo 'DataConnector))
-> SchemaT r m (TableInfo 'DataConnector)
-> MaybeT (SchemaT r m) (TableInfo 'DataConnector)
forall a b. (a -> b) -> a -> b
$ TableName 'DataConnector -> SchemaT r m (TableInfo 'DataConnector)
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
GS.C.askTableInfo TableName 'DataConnector
_fiReturnType
  SelPermInfo 'DataConnector
selectPermissions <- Maybe (SelPermInfo 'DataConnector)
-> MaybeT (SchemaT r m) (SelPermInfo 'DataConnector)
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe (Maybe (SelPermInfo 'DataConnector)
 -> MaybeT (SchemaT r m) (SelPermInfo 'DataConnector))
-> Maybe (SelPermInfo 'DataConnector)
-> MaybeT (SchemaT r m) (SelPermInfo 'DataConnector)
forall a b. (a -> b) -> a -> b
$ RoleName
-> TableInfo 'DataConnector -> Maybe (SelPermInfo 'DataConnector)
forall (b :: BackendType).
RoleName -> TableInfo b -> Maybe (SelPermInfo b)
GS.T.tableSelectPermissions RoleName
roleName TableInfo 'DataConnector
tableInfo
  Parser 'Output n (AnnotatedFields 'DataConnector)
selectionSetParser <- SchemaT
  r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
-> MaybeT
     (SchemaT r m) (Parser 'Output n (AnnotatedFields 'DataConnector))
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (SchemaT
   r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
 -> MaybeT
      (SchemaT r m) (Parser 'Output n (AnnotatedFields 'DataConnector)))
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
-> MaybeT
     (SchemaT r m) (Parser 'Output n (AnnotatedFields 'DataConnector))
forall a b. (a -> b) -> a -> b
$ TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
returnFunctionParser TableInfo 'DataConnector
tableInfo
  SchemaT r m (FieldParser n (SelectExp 'DataConnector))
-> MaybeT (SchemaT r m) (FieldParser n (SelectExp 'DataConnector))
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift do
    StringifyNumbers
stringifyNumbers <- (SchemaOptions -> StringifyNumbers) -> SchemaT r m StringifyNumbers
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
GS.C.retrieve SchemaOptions -> StringifyNumbers
Options.soStringifyNumbers
    InputFieldsParser
  n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
tableArgsParser <- TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT
     r m (InputFieldsParser n (SelectArgsG b (UnpreparedValue b)))
tableArguments TableInfo 'DataConnector
tableInfo
    InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
functionArgsParser <- FunctionInfo 'DataConnector
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
FunctionInfo 'DataConnector
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
customFunctionArgs FunctionInfo 'DataConnector
fi Name
_fiGQLName Name
_fiGQLArgsName
    let argsParser :: InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
   SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
argsParser = (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
 -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)
 -> (FunctionArgsExpG
       (ArgumentExp (UnpreparedValue 'DataConnector)),
     SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
      SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
forall a b c.
(a -> b -> c)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
-> InputFieldsParser MetadataObjId n c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
functionArgsParser InputFieldsParser
  n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
tableArgsParser
        functionFieldName :: Name
functionFieldName = MkRootFieldName -> Name -> Name
RQL.runMkRootFieldName MkRootFieldName
mkRootFieldName Name
_fiGQLName
    FieldParser n (SelectExp 'DataConnector)
-> SchemaT r m (FieldParser n (SelectExp 'DataConnector))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (FieldParser n (SelectExp 'DataConnector)
 -> SchemaT r m (FieldParser n (SelectExp 'DataConnector)))
-> FieldParser n (SelectExp 'DataConnector)
-> SchemaT r m (FieldParser n (SelectExp 'DataConnector))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
      SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> Parser 'Output n (AnnotatedFields 'DataConnector)
-> FieldParser
     MetadataObjId
     n
     ((FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
       SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)),
      AnnotatedFields 'DataConnector)
forall (m :: * -> *) origin a b.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Output m b
-> FieldParser origin m (a, b)
P.subselection Name
functionFieldName Maybe Description
description InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
   SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
argsParser Parser 'Output n (AnnotatedFields 'DataConnector)
selectionSetParser
      FieldParser
  MetadataObjId
  n
  ((FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)),
    SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)),
   AnnotatedFields 'DataConnector)
-> (((FunctionArgsExpG
        (ArgumentExp (UnpreparedValue 'DataConnector)),
      SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)),
     AnnotatedFields 'DataConnector)
    -> SelectExp 'DataConnector)
-> FieldParser n (SelectExp 'DataConnector)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \((FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
funcArgs, SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)
tableArgs''), AnnotatedFields 'DataConnector
fields) ->
        IR.AnnSelectG
          { $sel:_asnFields:AnnSelectG :: AnnotatedFields 'DataConnector
IR._asnFields = AnnotatedFields 'DataConnector
fields,
            $sel:_asnFrom:AnnSelectG :: SelectFromG 'DataConnector (UnpreparedValue 'DataConnector)
IR._asnFrom = FunctionName 'DataConnector
-> FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)
-> Maybe [(Column 'DataConnector, ScalarType 'DataConnector)]
-> SelectFromG 'DataConnector (UnpreparedValue 'DataConnector)
forall (b :: BackendType) v.
FunctionName b
-> FunctionArgsExp b v
-> Maybe [(Column b, ScalarType b)]
-> SelectFromG b v
IR.FromFunction FunctionName 'DataConnector
_fiSQLName FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)
FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
funcArgs Maybe [(Column 'DataConnector, ScalarType 'DataConnector)]
Maybe [(ColumnName, ScalarType)]
forall a. Maybe a
Nothing,
            $sel:_asnPerm:AnnSelectG :: TablePermG 'DataConnector (UnpreparedValue 'DataConnector)
IR._asnPerm = SelPermInfo 'DataConnector
-> TablePermG 'DataConnector (UnpreparedValue 'DataConnector)
forall (b :: BackendType).
Backend b =>
SelPermInfo b -> TablePerms b
GS.S.tablePermissionsInfo SelPermInfo 'DataConnector
selectPermissions,
            $sel:_asnArgs:AnnSelectG :: SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)
IR._asnArgs = SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)
tableArgs'',
            $sel:_asnStrfyNum:AnnSelectG :: StringifyNumbers
IR._asnStrfyNum = StringifyNumbers
stringifyNumbers,
            $sel:_asnNamingConvention:AnnSelectG :: Maybe NamingCase
IR._asnNamingConvention = NamingCase -> Maybe NamingCase
forall a. a -> Maybe a
Just NamingCase
tCase
          }
  where
    returnFunctionParser :: TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
returnFunctionParser =
      case JsonAggSelect
_fiJsonAggSelect of
        JsonAggSelect
RQL.JASSingleObject -> TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSourceSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendTableSelectSchema b, MonadBuildSourceSchema b r m n) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
tableSelectionSet
        JsonAggSelect
RQL.JASMultipleRows -> TableInfo 'DataConnector
-> SchemaT
     r m (Maybe (Parser 'Output n (AnnotatedFields 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
TableInfo b
-> SchemaT r m (Maybe (Parser 'Output n (AnnotatedFields b)))
GS.S.tableSelectionList

-- Modified version of the PG Reference: customSQLFunctionArgs.

-- | The custom SQL functions' input "args" field parser
-- > function_name(args: function_args)
customFunctionArgs ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.FunctionInfo 'DataConnector ->
  GQL.Name ->
  GQL.Name ->
  GS.C.SchemaT r m (P.InputFieldsParser n (RQL.FunctionArgsExp 'DataConnector (IR.UnpreparedValue 'DataConnector)))
customFunctionArgs :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
FunctionInfo 'DataConnector
-> Name
-> Name
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
customFunctionArgs RQL.FunctionInfo {Maybe Text
FunctionPermissionsMap
Seq (FunctionInputArgument 'DataConnector)
Name
SystemDefined
JsonAggSelect
TableName 'DataConnector
FunctionName 'DataConnector
FunctionExposedAs
FunctionVolatility
_fiComment :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiDescription :: forall (b :: BackendType). FunctionInfo b -> Maybe Text
_fiJsonAggSelect :: forall (b :: BackendType). FunctionInfo b -> JsonAggSelect
_fiSQLName :: forall (b :: BackendType). FunctionInfo b -> FunctionName b
_fiGQLName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLArgsName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiGQLAggregateName :: forall (b :: BackendType). FunctionInfo b -> Name
_fiSystemDefined :: forall (b :: BackendType). FunctionInfo b -> SystemDefined
_fiVolatility :: forall (b :: BackendType). FunctionInfo b -> FunctionVolatility
_fiExposedAs :: forall (b :: BackendType). FunctionInfo b -> FunctionExposedAs
_fiInputArgs :: forall (b :: BackendType).
FunctionInfo b -> Seq (FunctionInputArgument b)
_fiReturnType :: forall (b :: BackendType). FunctionInfo b -> TableName b
_fiPermissions :: forall (b :: BackendType). FunctionInfo b -> FunctionPermissionsMap
_fiSQLName :: FunctionName 'DataConnector
_fiGQLName :: Name
_fiGQLArgsName :: Name
_fiGQLAggregateName :: Name
_fiSystemDefined :: SystemDefined
_fiVolatility :: FunctionVolatility
_fiExposedAs :: FunctionExposedAs
_fiInputArgs :: Seq (FunctionInputArgument 'DataConnector)
_fiReturnType :: TableName 'DataConnector
_fiDescription :: Maybe Text
_fiPermissions :: FunctionPermissionsMap
_fiJsonAggSelect :: JsonAggSelect
_fiComment :: Maybe Text
..} Name
functionName Name
functionArgsName =
  FunctionTrackedAs 'DataConnector
-> Seq (FunctionInputArgument 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
FunctionTrackedAs 'DataConnector
-> Seq (FunctionInputArgument 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
functionArgs'
    ( CustomFunctionNames -> FunctionTrackedAs 'DataConnector
forall (b :: BackendType).
CustomFunctionNames -> FunctionTrackedAs b
FTACustomFunction
        (CustomFunctionNames -> FunctionTrackedAs 'DataConnector)
-> CustomFunctionNames -> FunctionTrackedAs 'DataConnector
forall a b. (a -> b) -> a -> b
$ RQL.CustomFunctionNames
          { cfnFunctionName :: Name
cfnFunctionName = Name
functionName,
            cfnArgsName :: Name
cfnArgsName = Name
functionArgsName
          }
    )
    Seq (FunctionInputArgument 'DataConnector)
_fiInputArgs

-- NOTE: Modified version of server/src-lib/Hasura/Backends/Postgres/Schema/Select.hs ~ functionArgs
functionArgs' ::
  forall r m n.
  (MonadBuildSchema 'DataConnector r m n) =>
  FunctionTrackedAs 'DataConnector ->
  Seq.Seq (RQL.FunctionInputArgument 'DataConnector) ->
  GS.C.SchemaT r m (P.InputFieldsParser n (RQL.FunctionArgsExp 'DataConnector (IR.UnpreparedValue 'DataConnector)))
functionArgs' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
FunctionTrackedAs 'DataConnector
-> Seq (FunctionInputArgument 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (FunctionArgsExp 'DataConnector (UnpreparedValue 'DataConnector)))
functionArgs' FunctionTrackedAs 'DataConnector
functionTrackedAs (Seq (InputArgument FunctionArg) -> [InputArgument FunctionArg]
Seq (FunctionInputArgument 'DataConnector)
-> [InputArgument FunctionArg]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList -> [InputArgument FunctionArg]
inputArgs) = do
  SourceInfo 'DataConnector
sourceInfo :: RQL.SourceInfo 'DataConnector <- (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  let customization :: ResolvedSourceCustomization
customization = SourceInfo 'DataConnector -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
RQL._siCustomization SourceInfo 'DataConnector
sourceInfo
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
RQL._rscNamingConvention ResolvedSourceCustomization
customization
      mkTypename :: Name -> Name
mkTypename = MkTypename -> Name -> Name
GS.N.runMkTypename (MkTypename -> Name -> Name) -> MkTypename -> Name -> Name
forall a b. (a -> b) -> a -> b
$ ResolvedSourceCustomization -> MkTypename
RQL._rscTypeNames ResolvedSourceCustomization
customization
      ([Text]
names, [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
session, [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
optional, [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
mandatory) = [([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
  [SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
  [SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])]
-> ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])
forall a. Monoid a => [a] -> a
mconcat ([([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])]
 -> ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]))
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])]
-> ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])
forall a b. (a -> b) -> a -> b
$ (Int,
 [([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
   [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])])
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])]
forall a b. (a, b) -> b
snd ((Int,
  [([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
    [SchemaT
       r
       m
       (InputFieldsParser
          n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])])
 -> [([Text],
      [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])])
-> (Int,
    [([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])])
-> [([Text],
     [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])]
forall a b. (a -> b) -> a -> b
$ (Int
 -> InputArgument FunctionArg
 -> (Int,
     ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])))
-> Int
-> [InputArgument FunctionArg]
-> (Int,
    [([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
      [SchemaT
         r
         m
         (InputFieldsParser
            n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))])])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL Int
-> InputArgument FunctionArg
-> (Int,
    ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]))
Int
-> FunctionInputArgument 'DataConnector
-> (Int,
    ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]))
splitArguments Int
1 [InputArgument FunctionArg]
inputArgs
      defaultArguments :: FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
defaultArguments = [ArgumentExp (UnpreparedValue 'DataConnector)]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
-> FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
RQL.FunctionArgsExp ((Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> ArgumentExp (UnpreparedValue 'DataConnector)
forall a b. (a, b) -> b
snd ((Text, ArgumentExp (UnpreparedValue 'DataConnector))
 -> ArgumentExp (UnpreparedValue 'DataConnector))
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> [ArgumentExp (UnpreparedValue 'DataConnector)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
session) HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
forall k v. HashMap k v
HashMap.empty
  if
    | [(Text, ArgumentExp (UnpreparedValue 'DataConnector))] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
session Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 ->
        Text
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))))
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 Text
"there shouldn't be more than one session argument"
    | [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
optional Bool -> Bool -> Bool
&& [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
mandatory ->
        InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   MetadataObjId
   n
   (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))))
forall a b. (a -> b) -> a -> b
$ FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. a -> InputFieldsParser MetadataObjId n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
defaultArguments
    | Bool
otherwise -> do
        [InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))]
argumentParsers <- [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> SchemaT
     r
     m
     [InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA ([SchemaT
    r
    m
    (InputFieldsParser
       n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
 -> SchemaT
      r
      m
      [InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))])
-> [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> SchemaT
     r
     m
     [InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))]
forall a b. (a -> b) -> a -> b
$ [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
optional [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
-> [SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
forall a. Semigroup a => a -> a -> a
<> [SchemaT
   r
   m
   (InputFieldsParser
      n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]
mandatory
        Name
objectName <-
          Name -> Name
mkTypename
            (Name -> Name)
-> (GQLNameIdentifier -> Name) -> GQLNameIdentifier -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamingCase -> GQLNameIdentifier -> Name
RQL.applyTypeNameCaseIdentifier NamingCase
tCase
            (GQLNameIdentifier -> Name)
-> SchemaT r m GQLNameIdentifier -> SchemaT r m Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case FunctionTrackedAs 'DataConnector
functionTrackedAs of
              FTAComputedField ComputedFieldName
computedFieldName SourceName
_sourceName TableName 'DataConnector
tableName -> do
                TableInfo 'DataConnector
tableInfo <- TableName 'DataConnector -> SchemaT r m (TableInfo 'DataConnector)
forall (b :: BackendType) r (m :: * -> *).
(Backend b, MonadError QErr m, MonadReader r m,
 Has (SourceInfo b) r) =>
TableName b -> m (TableInfo b)
GS.C.askTableInfo TableName 'DataConnector
tableName
                Name
computedFieldGQLName <- Text -> SchemaT r m Name
forall (m :: * -> *). MonadError QErr m => Text -> m Name
GS.C.textToName (Text -> SchemaT r m Name) -> Text -> SchemaT r m Name
forall a b. (a -> b) -> a -> b
$ ComputedFieldName -> Text
computedFieldNameToText ComputedFieldName
computedFieldName
                GQLNameIdentifier
tableGQLName <- forall (b :: BackendType) (m :: * -> *).
(Backend b, MonadError QErr m) =>
TableInfo b -> m GQLNameIdentifier
GS.T.getTableIdentifierName @'DataConnector TableInfo 'DataConnector
tableInfo
                GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GQLNameIdentifier -> SchemaT r m GQLNameIdentifier)
-> GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a b. (a -> b) -> a -> b
$ Name -> GQLNameIdentifier -> GQLNameIdentifier
RQL.mkFunctionArgsTypeName Name
computedFieldGQLName GQLNameIdentifier
tableGQLName
              FTACustomFunction (CustomFunctionNames {Name
cfnArgsName :: CustomFunctionNames -> Name
cfnArgsName :: Name
cfnArgsName}) ->
                GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GQLNameIdentifier -> SchemaT r m GQLNameIdentifier)
-> GQLNameIdentifier -> SchemaT r m GQLNameIdentifier
forall a b. (a -> b) -> a -> b
$ Name -> GQLNameIdentifier
fromCustomName Name
cfnArgsName
        let fieldName :: Name
fieldName = Name
Name._args
            fieldDesc :: Description
fieldDesc =
              case FunctionTrackedAs 'DataConnector
functionTrackedAs of
                FTAComputedField ComputedFieldName
computedFieldName SourceName
_sourceName TableName 'DataConnector
tableName ->
                  Text -> Description
GQL.Description
                    (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input parameters for computed field "
                    Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ComputedFieldName
computedFieldName
                    ComputedFieldName -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" defined on table "
                    Text -> TableName -> Text
forall t. ToTxt t => Text -> t -> Text
<>> TableName 'DataConnector
TableName
tableName
                FTACustomFunction (CustomFunctionNames {Name
cfnFunctionName :: CustomFunctionNames -> Name
cfnFunctionName :: Name
cfnFunctionName}) ->
                  Text -> Description
GQL.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input parameters for function " Text -> Name -> Text
forall t. ToTxt t => Text -> t -> Text
<>> Name
cfnFunctionName
            objectParser :: Parser
  MetadataObjId
  'Input
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
objectParser =
              Name
-> Maybe Description
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> Parser
     MetadataObjId
     'Input
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
objectName Maybe Description
forall a. Maybe a
Nothing ([InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))]
-> InputFieldsParser
     MetadataObjId
     n
     [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA [InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))]
argumentParsers) Parser
  MetadataObjId
  'Input
  n
  [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> ([Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
    -> n (FunctionArgsExpG
            (ArgumentExp (UnpreparedValue 'DataConnector))))
-> Parser
     MetadataObjId
     'Input
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
forall (m :: * -> *) origin (k :: Kind) a b.
Monad m =>
Parser origin k m a -> (a -> m b) -> Parser origin k m b
`P.bind` \[Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
arguments -> do
                let foundArguments :: HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
foundArguments = [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
 -> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector)))
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
forall a b. (a -> b) -> a -> b
$ [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
arguments [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall a. Semigroup a => a -> a -> a
<> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
session
                    argsWithNames :: [(Text, InputArgument FunctionArg)]
argsWithNames = [Text]
-> [InputArgument FunctionArg]
-> [(Text, InputArgument FunctionArg)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Text]
names [InputArgument FunctionArg]
inputArgs

                -- All args have names in DC for now
                HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
named <- [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
 -> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector)))
-> ([Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
    -> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))])
-> [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> [(Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes ([Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
 -> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector)))
-> n [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
-> n (HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Text, InputArgument FunctionArg)
 -> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
-> [(Text, InputArgument FunctionArg)]
-> n [Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
-> (Text, FunctionInputArgument 'DataConnector)
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
namedArgument HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
foundArguments) [(Text, InputArgument FunctionArg)]
argsWithNames
                FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
-> n (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
 -> n (FunctionArgsExpG
         (ArgumentExp (UnpreparedValue 'DataConnector))))
-> FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
-> n (FunctionArgsExpG
        (ArgumentExp (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ [ArgumentExp (UnpreparedValue 'DataConnector)]
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
-> FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))
forall a. [a] -> HashMap Text a -> FunctionArgsExpG a
RQL.FunctionArgsExp [] HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
named

        InputFieldsParser
  MetadataObjId
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   MetadataObjId
   n
   (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector))))
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> Parser
     MetadataObjId
     'Input
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     MetadataObjId
     n
     (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m a
P.field Name
fieldName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
fieldDesc) Parser
  MetadataObjId
  'Input
  n
  (FunctionArgsExpG (ArgumentExp (UnpreparedValue 'DataConnector)))
objectParser
  where
    sessionPlaceholder :: DC.ArgumentExp (IR.UnpreparedValue b)
    sessionPlaceholder :: forall (b :: BackendType). ArgumentExp (UnpreparedValue b)
sessionPlaceholder = UnpreparedValue b -> ArgumentExp (UnpreparedValue b)
forall a. a -> ArgumentExp a
DC.AEInput UnpreparedValue b
forall (b :: BackendType). UnpreparedValue b
IR.UVSession

    splitArguments ::
      Int ->
      RQL.FunctionInputArgument 'DataConnector ->
      ( Int,
        ( [Text], -- graphql names, in order
          [(Text, DC.ArgumentExp (IR.UnpreparedValue 'DataConnector))], -- session argument
          [GS.C.SchemaT r m (P.InputFieldsParser n (Maybe (Text, DC.ArgumentExp (IR.UnpreparedValue 'DataConnector))))], -- optional argument
          [GS.C.SchemaT r m (P.InputFieldsParser n (Maybe (Text, DC.ArgumentExp (IR.UnpreparedValue 'DataConnector))))] -- mandatory argument
        )
      )
    splitArguments :: Int
-> FunctionInputArgument 'DataConnector
-> (Int,
    ([Text], [(Text, ArgumentExp (UnpreparedValue 'DataConnector))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))],
     [SchemaT
        r
        m
        (InputFieldsParser
           n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))]))
splitArguments Int
positionalIndex (RQL.IASessionVariables FunctionArgName
name) =
      let argName :: Text
argName = FunctionArgName -> Text
RQL.getFuncArgNameTxt FunctionArgName
name
       in (Int
positionalIndex, ([Text
argName], [(Text
argName, ArgumentExp (UnpreparedValue 'DataConnector)
forall (b :: BackendType). ArgumentExp (UnpreparedValue b)
sessionPlaceholder)], [], []))
    splitArguments Int
positionalIndex (RQL.IAUserProvided arg :: FunctionArgument 'DataConnector
arg@(API.FunctionArg Text
faName ScalarType
_faType Bool
_faOptional)) =
      let (Text
argName, Int
newIndex) = (Text
faName, Int
positionalIndex) -- Names are currently always present
       in -- NOTE: Positional defaults are not implemented here, but named arguments should support this.
          -- See:  `if Postgres.unHasDefault $ Postgres.faHasDefault arg`
          (Int
newIndex, ([Text
argName], [], [], [FunctionArgument 'DataConnector
-> Text
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
parseArgument FunctionArgument 'DataConnector
arg Text
argName]))

    parseArgument :: RQL.FunctionArgument 'DataConnector -> Text -> GS.C.SchemaT r m (P.InputFieldsParser n (Maybe (Text, DC.ArgumentExp (IR.UnpreparedValue 'DataConnector))))
    parseArgument :: FunctionArgument 'DataConnector
-> Text
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
parseArgument (API.FunctionArg Text
faName ScalarType
faType Bool
_faOptional) Text
name = do
      Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser <- ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(BackendSchema b, MonadBuildSchema b r m n) =>
ColumnType b
-> Nullability
-> SchemaT r m (Parser 'Both n (ValueWithOrigin (ColumnValue b)))
columnParser (ScalarType 'DataConnector -> ColumnType 'DataConnector
forall (b :: BackendType). ScalarType b -> ColumnType b
RQL.ColumnScalar (ScalarType 'DataConnector -> ColumnType 'DataConnector)
-> ScalarType 'DataConnector -> ColumnType 'DataConnector
forall a b. (a -> b) -> a -> b
$ ScalarType -> ScalarType
forall source target. From source target => source -> target
Witch.from ScalarType
faType) (Bool -> Nullability
GQL.Nullability Bool
True)
      Name
fieldName <- Text -> SchemaT r m Name
forall (m :: * -> *). MonadError QErr m => Text -> m Name
GS.C.textToName Text
name
      let argParser :: InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue 'DataConnector)))
argParser = Name
-> Maybe Description
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (ValueWithOrigin (ColumnValue 'DataConnector)))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
fieldName Maybe Description
forall a. Maybe a
Nothing Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser
      InputFieldsParser
  n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
 -> SchemaT
      r
      m
      (InputFieldsParser
         n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))))
-> InputFieldsParser
     n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
forall a b. (a -> b) -> a -> b
$ InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue 'DataConnector)))
argParser InputFieldsParser
  MetadataObjId
  n
  (Maybe (ValueWithOrigin (ColumnValue 'DataConnector)))
-> (ValueWithOrigin (ColumnValue 'DataConnector)
    -> (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall (m :: * -> *) a b.
Functor m =>
InputFieldsParser m (Maybe a)
-> (a -> b) -> InputFieldsParser m (Maybe b)
`GS.C.mapField` ((Text
faName,) (ArgumentExp (UnpreparedValue 'DataConnector)
 -> (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
-> (ValueWithOrigin (ColumnValue 'DataConnector)
    -> ArgumentExp (UnpreparedValue 'DataConnector))
-> ValueWithOrigin (ColumnValue 'DataConnector)
-> (Text, ArgumentExp (UnpreparedValue 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnpreparedValue 'DataConnector
-> ArgumentExp (UnpreparedValue 'DataConnector)
forall a. a -> ArgumentExp a
DC.AEInput (UnpreparedValue 'DataConnector
 -> ArgumentExp (UnpreparedValue 'DataConnector))
-> (ValueWithOrigin (ColumnValue 'DataConnector)
    -> UnpreparedValue 'DataConnector)
-> ValueWithOrigin (ColumnValue 'DataConnector)
-> ArgumentExp (UnpreparedValue 'DataConnector)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueWithOrigin (ColumnValue 'DataConnector)
-> UnpreparedValue 'DataConnector
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter)

    namedArgument ::
      HashMap Text (DC.ArgumentExp (IR.UnpreparedValue 'DataConnector)) ->
      (Text, RQL.FunctionInputArgument 'DataConnector) ->
      n (Maybe (Text, DC.ArgumentExp (IR.UnpreparedValue 'DataConnector)))
    namedArgument :: HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
-> (Text, FunctionInputArgument 'DataConnector)
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
namedArgument HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
dictionary (Text
name, FunctionInputArgument 'DataConnector
inputArgument) = case FunctionInputArgument 'DataConnector
inputArgument of
      RQL.IASessionVariables FunctionArgName
_ -> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
 -> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
-> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
forall a. a -> Maybe a
Just (Text
name, ArgumentExp (UnpreparedValue 'DataConnector)
forall (b :: BackendType). ArgumentExp (UnpreparedValue b)
sessionPlaceholder)
      RQL.IAUserProvided (API.FunctionArg Text
_faName ScalarType
_faType Bool
faOptional) -> case Text
-> HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
-> Maybe (ArgumentExp (UnpreparedValue 'DataConnector))
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup Text
name HashMap Text (ArgumentExp (UnpreparedValue 'DataConnector))
dictionary of
        Just ArgumentExp (UnpreparedValue 'DataConnector)
parsedValue -> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
 -> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))))
-> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
forall a. a -> Maybe a
Just (Text
name, ArgumentExp (UnpreparedValue 'DataConnector)
parsedValue) -- Names are currently always present
        Maybe (ArgumentExp (UnpreparedValue 'DataConnector))
Nothing ->
          if Bool
faOptional
            then Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. a -> n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector))
forall a. Maybe a
Nothing
            else ParseErrorCode
-> ErrorMessage
-> n (Maybe (Text, ArgumentExp (UnpreparedValue 'DataConnector)))
forall a. ParseErrorCode -> ErrorMessage -> n a
forall (m :: * -> *) a.
MonadParse m =>
ParseErrorCode -> ErrorMessage -> m a
P.parseErrorWith ParseErrorCode
P.NotSupported ErrorMessage
"Non default arguments cannot be omitted"

buildTableInsertMutationFields' ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.MkRootFieldName ->
  GS.C.Scenario ->
  RQL.TableName 'DataConnector ->
  RQL.TableInfo 'DataConnector ->
  GQLNameIdentifier ->
  GS.C.SchemaT r m [P.FieldParser n (IR.AnnotatedInsert 'DataConnector (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue 'DataConnector))]
buildTableInsertMutationFields' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableInsertMutationFields' MkRootFieldName
mkRootFieldName Scenario
scenario TableName 'DataConnector
tableName TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName = do
  API.Capabilities {Maybe Licensing
Maybe UserDefinedFunctionCapabilities
Maybe DatasetCapabilities
Maybe RawCapabilities
Maybe ExplainCapabilities
Maybe MetricsCapabilities
Maybe ComparisonCapabilities
Maybe RelationshipCapabilities
Maybe SubscriptionCapabilities
Maybe MutationCapabilities
Maybe QueryCapabilities
ScalarTypesCapabilities
DataSchemaCapabilities
_cDataSchema :: DataSchemaCapabilities
_cQueries :: Maybe QueryCapabilities
_cMutations :: Maybe MutationCapabilities
_cSubscriptions :: Maybe SubscriptionCapabilities
_cScalarTypes :: ScalarTypesCapabilities
_cRelationships :: Maybe RelationshipCapabilities
_cComparisons :: Maybe ComparisonCapabilities
_cMetrics :: Maybe MetricsCapabilities
_cExplain :: Maybe ExplainCapabilities
_cRaw :: Maybe RawCapabilities
_cDatasets :: Maybe DatasetCapabilities
_cUserDefinedFunctions :: Maybe UserDefinedFunctionCapabilities
_cLicensing :: Maybe Licensing
_cDataSchema :: Capabilities -> DataSchemaCapabilities
_cQueries :: Capabilities -> Maybe QueryCapabilities
_cMutations :: Capabilities -> Maybe MutationCapabilities
_cSubscriptions :: Capabilities -> Maybe SubscriptionCapabilities
_cScalarTypes :: Capabilities -> ScalarTypesCapabilities
_cRelationships :: Capabilities -> Maybe RelationshipCapabilities
_cComparisons :: Capabilities -> Maybe ComparisonCapabilities
_cMetrics :: Capabilities -> Maybe MetricsCapabilities
_cExplain :: Capabilities -> Maybe ExplainCapabilities
_cRaw :: Capabilities -> Maybe RawCapabilities
_cDatasets :: Capabilities -> Maybe DatasetCapabilities
_cUserDefinedFunctions :: Capabilities -> Maybe UserDefinedFunctionCapabilities
_cLicensing :: Capabilities -> Maybe Licensing
..} <- SourceConfig -> Capabilities
DC._scCapabilities (SourceConfig -> Capabilities)
-> (SourceInfo 'DataConnector -> SourceConfig)
-> SourceInfo 'DataConnector
-> Capabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType). SourceInfo b -> SourceConfig b
RQL._siConfiguration @('DataConnector) (SourceInfo 'DataConnector -> Capabilities)
-> SchemaT r m (SourceInfo 'DataConnector)
-> SchemaT r m Capabilities
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  case Maybe MutationCapabilities
_cMutations Maybe MutationCapabilities
-> (MutationCapabilities -> Maybe InsertCapabilities)
-> Maybe InsertCapabilities
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutationCapabilities -> Maybe InsertCapabilities
API._mcInsertCapabilities of
    Just InsertCapabilities
_insertCapabilities -> (TableInfo 'DataConnector
 -> SchemaT
      r
      m
      (InputFieldsParser
         n (BackendInsert 'DataConnector (UnpreparedValue 'DataConnector))))
-> MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, BackendTableSelectSchema b) =>
(TableInfo b
 -> SchemaT
      r m (InputFieldsParser n (BackendInsert b (UnpreparedValue b))))
-> MkRootFieldName
-> Scenario
-> TableName b
-> TableInfo b
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
GS.B.buildTableInsertMutationFields TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert 'DataConnector (UnpreparedValue 'DataConnector)))
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert (UnpreparedValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert (UnpreparedValue 'DataConnector)))
mkBackendInsertParser MkRootFieldName
mkRootFieldName Scenario
scenario TableName 'DataConnector
tableName TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName
    Maybe InsertCapabilities
Nothing -> [FieldParser
   n
   (AnnotatedInsert
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedInsert
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

mkBackendInsertParser ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.TableInfo 'DataConnector ->
  GS.C.SchemaT r m (P.InputFieldsParser n (DC.BackendInsert (IR.UnpreparedValue 'DataConnector)))
mkBackendInsertParser :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert (UnpreparedValue 'DataConnector)))
mkBackendInsertParser TableInfo 'DataConnector
_tableInfo =
  InputFieldsParser
  n (BackendInsert (UnpreparedValue 'DataConnector))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert (UnpreparedValue 'DataConnector)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (InputFieldsParser
   n (BackendInsert (UnpreparedValue 'DataConnector))
 -> SchemaT
      r
      m
      (InputFieldsParser
         n (BackendInsert (UnpreparedValue 'DataConnector))))
-> InputFieldsParser
     n (BackendInsert (UnpreparedValue 'DataConnector))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (BackendInsert (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ BackendInsert (UnpreparedValue 'DataConnector)
-> InputFieldsParser
     n (BackendInsert (UnpreparedValue 'DataConnector))
forall a. a -> InputFieldsParser MetadataObjId n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure BackendInsert (UnpreparedValue 'DataConnector)
forall v. BackendInsert v
DC.BackendInsert

buildTableUpdateMutationFields' ::
  (MonadBuildSchema 'DataConnector r m n) =>
  GS.C.Scenario ->
  RQL.TableInfo 'DataConnector ->
  GQLNameIdentifier ->
  GS.C.SchemaT r m [P.FieldParser n (IR.AnnotatedUpdateG 'DataConnector (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue 'DataConnector))]
buildTableUpdateMutationFields' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableUpdateMutationFields' Scenario
scenario TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName = do
  API.Capabilities {Maybe Licensing
Maybe UserDefinedFunctionCapabilities
Maybe DatasetCapabilities
Maybe RawCapabilities
Maybe ExplainCapabilities
Maybe MetricsCapabilities
Maybe ComparisonCapabilities
Maybe RelationshipCapabilities
Maybe SubscriptionCapabilities
Maybe MutationCapabilities
Maybe QueryCapabilities
ScalarTypesCapabilities
DataSchemaCapabilities
_cDataSchema :: Capabilities -> DataSchemaCapabilities
_cQueries :: Capabilities -> Maybe QueryCapabilities
_cMutations :: Capabilities -> Maybe MutationCapabilities
_cSubscriptions :: Capabilities -> Maybe SubscriptionCapabilities
_cScalarTypes :: Capabilities -> ScalarTypesCapabilities
_cRelationships :: Capabilities -> Maybe RelationshipCapabilities
_cComparisons :: Capabilities -> Maybe ComparisonCapabilities
_cMetrics :: Capabilities -> Maybe MetricsCapabilities
_cExplain :: Capabilities -> Maybe ExplainCapabilities
_cRaw :: Capabilities -> Maybe RawCapabilities
_cDatasets :: Capabilities -> Maybe DatasetCapabilities
_cUserDefinedFunctions :: Capabilities -> Maybe UserDefinedFunctionCapabilities
_cLicensing :: Capabilities -> Maybe Licensing
_cDataSchema :: DataSchemaCapabilities
_cQueries :: Maybe QueryCapabilities
_cMutations :: Maybe MutationCapabilities
_cSubscriptions :: Maybe SubscriptionCapabilities
_cScalarTypes :: ScalarTypesCapabilities
_cRelationships :: Maybe RelationshipCapabilities
_cComparisons :: Maybe ComparisonCapabilities
_cMetrics :: Maybe MetricsCapabilities
_cExplain :: Maybe ExplainCapabilities
_cRaw :: Maybe RawCapabilities
_cDatasets :: Maybe DatasetCapabilities
_cUserDefinedFunctions :: Maybe UserDefinedFunctionCapabilities
_cLicensing :: Maybe Licensing
..} <- SourceConfig -> Capabilities
DC._scCapabilities (SourceConfig -> Capabilities)
-> (SourceInfo 'DataConnector -> SourceConfig)
-> SourceInfo 'DataConnector
-> Capabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType). SourceInfo b -> SourceConfig b
RQL._siConfiguration @('DataConnector) (SourceInfo 'DataConnector -> Capabilities)
-> SchemaT r m (SourceInfo 'DataConnector)
-> SchemaT r m Capabilities
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  case Maybe MutationCapabilities
_cMutations Maybe MutationCapabilities
-> (MutationCapabilities -> Maybe UpdateCapabilities)
-> Maybe UpdateCapabilities
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutationCapabilities -> Maybe UpdateCapabilities
API._mcUpdateCapabilities of
    Just UpdateCapabilities
_updateCapabilities -> do
      [FieldParser
   n
   (AnnotatedUpdateG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
updateRootFields <- (UpdateBatch
   'DataConnector
   (UpdateOperators 'DataConnector)
   (UnpreparedValue 'DataConnector)
 -> UpdateVariant 'DataConnector (UnpreparedValue 'DataConnector))
-> Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b,
 BackendTableSelectSchema b, BackendUpdateOperatorsSchema b) =>
(UpdateBatch b (UpdateOperators b) (UnpreparedValue b)
 -> UpdateVariant b (UnpreparedValue b))
-> Scenario
-> TableInfo b
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
GS.B.buildSingleBatchTableUpdateMutationFields UpdateBatch
  'DataConnector UpdateOperator (UnpreparedValue 'DataConnector)
-> DataConnectorUpdateVariant (UnpreparedValue 'DataConnector)
UpdateBatch
  'DataConnector
  (UpdateOperators 'DataConnector)
  (UnpreparedValue 'DataConnector)
-> UpdateVariant 'DataConnector (UnpreparedValue 'DataConnector)
forall v.
UpdateBatch 'DataConnector UpdateOperator v
-> DataConnectorUpdateVariant v
DC.SingleBatch Scenario
scenario TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName
      Maybe
  (FieldParser
     n
     (AnnotatedUpdateG
        'DataConnector
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue 'DataConnector)))
updateManyRootField <- ([UpdateBatch
    'DataConnector
    (UpdateOperators 'DataConnector)
    (UnpreparedValue 'DataConnector)]
 -> UpdateVariant 'DataConnector (UnpreparedValue 'DataConnector))
-> Scenario
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedUpdateG
              'DataConnector
              (RemoteRelationshipField UnpreparedValue)
              (UnpreparedValue 'DataConnector))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b,
 BackendTableSelectSchema b, BackendUpdateOperatorsSchema b) =>
([UpdateBatch b (UpdateOperators b) (UnpreparedValue b)]
 -> UpdateVariant b (UnpreparedValue b))
-> Scenario
-> TableInfo b
-> GQLNameIdentifier
-> SchemaT
     r
     m
     (Maybe
        (FieldParser
           n
           (AnnotatedUpdateG
              b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))))
GS.U.B.updateTableMany [UpdateBatch
   'DataConnector UpdateOperator (UnpreparedValue 'DataConnector)]
-> DataConnectorUpdateVariant (UnpreparedValue 'DataConnector)
[UpdateBatch
   'DataConnector
   (UpdateOperators 'DataConnector)
   (UnpreparedValue 'DataConnector)]
-> UpdateVariant 'DataConnector (UnpreparedValue 'DataConnector)
forall v.
[UpdateBatch 'DataConnector UpdateOperator v]
-> DataConnectorUpdateVariant v
DC.MultipleBatches Scenario
scenario TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName
      [FieldParser
   n
   (AnnotatedUpdateG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([FieldParser
    n
    (AnnotatedUpdateG
       'DataConnector
       (RemoteRelationshipField UnpreparedValue)
       (UnpreparedValue 'DataConnector))]
 -> SchemaT
      r
      m
      [FieldParser
         n
         (AnnotatedUpdateG
            'DataConnector
            (RemoteRelationshipField UnpreparedValue)
            (UnpreparedValue 'DataConnector))])
-> [FieldParser
      n
      (AnnotatedUpdateG
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a b. (a -> b) -> a -> b
$ [FieldParser
   n
   (AnnotatedUpdateG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
updateRootFields [FieldParser
   n
   (AnnotatedUpdateG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> [FieldParser
      n
      (AnnotatedUpdateG
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector))]
-> [FieldParser
      n
      (AnnotatedUpdateG
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector))]
forall a. [a] -> [a] -> [a]
++ (Maybe
  (FieldParser
     n
     (AnnotatedUpdateG
        'DataConnector
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue 'DataConnector)))
-> [FieldParser
      n
      (AnnotatedUpdateG
         'DataConnector
         (RemoteRelationshipField UnpreparedValue)
         (UnpreparedValue 'DataConnector))]
forall a. Maybe a -> [a]
maybeToList Maybe
  (FieldParser
     n
     (AnnotatedUpdateG
        'DataConnector
        (RemoteRelationshipField UnpreparedValue)
        (UnpreparedValue 'DataConnector)))
updateManyRootField)
    Maybe UpdateCapabilities
Nothing -> [FieldParser
   n
   (AnnotatedUpdateG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnotatedUpdateG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

parseUpdateOperators' ::
  forall m n r.
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.TableInfo 'DataConnector ->
  RQL.UpdPermInfo 'DataConnector ->
  GS.C.SchemaT r m (P.InputFieldsParser n (HashMap (RQL.Column 'DataConnector) (DC.UpdateOperator (IR.UnpreparedValue 'DataConnector))))
parseUpdateOperators' :: forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> UpdPermInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperator (UnpreparedValue 'DataConnector))))
parseUpdateOperators' TableInfo 'DataConnector
tableInfo UpdPermInfo 'DataConnector
updatePermissions = do
  Capabilities
capabilities <- SourceConfig -> Capabilities
DC._scCapabilities (SourceConfig -> Capabilities)
-> (SourceInfo 'DataConnector -> SourceConfig)
-> SourceInfo 'DataConnector
-> Capabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType). SourceInfo b -> SourceConfig b
RQL._siConfiguration @('DataConnector) (SourceInfo 'DataConnector -> Capabilities)
-> SchemaT r m (SourceInfo 'DataConnector)
-> SchemaT r m Capabilities
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  let scalarTypeCapabilities :: HashMap ScalarType ScalarTypeCapabilities
scalarTypeCapabilities = ScalarTypesCapabilities
-> HashMap ScalarType ScalarTypeCapabilities
API.unScalarTypesCapabilities (ScalarTypesCapabilities
 -> HashMap ScalarType ScalarTypeCapabilities)
-> (Capabilities -> ScalarTypesCapabilities)
-> Capabilities
-> HashMap ScalarType ScalarTypeCapabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Capabilities -> ScalarTypesCapabilities
API._cScalarTypes (Capabilities -> HashMap ScalarType ScalarTypeCapabilities)
-> Capabilities -> HashMap ScalarType ScalarTypeCapabilities
forall a b. (a -> b) -> a -> b
$ Capabilities
capabilities
  -- Group all the custom operators by operator name
  let customOperatorCapabilities :: HashMap
  UpdateColumnOperatorName
  (HashMap ScalarType UpdateColumnOperatorDefinition)
customOperatorCapabilities =
        HashMap ScalarType ScalarTypeCapabilities
scalarTypeCapabilities
          HashMap ScalarType ScalarTypeCapabilities
-> (HashMap ScalarType ScalarTypeCapabilities
    -> [(ScalarType, ScalarTypeCapabilities)])
-> [(ScalarType, ScalarTypeCapabilities)]
forall a b. a -> (a -> b) -> b
& HashMap ScalarType ScalarTypeCapabilities
-> [(ScalarType, ScalarTypeCapabilities)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
          [(ScalarType, ScalarTypeCapabilities)]
-> ((ScalarType, ScalarTypeCapabilities)
    -> [HashMap
          UpdateColumnOperatorName
          (HashMap ScalarType UpdateColumnOperatorDefinition)])
-> [HashMap
      UpdateColumnOperatorName
      (HashMap ScalarType UpdateColumnOperatorDefinition)]
forall a b. [a] -> (a -> [b]) -> [b]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ( \(ScalarType
scalarType, API.ScalarTypeCapabilities {Maybe GraphQLType
UpdateColumnOperators
AggregateFunctions
ComparisonOperators
_stcComparisonOperators :: ComparisonOperators
_stcAggregateFunctions :: AggregateFunctions
_stcUpdateColumnOperators :: UpdateColumnOperators
_stcGraphQLType :: Maybe GraphQLType
_stcComparisonOperators :: ScalarTypeCapabilities -> ComparisonOperators
_stcAggregateFunctions :: ScalarTypeCapabilities -> AggregateFunctions
_stcUpdateColumnOperators :: ScalarTypeCapabilities -> UpdateColumnOperators
_stcGraphQLType :: ScalarTypeCapabilities -> Maybe GraphQLType
..}) ->
                  let scalarType' :: ScalarType
scalarType' = ScalarType -> ScalarType
forall source target. From source target => source -> target
Witch.from ScalarType
scalarType
                   in UpdateColumnOperators
-> HashMap UpdateColumnOperatorName UpdateColumnOperatorDefinition
API.unUpdateColumnOperators UpdateColumnOperators
_stcUpdateColumnOperators
                        HashMap UpdateColumnOperatorName UpdateColumnOperatorDefinition
-> (HashMap UpdateColumnOperatorName UpdateColumnOperatorDefinition
    -> [(UpdateColumnOperatorName, UpdateColumnOperatorDefinition)])
-> [(UpdateColumnOperatorName, UpdateColumnOperatorDefinition)]
forall a b. a -> (a -> b) -> b
& HashMap UpdateColumnOperatorName UpdateColumnOperatorDefinition
-> [(UpdateColumnOperatorName, UpdateColumnOperatorDefinition)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
                        [(UpdateColumnOperatorName, UpdateColumnOperatorDefinition)]
-> ((UpdateColumnOperatorName, UpdateColumnOperatorDefinition)
    -> HashMap
         UpdateColumnOperatorName
         (HashMap ScalarType UpdateColumnOperatorDefinition))
-> [HashMap
      UpdateColumnOperatorName
      (HashMap ScalarType UpdateColumnOperatorDefinition)]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\(UpdateColumnOperatorName
operatorName, UpdateColumnOperatorDefinition
operatorDefinition) -> UpdateColumnOperatorName
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> HashMap
     UpdateColumnOperatorName
     (HashMap ScalarType UpdateColumnOperatorDefinition)
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton UpdateColumnOperatorName
operatorName (ScalarType
-> UpdateColumnOperatorDefinition
-> HashMap ScalarType UpdateColumnOperatorDefinition
forall k v. Hashable k => k -> v -> HashMap k v
HashMap.singleton ScalarType
scalarType' UpdateColumnOperatorDefinition
operatorDefinition))
              )
          [HashMap
   UpdateColumnOperatorName
   (HashMap ScalarType UpdateColumnOperatorDefinition)]
-> ([HashMap
       UpdateColumnOperatorName
       (HashMap ScalarType UpdateColumnOperatorDefinition)]
    -> HashMap
         UpdateColumnOperatorName
         (HashMap ScalarType UpdateColumnOperatorDefinition))
-> HashMap
     UpdateColumnOperatorName
     (HashMap ScalarType UpdateColumnOperatorDefinition)
forall a b. a -> (a -> b) -> b
& (HashMap ScalarType UpdateColumnOperatorDefinition
 -> HashMap ScalarType UpdateColumnOperatorDefinition
 -> HashMap ScalarType UpdateColumnOperatorDefinition)
-> [HashMap
      UpdateColumnOperatorName
      (HashMap ScalarType UpdateColumnOperatorDefinition)]
-> HashMap
     UpdateColumnOperatorName
     (HashMap ScalarType UpdateColumnOperatorDefinition)
forall k (t :: * -> *) v.
(Hashable k, Foldable t) =>
(v -> v -> v) -> t (HashMap k v) -> HashMap k v
HashMap.unionsWith HashMap ScalarType UpdateColumnOperatorDefinition
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> HashMap ScalarType UpdateColumnOperatorDefinition
forall a. Semigroup a => a -> a -> a
(<>)
  let customOperators :: [UpdateOperator
   'DataConnector
   r
   m
   n
   (UpdateOperator (UnpreparedValue 'DataConnector))]
customOperators =
        HashMap
  UpdateColumnOperatorName
  (HashMap ScalarType UpdateColumnOperatorDefinition)
customOperatorCapabilities
          HashMap
  UpdateColumnOperatorName
  (HashMap ScalarType UpdateColumnOperatorDefinition)
-> (HashMap
      UpdateColumnOperatorName
      (HashMap ScalarType UpdateColumnOperatorDefinition)
    -> [(UpdateColumnOperatorName,
         HashMap ScalarType UpdateColumnOperatorDefinition)])
-> [(UpdateColumnOperatorName,
     HashMap ScalarType UpdateColumnOperatorDefinition)]
forall a b. a -> (a -> b) -> b
& HashMap
  UpdateColumnOperatorName
  (HashMap ScalarType UpdateColumnOperatorDefinition)
-> [(UpdateColumnOperatorName,
     HashMap ScalarType UpdateColumnOperatorDefinition)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
          [(UpdateColumnOperatorName,
  HashMap ScalarType UpdateColumnOperatorDefinition)]
-> ((UpdateColumnOperatorName,
     HashMap ScalarType UpdateColumnOperatorDefinition)
    -> UpdateOperator
         'DataConnector
         r
         m
         n
         (UpdateOperator (UnpreparedValue 'DataConnector)))
-> [UpdateOperator
      'DataConnector
      r
      m
      n
      (UpdateOperator (UnpreparedValue 'DataConnector))]
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\(UpdateColumnOperatorName
operatorName, HashMap ScalarType UpdateColumnOperatorDefinition
operatorUsages) -> UpdateColumnOperatorName
-> UnpreparedValue 'DataConnector
-> UpdateOperator (UnpreparedValue 'DataConnector)
forall v. UpdateColumnOperatorName -> v -> UpdateOperator v
DC.UpdateCustomOperator UpdateColumnOperatorName
operatorName (UnpreparedValue 'DataConnector
 -> UpdateOperator (UnpreparedValue 'DataConnector))
-> UpdateOperator
     'DataConnector r m n (UnpreparedValue 'DataConnector)
-> UpdateOperator
     'DataConnector
     r
     m
     n
     (UpdateOperator (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UpdateColumnOperatorName
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> UpdateOperator
     'DataConnector r m n (UnpreparedValue 'DataConnector)
forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
UpdateColumnOperatorName
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> UpdateOperator
     'DataConnector r m n (UnpreparedValue 'DataConnector)
updateCustomOp UpdateColumnOperatorName
operatorName HashMap ScalarType UpdateColumnOperatorDefinition
operatorUsages)
  HashMap
  (Column 'DataConnector)
  (UpdateOperator (UnpreparedValue 'DataConnector))
-> [UpdateOperator
      'DataConnector
      r
      m
      n
      (UpdateOperator (UnpreparedValue 'DataConnector))]
-> TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap
           (Column 'DataConnector)
           (UpdateOperator (UnpreparedValue 'DataConnector))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *) op.
MonadBuildSchema b r m n =>
HashMap (Column b) op
-> [UpdateOperator b r m n op]
-> TableInfo b
-> SchemaT r m (InputFieldsParser n (HashMap (Column b) op))
GS.U.buildUpdateOperators
    (UnpreparedValue 'DataConnector
-> UpdateOperator (UnpreparedValue 'DataConnector)
forall v. v -> UpdateOperator v
DC.UpdateSet (UnpreparedValue 'DataConnector
 -> UpdateOperator (UnpreparedValue 'DataConnector))
-> HashMap ColumnName (UnpreparedValue 'DataConnector)
-> HashMap
     ColumnName (UpdateOperator (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UpdPermInfo 'DataConnector
-> HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)
forall (b :: BackendType).
UpdPermInfo b -> HashMap (Column b) (UnpreparedValue b)
GS.U.presetColumns UpdPermInfo 'DataConnector
updatePermissions)
    ((UnpreparedValue 'DataConnector
-> UpdateOperator (UnpreparedValue 'DataConnector)
forall v. v -> UpdateOperator v
DC.UpdateSet (UnpreparedValue 'DataConnector
 -> UpdateOperator (UnpreparedValue 'DataConnector))
-> UpdateOperator
     'DataConnector r m n (UnpreparedValue 'DataConnector)
-> UpdateOperator
     'DataConnector
     r
     m
     n
     (UpdateOperator (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UpdateOperator
  'DataConnector r m n (UnpreparedValue 'DataConnector)
forall (b :: BackendType) (n :: * -> *) r (m :: * -> *).
MonadBuildSchema b r m n =>
UpdateOperator b r m n (UnpreparedValue b)
GS.U.setOp) UpdateOperator
  'DataConnector
  r
  m
  n
  (UpdateOperator (UnpreparedValue 'DataConnector))
-> [UpdateOperator
      'DataConnector
      r
      m
      n
      (UpdateOperator (UnpreparedValue 'DataConnector))]
-> [UpdateOperator
      'DataConnector
      r
      m
      n
      (UpdateOperator (UnpreparedValue 'DataConnector))]
forall a. a -> [a] -> [a]
: [UpdateOperator
   'DataConnector
   r
   m
   n
   (UpdateOperator (UnpreparedValue 'DataConnector))]
customOperators)
    TableInfo 'DataConnector
tableInfo

updateCustomOp ::
  forall m n r.
  (MonadBuildSchema 'DataConnector r m n) =>
  API.UpdateColumnOperatorName ->
  HashMap DC.ScalarType API.UpdateColumnOperatorDefinition ->
  GS.U.UpdateOperator 'DataConnector r m n (IR.UnpreparedValue 'DataConnector)
updateCustomOp :: forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
UpdateColumnOperatorName
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> UpdateOperator
     'DataConnector r m n (UnpreparedValue 'DataConnector)
updateCustomOp (API.UpdateColumnOperatorName Name
operatorName) HashMap ScalarType UpdateColumnOperatorDefinition
operatorUsages = GS.U.UpdateOperator {GQLNameIdentifier
-> TableName 'DataConnector
-> NonEmpty (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)))
ColumnInfo 'DataConnector -> Bool
updateOperatorApplicableColumn :: ColumnInfo 'DataConnector -> Bool
updateOperatorParser :: GQLNameIdentifier
-> TableName 'DataConnector
-> NonEmpty (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)))
updateOperatorApplicableColumn :: ColumnInfo 'DataConnector -> Bool
updateOperatorParser :: GQLNameIdentifier
-> TableName 'DataConnector
-> NonEmpty (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)))
..}
  where
    extractColumnScalarType :: RQL.ColumnInfo 'DataConnector -> Maybe DC.ScalarType
    extractColumnScalarType :: ColumnInfo 'DataConnector -> Maybe ScalarType
extractColumnScalarType RQL.ColumnInfo {Bool
Int
Maybe Description
Name
Column 'DataConnector
ColumnType 'DataConnector
ColumnMutability
ciColumn :: Column 'DataConnector
ciName :: Name
ciPosition :: Int
ciType :: ColumnType 'DataConnector
ciIsNullable :: Bool
ciDescription :: Maybe Description
ciMutability :: ColumnMutability
ciColumn :: forall (b :: BackendType). ColumnInfo b -> Column b
ciName :: forall (b :: BackendType). ColumnInfo b -> Name
ciPosition :: forall (b :: BackendType). ColumnInfo b -> Int
ciType :: forall (b :: BackendType). ColumnInfo b -> ColumnType b
ciIsNullable :: forall (b :: BackendType). ColumnInfo b -> Bool
ciDescription :: forall (b :: BackendType). ColumnInfo b -> Maybe Description
ciMutability :: forall (b :: BackendType). ColumnInfo b -> ColumnMutability
..} =
      case ColumnType 'DataConnector
ciType of
        RQL.ColumnScalar ScalarType 'DataConnector
columnScalarType -> ScalarType -> Maybe ScalarType
forall a. a -> Maybe a
Just ScalarType 'DataConnector
ScalarType
columnScalarType
        RQL.ColumnEnumReference EnumReference 'DataConnector
_enumReference -> Maybe ScalarType
forall a. Maybe a
Nothing

    updateOperatorApplicableColumn :: RQL.ColumnInfo 'DataConnector -> Bool
    updateOperatorApplicableColumn :: ColumnInfo 'DataConnector -> Bool
updateOperatorApplicableColumn ColumnInfo 'DataConnector
columnInfo =
      -- ColumnEnumReferences are not supported at this time
      ColumnInfo 'DataConnector -> Maybe ScalarType
extractColumnScalarType ColumnInfo 'DataConnector
columnInfo
        Maybe ScalarType -> (ScalarType -> Bool) -> Maybe Bool
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\ScalarType
columnScalarType -> ScalarType
-> HashMap ScalarType UpdateColumnOperatorDefinition -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
HashMap.member ScalarType
columnScalarType HashMap ScalarType UpdateColumnOperatorDefinition
operatorUsages)
        Maybe Bool -> (Maybe Bool -> Bool) -> Bool
forall a b. a -> (a -> b) -> b
& Bool -> Maybe Bool -> Bool
forall a. a -> Maybe a -> a
fromMaybe Bool
False

    -- Prepend the operator name with underscore
    operatorGraphqlFieldIdentifier :: GQLNameIdentifier
    operatorGraphqlFieldIdentifier :: GQLNameIdentifier
operatorGraphqlFieldIdentifier =
      Name -> GQLNameIdentifier
fromAutogeneratedName (Name -> GQLNameIdentifier) -> Name -> GQLNameIdentifier
forall a b. (a -> b) -> a -> b
$ Name -> [NameSuffix] -> Name
GQL.addSuffixes $$(GQL.litName "_") [Name -> NameSuffix
GQL.convertNameToSuffix Name
operatorName]

    updateOperatorParser ::
      GQLNameIdentifier ->
      RQL.TableName 'DataConnector ->
      NonEmpty (RQL.ColumnInfo 'DataConnector) ->
      GS.C.SchemaT r m (P.InputFieldsParser n (HashMap (RQL.Column 'DataConnector) (IR.UnpreparedValue 'DataConnector)))
    updateOperatorParser :: GQLNameIdentifier
-> TableName 'DataConnector
-> NonEmpty (ColumnInfo 'DataConnector)
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)))
updateOperatorParser GQLNameIdentifier
tableGQLName TableName 'DataConnector
tableName NonEmpty (ColumnInfo 'DataConnector)
columns = do
      let operatorIdentifier :: GQLNameIdentifier
operatorIdentifier = Name -> GQLNameIdentifier
fromAutogeneratedName Name
operatorName

      let typedParser :: RQL.ColumnInfo 'DataConnector -> GS.C.SchemaT r m (P.Parser 'P.Both n (IR.UnpreparedValue 'DataConnector))
          typedParser :: ColumnInfo 'DataConnector
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
typedParser ColumnInfo 'DataConnector
columnInfo = do
            ScalarType
columnScalarType <- ColumnInfo 'DataConnector -> Maybe ScalarType
extractColumnScalarType ColumnInfo 'DataConnector
columnInfo Maybe ScalarType
-> SchemaT r m ScalarType -> SchemaT r m ScalarType
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
`onNothing` Code -> Text -> SchemaT r m ScalarType
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"updateOperatorParser: Enum column types not supported"
            ColumnType 'DataConnector
argumentType <-
              ( ScalarType
-> HashMap ScalarType UpdateColumnOperatorDefinition
-> Maybe UpdateColumnOperatorDefinition
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup ScalarType
columnScalarType HashMap ScalarType UpdateColumnOperatorDefinition
operatorUsages
                  Maybe UpdateColumnOperatorDefinition
-> (UpdateColumnOperatorDefinition -> ColumnType 'DataConnector)
-> Maybe (ColumnType 'DataConnector)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (\API.UpdateColumnOperatorDefinition {ScalarType
_ucodArgumentType :: ScalarType
_ucodArgumentType :: UpdateColumnOperatorDefinition -> ScalarType
..} -> ScalarType 'DataConnector -> ColumnType 'DataConnector
forall (b :: BackendType). ScalarType b -> ColumnType b
RQL.ColumnScalar (ScalarType 'DataConnector -> ColumnType 'DataConnector)
-> ScalarType 'DataConnector -> ColumnType 'DataConnector
forall a b. (a -> b) -> a -> b
$ ScalarType -> ScalarType
forall source target. From source target => source -> target
Witch.from ScalarType
_ucodArgumentType)
                )
                -- This shouldn't happen 😬 because updateOperatorApplicableColumn should protect this
                -- parser from being used with unsupported column types
                Maybe (ColumnType 'DataConnector)
-> SchemaT r m (ColumnType 'DataConnector)
-> SchemaT r m (ColumnType 'DataConnector)
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
`onNothing` Text -> SchemaT r m (ColumnType 'DataConnector)
forall (m :: * -> *) a. QErrM m => Text -> m a
throw500 (Text
"updateOperatorParser: Unable to find argument type for update column operator " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
forall a. ToTxt a => a -> Text
toTxt Name
operatorName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" used with column scalar type " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ScalarType -> Text
forall a. ToTxt a => a -> Text
toTxt ScalarType
columnScalarType)

            (ValueWithOrigin (ColumnValue 'DataConnector)
 -> UnpreparedValue 'DataConnector)
-> Parser
     MetadataObjId
     'Both
     n
     (ValueWithOrigin (ColumnValue 'DataConnector))
-> Parser 'Both n (UnpreparedValue 'DataConnector)
forall a b.
(a -> b)
-> Parser MetadataObjId 'Both n a -> Parser MetadataObjId 'Both n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueWithOrigin (ColumnValue 'DataConnector)
-> UnpreparedValue 'DataConnector
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter
              (Parser
   MetadataObjId
   'Both
   n
   (ValueWithOrigin (ColumnValue 'DataConnector))
 -> Parser 'Both n (UnpreparedValue 'DataConnector))
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Both
        n
        (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r
     m
     (Parser
        MetadataObjId
        'Both
        n
        (ValueWithOrigin (ColumnValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser'
                ColumnType 'DataConnector
argumentType
                (Bool -> Nullability
GQL.Nullability (Bool -> Nullability) -> Bool -> Nullability
forall a b. (a -> b) -> a -> b
$ ColumnInfo 'DataConnector -> Bool
forall (b :: BackendType). ColumnInfo b -> Bool
RQL.ciIsNullable ColumnInfo 'DataConnector
columnInfo)

      GQLNameIdentifier
-> GQLNameIdentifier
-> GQLNameIdentifier
-> (ColumnInfo 'DataConnector
    -> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector)))
-> NonEmpty (ColumnInfo 'DataConnector)
-> Description
-> Description
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (HashMap (Column 'DataConnector) (UnpreparedValue 'DataConnector)))
forall (n :: * -> *) r (m :: * -> *) (b :: BackendType) a.
MonadBuildSchema b r m n =>
GQLNameIdentifier
-> GQLNameIdentifier
-> GQLNameIdentifier
-> (ColumnInfo b -> SchemaT r m (Parser 'Both n a))
-> NonEmpty (ColumnInfo b)
-> Description
-> Description
-> SchemaT r m (InputFieldsParser n (HashMap (Column b) a))
GS.U.updateOperator
        GQLNameIdentifier
tableGQLName
        GQLNameIdentifier
operatorIdentifier
        GQLNameIdentifier
operatorGraphqlFieldIdentifier
        ColumnInfo 'DataConnector
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
typedParser
        NonEmpty (ColumnInfo 'DataConnector)
columns
        (Text -> Description
GQL.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"applies the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
forall a. ToTxt a => a -> Text
toTxt Name
operatorName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" operator with the given values to the specified columns")
        (Text -> Description
GQL.Description (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"input type for applying the " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Name -> Text
forall a. ToTxt a => a -> Text
toTxt Name
operatorName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" operator to columns in table " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> TableName -> Text
forall a. ToTxt a => a -> Text
toTxt TableName 'DataConnector
TableName
tableName)

buildTableDeleteMutationFields' ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.MkRootFieldName ->
  GS.C.Scenario ->
  RQL.TableName 'DataConnector ->
  RQL.TableInfo 'DataConnector ->
  GQLNameIdentifier ->
  GS.C.SchemaT r m [P.FieldParser n (IR.AnnDelG 'DataConnector (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue 'DataConnector))]
buildTableDeleteMutationFields' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
buildTableDeleteMutationFields' MkRootFieldName
mkRootFieldName Scenario
scenario TableName 'DataConnector
tableName TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName = do
  API.Capabilities {Maybe Licensing
Maybe UserDefinedFunctionCapabilities
Maybe DatasetCapabilities
Maybe RawCapabilities
Maybe ExplainCapabilities
Maybe MetricsCapabilities
Maybe ComparisonCapabilities
Maybe RelationshipCapabilities
Maybe SubscriptionCapabilities
Maybe MutationCapabilities
Maybe QueryCapabilities
ScalarTypesCapabilities
DataSchemaCapabilities
_cDataSchema :: Capabilities -> DataSchemaCapabilities
_cQueries :: Capabilities -> Maybe QueryCapabilities
_cMutations :: Capabilities -> Maybe MutationCapabilities
_cSubscriptions :: Capabilities -> Maybe SubscriptionCapabilities
_cScalarTypes :: Capabilities -> ScalarTypesCapabilities
_cRelationships :: Capabilities -> Maybe RelationshipCapabilities
_cComparisons :: Capabilities -> Maybe ComparisonCapabilities
_cMetrics :: Capabilities -> Maybe MetricsCapabilities
_cExplain :: Capabilities -> Maybe ExplainCapabilities
_cRaw :: Capabilities -> Maybe RawCapabilities
_cDatasets :: Capabilities -> Maybe DatasetCapabilities
_cUserDefinedFunctions :: Capabilities -> Maybe UserDefinedFunctionCapabilities
_cLicensing :: Capabilities -> Maybe Licensing
_cDataSchema :: DataSchemaCapabilities
_cQueries :: Maybe QueryCapabilities
_cMutations :: Maybe MutationCapabilities
_cSubscriptions :: Maybe SubscriptionCapabilities
_cScalarTypes :: ScalarTypesCapabilities
_cRelationships :: Maybe RelationshipCapabilities
_cComparisons :: Maybe ComparisonCapabilities
_cMetrics :: Maybe MetricsCapabilities
_cExplain :: Maybe ExplainCapabilities
_cRaw :: Maybe RawCapabilities
_cDatasets :: Maybe DatasetCapabilities
_cUserDefinedFunctions :: Maybe UserDefinedFunctionCapabilities
_cLicensing :: Maybe Licensing
..} <- SourceConfig -> Capabilities
DC._scCapabilities (SourceConfig -> Capabilities)
-> (SourceInfo 'DataConnector -> SourceConfig)
-> SourceInfo 'DataConnector
-> Capabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (b :: BackendType). SourceInfo b -> SourceConfig b
RQL._siConfiguration @('DataConnector) (SourceInfo 'DataConnector -> Capabilities)
-> SchemaT r m (SourceInfo 'DataConnector)
-> SchemaT r m Capabilities
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  case Maybe MutationCapabilities
_cMutations Maybe MutationCapabilities
-> (MutationCapabilities -> Maybe DeleteCapabilities)
-> Maybe DeleteCapabilities
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= MutationCapabilities -> Maybe DeleteCapabilities
API._mcDeleteCapabilities of
    Just DeleteCapabilities
_deleteCapabilities -> MkRootFieldName
-> Scenario
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(MonadBuildSchema b r m n, AggregationPredicatesSchema b,
 BackendTableSelectSchema b) =>
MkRootFieldName
-> Scenario
-> TableName b
-> TableInfo b
-> GQLNameIdentifier
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
GS.B.buildTableDeleteMutationFields MkRootFieldName
mkRootFieldName Scenario
scenario TableName 'DataConnector
tableName TableInfo 'DataConnector
tableInfo GQLNameIdentifier
gqlName
    Maybe DeleteCapabilities
Nothing -> [FieldParser
   n
   (AnnDelG
      'DataConnector
      (RemoteRelationshipField UnpreparedValue)
      (UnpreparedValue 'DataConnector))]
-> SchemaT
     r
     m
     [FieldParser
        n
        (AnnDelG
           'DataConnector
           (RemoteRelationshipField UnpreparedValue)
           (UnpreparedValue 'DataConnector))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

experimentalBuildTableRelayQueryFields ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.MkRootFieldName ->
  RQL.TableName 'DataConnector ->
  RQL.TableInfo 'DataConnector ->
  GQLNameIdentifier ->
  NESeq (RQL.ColumnInfo 'DataConnector) ->
  GS.C.SchemaT r m [P.FieldParser n a]
experimentalBuildTableRelayQueryFields :: forall r (m :: * -> *) (n :: * -> *) a.
MonadBuildSchema 'DataConnector r m n =>
MkRootFieldName
-> TableName 'DataConnector
-> TableInfo 'DataConnector
-> GQLNameIdentifier
-> NESeq (ColumnInfo 'DataConnector)
-> SchemaT r m [FieldParser n a]
experimentalBuildTableRelayQueryFields MkRootFieldName
_mkRootFieldName TableName 'DataConnector
_tableName TableInfo 'DataConnector
_tableInfo GQLNameIdentifier
_gqlName NESeq (ColumnInfo 'DataConnector)
_pkeyColumns =
  [FieldParser n a] -> SchemaT r m [FieldParser n a]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []

columnParser' ::
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.ColumnType 'DataConnector ->
  GQL.Nullability ->
  GS.C.SchemaT r m (P.Parser 'P.Both n (IR.ValueWithOrigin (RQL.ColumnValue 'DataConnector)))
columnParser' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser' ColumnType 'DataConnector
columnType Nullability
nullability = case ColumnType 'DataConnector
columnType of
  RQL.ColumnScalar scalarType :: ScalarType 'DataConnector
scalarType@(DC.ScalarType Text
name) ->
    Name
-> (ScalarType, Nullability)
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
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)
P.memoizeOn 'columnParser' (ScalarType 'DataConnector
ScalarType
scalarType, Nullability
nullability)
      (SchemaT
   r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
 -> SchemaT
      r
      m
      (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))))
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ Parser 'Both n (ColumnValue 'DataConnector)
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
forall (m :: * -> *) a.
MonadParse m =>
Parser 'Both m a -> Parser 'Both m (ValueWithOrigin a)
GS.C.peelWithOrigin
      (Parser 'Both n (ColumnValue 'DataConnector)
 -> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> (Parser 'Both n Value
    -> Parser 'Both n (ColumnValue 'DataConnector))
-> Parser 'Both n Value
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Value -> ColumnValue 'DataConnector)
-> Parser 'Both n Value
-> Parser 'Both n (ColumnValue 'DataConnector)
forall a b.
(a -> b)
-> Parser MetadataObjId 'Both n a -> Parser MetadataObjId 'Both n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ColumnType 'DataConnector
-> ScalarValue 'DataConnector -> ColumnValue 'DataConnector
forall (b :: BackendType).
ColumnType b -> ScalarValue b -> ColumnValue b
RQL.ColumnValue ColumnType 'DataConnector
columnType)
      (Parser 'Both n Value
 -> Parser 'Both n (ColumnValue 'DataConnector))
-> (Parser 'Both n Value -> Parser 'Both n Value)
-> Parser 'Both n Value
-> Parser 'Both n (ColumnValue 'DataConnector)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScalarType 'DataConnector
-> Nullability -> Parser 'Both n Value -> Parser 'Both n Value
forall (m :: * -> *).
MonadParse m =>
ScalarType 'DataConnector
-> Nullability -> Parser 'Both m Value -> Parser 'Both m Value
possiblyNullable' ScalarType 'DataConnector
scalarType Nullability
nullability
      (Parser 'Both n Value
 -> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT r m (Parser 'Both n Value)
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
        Name
gqlName <-
          Text -> Maybe Name
GQL.mkName Text
name
            Maybe Name -> SchemaT r m Name -> SchemaT r m Name
forall (m :: * -> *) a. Applicative m => Maybe a -> m a -> m a
`onNothing` Code -> Text -> SchemaT r m Name
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
ValidationFailed (Text
"The column type name " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name Text -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
" is not a valid GraphQL name")
        ScalarTypesCapabilities
scalarTypesCapabilities <- forall (b :: BackendType) r (m :: * -> *).
(MonadReader r m, Has (SourceInfo b) r,
 Has (ScalarTypeParsingContext b) (SourceConfig b)) =>
m (ScalarTypeParsingContext b)
GS.C.askScalarTypeParsingContext @'DataConnector
        let graphQLType :: Maybe GraphQLType
graphQLType = ScalarTypesCapabilities -> ScalarType -> Maybe GraphQLType
lookupGraphQLType ScalarTypesCapabilities
scalarTypesCapabilities ScalarType 'DataConnector
ScalarType
scalarType
        Parser 'Both n Value -> SchemaT r m (Parser 'Both n Value)
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Parser 'Both n Value -> SchemaT r m (Parser 'Both n Value))
-> Parser 'Both n Value -> SchemaT r m (Parser 'Both n Value)
forall a b. (a -> b) -> a -> b
$ case Maybe GraphQLType
graphQLType of
          Maybe GraphQLType
Nothing -> Name -> Maybe Description -> Parser 'Both n Value
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Maybe Description -> Parser origin 'Both m Value
P.jsonScalar Name
gqlName (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
"A custom scalar type")
          Just GraphQLType
DC.GraphQLInt -> (Scientific -> Value
J.Number (Scientific -> Value) -> (Int32 -> Scientific) -> Int32 -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Scientific
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (Int32 -> Value)
-> Parser MetadataObjId 'Both n Int32 -> Parser 'Both n Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Parser MetadataObjId 'Both n Int32
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Parser origin 'Both m Int32
P.namedInt Name
gqlName
          Just GraphQLType
DC.GraphQLFloat -> (Scientific -> Value
J.Number (Scientific -> Value) -> (Double -> Scientific) -> Double -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Scientific
forall a. RealFloat a => a -> Scientific
fromFloatDigits) (Double -> Value)
-> Parser MetadataObjId 'Both n Double -> Parser 'Both n Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Parser MetadataObjId 'Both n Double
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Parser origin 'Both m Double
P.namedFloat Name
gqlName
          Just GraphQLType
DC.GraphQLString -> Text -> Value
J.String (Text -> Value)
-> Parser MetadataObjId 'Both n Text -> Parser 'Both n Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Parser origin 'Both m Text
P.namedString Name
gqlName
          Just GraphQLType
DC.GraphQLBoolean -> Bool -> Value
J.Bool (Bool -> Value)
-> Parser MetadataObjId 'Both n Bool -> Parser 'Both n Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Parser MetadataObjId 'Both n Bool
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Parser origin 'Both m Bool
P.namedBoolean Name
gqlName
          Just GraphQLType
DC.GraphQLID -> Text -> Value
J.String (Text -> Value)
-> Parser MetadataObjId 'Both n Text -> Parser 'Both n Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Parser MetadataObjId 'Both n Text
forall (m :: * -> *) origin.
MonadParse m =>
Name -> Parser origin 'Both m Text
P.namedIdentifier Name
gqlName
  RQL.ColumnEnumReference (RQL.EnumReference TableName 'DataConnector
tableName EnumValues
enumValues Maybe Name
customTableName) ->
    case [(EnumValue, EnumValueInfo)]
-> Maybe (NonEmpty (EnumValue, EnumValueInfo))
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty (EnumValues -> [(EnumValue, EnumValueInfo)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList EnumValues
enumValues) of
      Just NonEmpty (EnumValue, EnumValueInfo)
enumValuesList ->
        Parser 'Both n (ColumnValue 'DataConnector)
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
forall (m :: * -> *) a.
MonadParse m =>
Parser 'Both m a -> Parser 'Both m (ValueWithOrigin a)
GS.C.peelWithOrigin
          (Parser 'Both n (ColumnValue 'DataConnector)
 -> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> (Parser 'Both n Value
    -> Parser 'Both n (ColumnValue 'DataConnector))
-> Parser 'Both n Value
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Value -> ColumnValue 'DataConnector)
-> Parser 'Both n Value
-> Parser 'Both n (ColumnValue 'DataConnector)
forall a b.
(a -> b)
-> Parser MetadataObjId 'Both n a -> Parser MetadataObjId 'Both n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ColumnType 'DataConnector
-> ScalarValue 'DataConnector -> ColumnValue 'DataConnector
forall (b :: BackendType).
ColumnType b -> ScalarValue b -> ColumnValue b
RQL.ColumnValue ColumnType 'DataConnector
columnType)
          (Parser 'Both n Value
 -> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT r m (Parser 'Both n Value)
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
forall (m :: * -> *) r (n :: * -> *).
MonadError QErr m =>
TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
enumParser' TableName 'DataConnector
tableName NonEmpty (EnumValue, EnumValueInfo)
enumValuesList Maybe Name
customTableName Nullability
nullability
      Maybe (NonEmpty (EnumValue, EnumValueInfo))
Nothing -> Code
-> Text
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
ValidationFailed Text
"empty enum values"

enumParser' ::
  (MonadError QErr m) =>
  RQL.TableName 'DataConnector ->
  NonEmpty (RQL.EnumValue, RQL.EnumValueInfo) ->
  Maybe GQL.Name ->
  GQL.Nullability ->
  GS.C.SchemaT r m (P.Parser 'P.Both n (RQL.ScalarValue 'DataConnector))
enumParser' :: forall (m :: * -> *) r (n :: * -> *).
MonadError QErr m =>
TableName 'DataConnector
-> NonEmpty (EnumValue, EnumValueInfo)
-> Maybe Name
-> Nullability
-> SchemaT r m (Parser 'Both n (ScalarValue 'DataConnector))
enumParser' TableName 'DataConnector
_tableName NonEmpty (EnumValue, EnumValueInfo)
_enumValues Maybe Name
_customTableName Nullability
_nullability =
  Code -> Text -> SchemaT r m (Parser 'Both n Value)
forall (m :: * -> *) a. QErrM m => Code -> Text -> m a
throw400 Code
NotSupported Text
"This column type is unsupported by the Data Connector backend"

possiblyNullable' ::
  (MonadParse m) =>
  RQL.ScalarType 'DataConnector ->
  GQL.Nullability ->
  P.Parser 'P.Both m J.Value ->
  P.Parser 'P.Both m J.Value
possiblyNullable' :: forall (m :: * -> *).
MonadParse m =>
ScalarType 'DataConnector
-> Nullability -> Parser 'Both m Value -> Parser 'Both m Value
possiblyNullable' ScalarType 'DataConnector
_scalarType (GQL.Nullability Bool
isNullable)
  | Bool
isNullable = (Maybe Value -> Value)
-> Parser MetadataObjId 'Both m (Maybe Value)
-> Parser MetadataObjId 'Both m Value
forall a b.
(a -> b)
-> Parser MetadataObjId 'Both m a -> Parser MetadataObjId 'Both m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Value -> Maybe Value -> Value
forall a. a -> Maybe a -> a
fromMaybe Value
J.Null) (Parser MetadataObjId 'Both m (Maybe Value)
 -> Parser MetadataObjId 'Both m Value)
-> (Parser MetadataObjId 'Both m Value
    -> Parser MetadataObjId 'Both m (Maybe Value))
-> Parser MetadataObjId 'Both m Value
-> Parser MetadataObjId 'Both m Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser MetadataObjId 'Both m Value
-> Parser MetadataObjId 'Both m (Maybe Value)
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m (Maybe a)
P.nullable
  | Bool
otherwise = Parser MetadataObjId 'Both m Value
-> Parser MetadataObjId 'Both m Value
forall a. a -> a
id

orderByOperators' :: RQL.SourceInfo 'DataConnector -> NamingCase -> (GQL.Name, NonEmpty (P.Definition P.EnumValueInfo, (RQL.BasicOrderType 'DataConnector, RQL.NullsOrderType 'DataConnector)))
orderByOperators' :: SourceInfo 'DataConnector
-> NamingCase
-> (Name,
    NonEmpty
      (Definition EnumValueInfo,
       (BasicOrderType 'DataConnector, NullsOrderType 'DataConnector)))
orderByOperators' RQL.SourceInfo {SourceConfig 'DataConnector
_siConfiguration :: forall (b :: BackendType). SourceInfo b -> SourceConfig b
_siConfiguration :: SourceConfig 'DataConnector
_siConfiguration} NamingCase
_tCase =
  let dcName :: DataConnectorName
dcName = SourceConfig -> DataConnectorName
DC._scDataConnectorName SourceConfig 'DataConnector
SourceConfig
_siConfiguration
      orderBy :: Name
orderBy = Name -> [NameSuffix] -> Name
GQL.addSuffixes (DataConnectorName -> Name
DC.unDataConnectorName DataConnectorName
dcName) [$$(GQL.litSuffix "_order_by")]
   in (Name
orderBy,)
        (NonEmpty (Definition EnumValueInfo, (OrderDirection, ()))
 -> (Name,
     NonEmpty
       (Definition EnumValueInfo,
        (BasicOrderType 'DataConnector, NullsOrderType 'DataConnector))))
-> NonEmpty (Definition EnumValueInfo, (OrderDirection, ()))
-> (Name,
    NonEmpty
      (Definition EnumValueInfo,
       (BasicOrderType 'DataConnector, NullsOrderType 'DataConnector)))
forall a b. (a -> b) -> a -> b
$
        -- NOTE: NamingCase is not being used here as we don't support naming conventions for this DB
        [(Definition EnumValueInfo, (OrderDirection, ()))]
-> NonEmpty (Definition EnumValueInfo, (OrderDirection, ()))
forall a. HasCallStack => [a] -> NonEmpty a
NE.fromList
          [ ( Name -> Description -> Definition EnumValueInfo
forall {origin}.
Name -> Description -> Definition origin EnumValueInfo
define $$(GQL.litName "asc") Description
"in ascending order",
              (OrderDirection
DC.Ascending, ())
            ),
            ( Name -> Description -> Definition EnumValueInfo
forall {origin}.
Name -> Description -> Definition origin EnumValueInfo
define $$(GQL.litName "desc") Description
"in descending order",
              (OrderDirection
DC.Descending, ())
            )
          ]
  where
    define :: Name -> Description -> Definition origin EnumValueInfo
define Name
name Description
desc = Name
-> Maybe Description
-> Maybe origin
-> [Directive Void]
-> EnumValueInfo
-> Definition origin EnumValueInfo
forall origin a.
Name
-> Maybe Description
-> Maybe origin
-> [Directive Void]
-> a
-> Definition origin a
P.Definition Name
name (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
desc) Maybe origin
forall a. Maybe a
Nothing [] EnumValueInfo
P.EnumValueInfo

comparisonExps' ::
  forall m n r.
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.ColumnType 'DataConnector ->
  GS.C.SchemaT r m (P.Parser 'P.Input n [ComparisonExp 'DataConnector])
comparisonExps' :: forall (m :: * -> *) (n :: * -> *) r.
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
comparisonExps' ColumnType 'DataConnector
columnType = do
  DangerouslyCollapseBooleans
collapseIfNull <- (SchemaOptions -> DangerouslyCollapseBooleans)
-> SchemaT r m DangerouslyCollapseBooleans
forall r (m :: * -> *) a b.
(MonadReader r m, Has a r) =>
(a -> b) -> m b
GS.C.retrieve SchemaOptions -> DangerouslyCollapseBooleans
Options.soDangerousBooleanCollapse
  SourceInfo 'DataConnector
sourceInfo :: RQL.SourceInfo 'DataConnector <- (r -> SourceInfo 'DataConnector)
-> SchemaT r m (SourceInfo 'DataConnector)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks r -> SourceInfo 'DataConnector
forall a t. Has a t => t -> a
getter
  let dataConnectorName :: DataConnectorName
dataConnectorName = SourceInfo 'DataConnector
sourceInfo SourceInfo 'DataConnector
-> Getting
     DataConnectorName (SourceInfo 'DataConnector) DataConnectorName
-> DataConnectorName
forall s a. s -> Getting a s a -> a
^. (SourceConfig 'DataConnector
 -> Const DataConnectorName (SourceConfig 'DataConnector))
-> SourceInfo 'DataConnector
-> Const DataConnectorName (SourceInfo 'DataConnector)
(SourceConfig -> Const DataConnectorName SourceConfig)
-> SourceInfo 'DataConnector
-> Const DataConnectorName (SourceInfo 'DataConnector)
forall (b :: BackendType) (f :: * -> *).
Functor f =>
(SourceConfig b -> f (SourceConfig b))
-> SourceInfo b -> f (SourceInfo b)
RQL.siConfiguration ((SourceConfig -> Const DataConnectorName SourceConfig)
 -> SourceInfo 'DataConnector
 -> Const DataConnectorName (SourceInfo 'DataConnector))
-> ((DataConnectorName
     -> Const DataConnectorName DataConnectorName)
    -> SourceConfig -> Const DataConnectorName SourceConfig)
-> Getting
     DataConnectorName (SourceInfo 'DataConnector) DataConnectorName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DataConnectorName -> Const DataConnectorName DataConnectorName)
-> SourceConfig -> Const DataConnectorName SourceConfig
Lens' SourceConfig DataConnectorName
DC.scDataConnectorName
      tCase :: NamingCase
tCase = ResolvedSourceCustomization -> NamingCase
RQL._rscNamingConvention (ResolvedSourceCustomization -> NamingCase)
-> ResolvedSourceCustomization -> NamingCase
forall a b. (a -> b) -> a -> b
$ SourceInfo 'DataConnector -> ResolvedSourceCustomization
forall (b :: BackendType).
SourceInfo b -> ResolvedSourceCustomization
RQL._siCustomization SourceInfo 'DataConnector
sourceInfo
  Name
-> (DataConnectorName, ColumnType 'DataConnector)
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
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)
P.memoizeOn 'comparisonExps' (DataConnectorName
dataConnectorName, ColumnType 'DataConnector
columnType) do
    Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser <- ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser' ColumnType 'DataConnector
columnType (Bool -> Nullability
GQL.Nullability Bool
False)
    let name :: Name
name = Name -> [NameSuffix] -> Name
GQL.addSuffixes (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Name
forall a. HasName a => a -> Name
P.getName Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser) [$$(GQL.litSuffix "_"), Name -> NameSuffix
GQL.convertNameToSuffix (DataConnectorName -> Name
DC.unDataConnectorName DataConnectorName
dataConnectorName), $$(GQL.litSuffix "_comparison_exp")]
        desc :: Description
desc =
          Text -> Description
GQL.Description
            (Text -> Description) -> Text -> Description
forall a b. (a -> b) -> a -> b
$ Text
"Boolean expression to compare columns of type "
            Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Name
forall a. HasName a => a -> Name
P.getName Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser
            Name -> Text -> Text
forall t. ToTxt t => t -> Text -> Text
<<> Text
". All fields are combined with logical 'AND'."
        columnListParser :: Parser MetadataObjId 'Both n [ColumnValue 'DataConnector]
columnListParser = (ValueWithOrigin (ColumnValue 'DataConnector)
 -> ColumnValue 'DataConnector)
-> [ValueWithOrigin (ColumnValue 'DataConnector)]
-> [ColumnValue 'DataConnector]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueWithOrigin (ColumnValue 'DataConnector)
-> ColumnValue 'DataConnector
forall a. ValueWithOrigin a -> a
IR.openValueOrigin ([ValueWithOrigin (ColumnValue 'DataConnector)]
 -> [ColumnValue 'DataConnector])
-> Parser
     MetadataObjId
     'Both
     n
     [ValueWithOrigin (ColumnValue 'DataConnector)]
-> Parser MetadataObjId 'Both n [ColumnValue 'DataConnector]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Parser
     MetadataObjId
     'Both
     n
     [ValueWithOrigin (ColumnValue 'DataConnector)]
forall origin (k :: Kind) (m :: * -> *) a.
(MonadParse m, 'Input <: k) =>
Parser origin k m a -> Parser origin k m [a]
P.list Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser
    [InputFieldsParser
   MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
customOperators <- ((InputFieldsParser
   MetadataObjId
   n
   (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
 -> InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector)))
-> [InputFieldsParser
      MetadataObjId
      n
      (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((InputFieldsParser
    MetadataObjId
    n
    (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
  -> InputFieldsParser
       MetadataObjId n (Maybe (ComparisonExp 'DataConnector)))
 -> [InputFieldsParser
       MetadataObjId
       n
       (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
 -> [InputFieldsParser
       MetadataObjId n (Maybe (ComparisonExp 'DataConnector))])
-> ((CustomBooleanOperator (UnpreparedValue 'DataConnector)
     -> ComparisonExp 'DataConnector)
    -> InputFieldsParser
         MetadataObjId
         n
         (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
    -> InputFieldsParser
         MetadataObjId n (Maybe (ComparisonExp 'DataConnector)))
-> (CustomBooleanOperator (UnpreparedValue 'DataConnector)
    -> ComparisonExp 'DataConnector)
-> [InputFieldsParser
      MetadataObjId
      n
      (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))
 -> Maybe (ComparisonExp 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     MetadataObjId n (Maybe (ComparisonExp 'DataConnector))
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))
  -> Maybe (ComparisonExp 'DataConnector))
 -> InputFieldsParser
      MetadataObjId
      n
      (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
 -> InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector)))
-> ((CustomBooleanOperator (UnpreparedValue 'DataConnector)
     -> ComparisonExp 'DataConnector)
    -> Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))
    -> Maybe (ComparisonExp 'DataConnector))
-> (CustomBooleanOperator (UnpreparedValue 'DataConnector)
    -> ComparisonExp 'DataConnector)
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     MetadataObjId n (Maybe (ComparisonExp 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CustomBooleanOperator (UnpreparedValue 'DataConnector)
 -> ComparisonExp 'DataConnector)
-> Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))
-> Maybe (ComparisonExp 'DataConnector)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) BooleanOperators 'DataConnector (UnpreparedValue 'DataConnector)
-> ComparisonExp 'DataConnector
CustomBooleanOperator (UnpreparedValue 'DataConnector)
-> ComparisonExp 'DataConnector
forall (backend :: BackendType) field.
BooleanOperators backend field -> OpExpG backend field
IR.ABackendSpecific ([InputFieldsParser
    MetadataObjId
    n
    (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
 -> [InputFieldsParser
       MetadataObjId n (Maybe (ComparisonExp 'DataConnector))])
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SourceInfo 'DataConnector
-> NamingCase
-> DangerouslyCollapseBooleans
-> Name
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
mkCustomOperators SourceInfo 'DataConnector
sourceInfo NamingCase
tCase DangerouslyCollapseBooleans
collapseIfNull (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Name
forall a. HasName a => a -> Name
P.getName Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser)
    Parser 'Input n [ComparisonExp 'DataConnector]
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (Parser 'Input n [ComparisonExp 'DataConnector]
 -> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector]))
-> Parser 'Input n [ComparisonExp 'DataConnector]
-> SchemaT r m (Parser 'Input n [ComparisonExp 'DataConnector])
forall a b. (a -> b) -> a -> b
$ Name
-> Maybe Description
-> InputFieldsParser MetadataObjId n [ComparisonExp 'DataConnector]
-> Parser 'Input n [ComparisonExp 'DataConnector]
forall (m :: * -> *) origin a.
MonadParse m =>
Name
-> Maybe Description
-> InputFieldsParser origin m a
-> Parser origin 'Input m a
P.object Name
name (Description -> Maybe Description
forall a. a -> Maybe a
Just Description
desc)
      (InputFieldsParser MetadataObjId n [ComparisonExp 'DataConnector]
 -> Parser 'Input n [ComparisonExp 'DataConnector])
-> InputFieldsParser MetadataObjId n [ComparisonExp 'DataConnector]
-> Parser 'Input n [ComparisonExp 'DataConnector]
forall a b. (a -> b) -> a -> b
$ ([Maybe (ComparisonExp 'DataConnector)]
 -> [ComparisonExp 'DataConnector])
-> InputFieldsParser
     MetadataObjId n [Maybe (ComparisonExp 'DataConnector)]
-> InputFieldsParser MetadataObjId n [ComparisonExp 'DataConnector]
forall a b.
(a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Maybe (ComparisonExp 'DataConnector)]
-> [ComparisonExp 'DataConnector]
forall a. [Maybe a] -> [a]
forall (f :: * -> *) a. Filterable f => f (Maybe a) -> f a
catMaybes
      (InputFieldsParser
   MetadataObjId n [Maybe (ComparisonExp 'DataConnector)]
 -> InputFieldsParser
      MetadataObjId n [ComparisonExp 'DataConnector])
-> InputFieldsParser
     MetadataObjId n [Maybe (ComparisonExp 'DataConnector)]
-> InputFieldsParser MetadataObjId n [ComparisonExp 'DataConnector]
forall a b. (a -> b) -> a -> b
$ [InputFieldsParser
   MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
-> InputFieldsParser
     MetadataObjId n [Maybe (ComparisonExp 'DataConnector)]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA
      ([InputFieldsParser
    MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
 -> InputFieldsParser
      MetadataObjId n [Maybe (ComparisonExp 'DataConnector)])
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
-> InputFieldsParser
     MetadataObjId n [Maybe (ComparisonExp 'DataConnector)]
forall a b. (a -> b) -> a -> b
$ [[InputFieldsParser
    MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]]
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ NamingCase
-> DangerouslyCollapseBooleans
-> Parser 'Both n (UnpreparedValue 'DataConnector)
-> Parser 'Both n (UnpreparedValue 'DataConnector)
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall (n :: * -> *) (k :: Kind) (b :: BackendType).
(MonadParse n, 'Input <: k) =>
NamingCase
-> DangerouslyCollapseBooleans
-> Parser k n (UnpreparedValue b)
-> Parser k n (UnpreparedValue b)
-> [InputFieldsParser n (Maybe (OpExpG b (UnpreparedValue b)))]
GS.BE.equalityOperators
            NamingCase
tCase
            DangerouslyCollapseBooleans
collapseIfNull
            (ValueWithOrigin (ColumnValue 'DataConnector)
-> UnpreparedValue 'DataConnector
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter (ValueWithOrigin (ColumnValue 'DataConnector)
 -> UnpreparedValue 'DataConnector)
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Parser 'Both n (UnpreparedValue 'DataConnector)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser)
            ([ColumnValue 'DataConnector] -> UnpreparedValue 'DataConnector
mkListLiteral ([ColumnValue 'DataConnector] -> UnpreparedValue 'DataConnector)
-> Parser MetadataObjId 'Both n [ColumnValue 'DataConnector]
-> Parser 'Both n (UnpreparedValue 'DataConnector)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser MetadataObjId 'Both n [ColumnValue 'DataConnector]
columnListParser),
          NamingCase
-> DangerouslyCollapseBooleans
-> Parser 'Both n (UnpreparedValue 'DataConnector)
-> [InputFieldsParser
      MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
forall (n :: * -> *) (k :: Kind) (b :: BackendType).
(MonadParse n, 'Input <: k) =>
NamingCase
-> DangerouslyCollapseBooleans
-> Parser k n (UnpreparedValue b)
-> [InputFieldsParser n (Maybe (OpExpG b (UnpreparedValue b)))]
GS.BE.comparisonOperators
            NamingCase
tCase
            DangerouslyCollapseBooleans
collapseIfNull
            (ValueWithOrigin (ColumnValue 'DataConnector)
-> UnpreparedValue 'DataConnector
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter (ValueWithOrigin (ColumnValue 'DataConnector)
 -> UnpreparedValue 'DataConnector)
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Parser 'Both n (UnpreparedValue 'DataConnector)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
typedParser),
          [InputFieldsParser
   MetadataObjId n (Maybe (ComparisonExp 'DataConnector))]
customOperators
        ]
  where
    mkListLiteral :: [RQL.ColumnValue 'DataConnector] -> IR.UnpreparedValue 'DataConnector
    mkListLiteral :: [ColumnValue 'DataConnector] -> UnpreparedValue 'DataConnector
mkListLiteral [ColumnValue 'DataConnector]
columnValues =
      SQLExpression 'DataConnector -> UnpreparedValue 'DataConnector
forall (b :: BackendType). SQLExpression b -> UnpreparedValue b
IR.UVLiteral (SQLExpression 'DataConnector -> UnpreparedValue 'DataConnector)
-> SQLExpression 'DataConnector -> UnpreparedValue 'DataConnector
forall a b. (a -> b) -> a -> b
$ ScalarType -> [Value] -> Literal
DC.ArrayLiteral (ColumnType 'DataConnector -> ScalarType
columnTypeToScalarType ColumnType 'DataConnector
columnType) (ColumnValue 'DataConnector -> Value
ColumnValue 'DataConnector -> ScalarValue 'DataConnector
forall (b :: BackendType). ColumnValue b -> ScalarValue b
RQL.cvValue (ColumnValue 'DataConnector -> Value)
-> [ColumnValue 'DataConnector] -> [Value]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ColumnValue 'DataConnector]
columnValues)

    mkCustomOperators ::
      RQL.SourceInfo 'DataConnector ->
      NamingCase ->
      Options.DangerouslyCollapseBooleans ->
      GQL.Name ->
      GS.C.SchemaT r m [P.InputFieldsParser n (Maybe (CustomBooleanOperator (IR.UnpreparedValue 'DataConnector)))]
    mkCustomOperators :: SourceInfo 'DataConnector
-> NamingCase
-> DangerouslyCollapseBooleans
-> Name
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
mkCustomOperators SourceInfo 'DataConnector
sourceInfo NamingCase
tCase DangerouslyCollapseBooleans
collapseIfNull Name
typeName = do
      let capabilities :: Capabilities
capabilities = SourceInfo 'DataConnector
sourceInfo SourceInfo 'DataConnector
-> Getting Capabilities (SourceInfo 'DataConnector) Capabilities
-> Capabilities
forall s a. s -> Getting a s a -> a
^. (SourceConfig 'DataConnector
 -> Const Capabilities (SourceConfig 'DataConnector))
-> SourceInfo 'DataConnector
-> Const Capabilities (SourceInfo 'DataConnector)
(SourceConfig -> Const Capabilities SourceConfig)
-> SourceInfo 'DataConnector
-> Const Capabilities (SourceInfo 'DataConnector)
forall (b :: BackendType) (f :: * -> *).
Functor f =>
(SourceConfig b -> f (SourceConfig b))
-> SourceInfo b -> f (SourceInfo b)
RQL.siConfiguration ((SourceConfig -> Const Capabilities SourceConfig)
 -> SourceInfo 'DataConnector
 -> Const Capabilities (SourceInfo 'DataConnector))
-> ((Capabilities -> Const Capabilities Capabilities)
    -> SourceConfig -> Const Capabilities SourceConfig)
-> Getting Capabilities (SourceInfo 'DataConnector) Capabilities
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Capabilities -> Const Capabilities Capabilities)
-> SourceConfig -> Const Capabilities SourceConfig
Lens' SourceConfig Capabilities
DC.scCapabilities
      case ScalarType
-> HashMap ScalarType ScalarTypeCapabilities
-> Maybe ScalarTypeCapabilities
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Name -> ScalarType
DC.fromGQLType Name
typeName) (ScalarTypesCapabilities
-> HashMap ScalarType ScalarTypeCapabilities
API.unScalarTypesCapabilities (ScalarTypesCapabilities
 -> HashMap ScalarType ScalarTypeCapabilities)
-> ScalarTypesCapabilities
-> HashMap ScalarType ScalarTypeCapabilities
forall a b. (a -> b) -> a -> b
$ Capabilities -> ScalarTypesCapabilities
API._cScalarTypes Capabilities
capabilities) of
        Maybe ScalarTypeCapabilities
Nothing -> [InputFieldsParser
   MetadataObjId
   n
   (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
        Just API.ScalarTypeCapabilities {Maybe GraphQLType
UpdateColumnOperators
AggregateFunctions
ComparisonOperators
_stcComparisonOperators :: ScalarTypeCapabilities -> ComparisonOperators
_stcAggregateFunctions :: ScalarTypeCapabilities -> AggregateFunctions
_stcUpdateColumnOperators :: ScalarTypeCapabilities -> UpdateColumnOperators
_stcGraphQLType :: ScalarTypeCapabilities -> Maybe GraphQLType
_stcComparisonOperators :: ComparisonOperators
_stcAggregateFunctions :: AggregateFunctions
_stcUpdateColumnOperators :: UpdateColumnOperators
_stcGraphQLType :: Maybe GraphQLType
..} -> do
          ((Name, ScalarType)
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))))
-> [(Name, ScalarType)]
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (NamingCase
-> DangerouslyCollapseBooleans
-> (Name, ScalarType)
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))))
mkCustomOperator NamingCase
tCase DangerouslyCollapseBooleans
collapseIfNull) ([(Name, ScalarType)]
 -> SchemaT
      r
      m
      [InputFieldsParser
         MetadataObjId
         n
         (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))])
-> [(Name, ScalarType)]
-> SchemaT
     r
     m
     [InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))]
forall a b. (a -> b) -> a -> b
$ HashMap Name ScalarType -> [(Name, ScalarType)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList (HashMap Name ScalarType -> [(Name, ScalarType)])
-> HashMap Name ScalarType -> [(Name, ScalarType)]
forall a b. (a -> b) -> a -> b
$ (ScalarType -> ScalarType)
-> HashMap Name ScalarType -> HashMap Name ScalarType
forall a b. (a -> b) -> HashMap Name a -> HashMap Name b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ScalarType -> ScalarType
forall source target. From source target => source -> target
Witch.from (HashMap Name ScalarType -> HashMap Name ScalarType)
-> HashMap Name ScalarType -> HashMap Name ScalarType
forall a b. (a -> b) -> a -> b
$ ComparisonOperators -> HashMap Name ScalarType
API.unComparisonOperators (ComparisonOperators -> HashMap Name ScalarType)
-> ComparisonOperators -> HashMap Name ScalarType
forall a b. (a -> b) -> a -> b
$ ComparisonOperators
_stcComparisonOperators

    mkCustomOperator ::
      NamingCase ->
      Options.DangerouslyCollapseBooleans ->
      (GQL.Name, DC.ScalarType) ->
      GS.C.SchemaT r m (P.InputFieldsParser n (Maybe (CustomBooleanOperator (IR.UnpreparedValue 'DataConnector))))
    mkCustomOperator :: NamingCase
-> DangerouslyCollapseBooleans
-> (Name, ScalarType)
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))))
mkCustomOperator NamingCase
tCase DangerouslyCollapseBooleans
collapseIfNull (Name
operatorName, ScalarType
argType) = do
      Parser 'Both n (UnpreparedValue 'DataConnector)
argParser <- ScalarType
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
mkArgParser ScalarType
argType
      InputFieldsParser
  MetadataObjId
  n
  (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
        (InputFieldsParser
   MetadataObjId
   n
   (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
 -> SchemaT
      r
      m
      (InputFieldsParser
         MetadataObjId
         n
         (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
-> SchemaT
     r
     m
     (InputFieldsParser
        MetadataObjId
        n
        (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))))
forall a b. (a -> b) -> a -> b
$ NamingCase
-> DangerouslyCollapseBooleans
-> GQLNameIdentifier
-> Maybe Description
-> Parser
     'Both n (CustomBooleanOperator (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
forall (n :: * -> *) (k :: Kind) a.
(MonadParse n, 'Input <: k) =>
NamingCase
-> DangerouslyCollapseBooleans
-> GQLNameIdentifier
-> Maybe Description
-> Parser k n a
-> InputFieldsParser n (Maybe a)
GS.BE.mkBoolOperator NamingCase
tCase DangerouslyCollapseBooleans
collapseIfNull (Name -> GQLNameIdentifier
fromCustomName Name
operatorName) Maybe Description
forall a. Maybe a
Nothing
        (Parser
   'Both n (CustomBooleanOperator (UnpreparedValue 'DataConnector))
 -> InputFieldsParser
      MetadataObjId
      n
      (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector))))
-> Parser
     'Both n (CustomBooleanOperator (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (CustomBooleanOperator (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ Text
-> Maybe
     (Either
        (RootOrCurrentColumn 'DataConnector)
        (UnpreparedValue 'DataConnector))
-> CustomBooleanOperator (UnpreparedValue 'DataConnector)
forall a.
Text
-> Maybe (Either (RootOrCurrentColumn 'DataConnector) a)
-> CustomBooleanOperator a
CustomBooleanOperator (Name -> Text
GQL.unName Name
operatorName)
        (Maybe
   (Either
      (RootOrCurrentColumn 'DataConnector)
      (UnpreparedValue 'DataConnector))
 -> CustomBooleanOperator (UnpreparedValue 'DataConnector))
-> (UnpreparedValue 'DataConnector
    -> Maybe
         (Either
            (RootOrCurrentColumn 'DataConnector)
            (UnpreparedValue 'DataConnector)))
-> UnpreparedValue 'DataConnector
-> CustomBooleanOperator (UnpreparedValue 'DataConnector)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Either
  (RootOrCurrentColumn 'DataConnector)
  (UnpreparedValue 'DataConnector)
-> Maybe
     (Either
        (RootOrCurrentColumn 'DataConnector)
        (UnpreparedValue 'DataConnector))
forall a. a -> Maybe a
Just
        (Either
   (RootOrCurrentColumn 'DataConnector)
   (UnpreparedValue 'DataConnector)
 -> Maybe
      (Either
         (RootOrCurrentColumn 'DataConnector)
         (UnpreparedValue 'DataConnector)))
-> (UnpreparedValue 'DataConnector
    -> Either
         (RootOrCurrentColumn 'DataConnector)
         (UnpreparedValue 'DataConnector))
-> UnpreparedValue 'DataConnector
-> Maybe
     (Either
        (RootOrCurrentColumn 'DataConnector)
        (UnpreparedValue 'DataConnector))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnpreparedValue 'DataConnector
-> Either
     (RootOrCurrentColumn 'DataConnector)
     (UnpreparedValue 'DataConnector)
forall a b. b -> Either a b
Right
        (UnpreparedValue 'DataConnector
 -> CustomBooleanOperator (UnpreparedValue 'DataConnector))
-> Parser 'Both n (UnpreparedValue 'DataConnector)
-> Parser
     'Both n (CustomBooleanOperator (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser 'Both n (UnpreparedValue 'DataConnector)
argParser

    mkArgParser :: DC.ScalarType -> GS.C.SchemaT r m (P.Parser 'P.Both n (IR.UnpreparedValue 'DataConnector))
    mkArgParser :: ScalarType
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
mkArgParser ScalarType
argType =
      (ValueWithOrigin (ColumnValue 'DataConnector)
 -> UnpreparedValue 'DataConnector)
-> Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
-> Parser 'Both n (UnpreparedValue 'DataConnector)
forall a b.
(a -> b)
-> Parser MetadataObjId 'Both n a -> Parser MetadataObjId 'Both n b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ValueWithOrigin (ColumnValue 'DataConnector)
-> UnpreparedValue 'DataConnector
forall (b :: BackendType).
ValueWithOrigin (ColumnValue b) -> UnpreparedValue b
IR.mkParameter
        (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector))
 -> Parser 'Both n (UnpreparedValue 'DataConnector))
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
-> SchemaT r m (Parser 'Both n (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
ColumnType 'DataConnector
-> Nullability
-> SchemaT
     r m (Parser 'Both n (ValueWithOrigin (ColumnValue 'DataConnector)))
columnParser'
          (ScalarType 'DataConnector -> ColumnType 'DataConnector
forall (b :: BackendType). ScalarType b -> ColumnType b
RQL.ColumnScalar ScalarType 'DataConnector
ScalarType
argType)
          (Bool -> Nullability
GQL.Nullability Bool
True)

tableArgs' ::
  forall r m n.
  (MonadBuildSchema 'DataConnector r m n) =>
  RQL.TableInfo 'DataConnector ->
  GS.C.SchemaT r m (P.InputFieldsParser n (IR.SelectArgsG 'DataConnector (IR.UnpreparedValue 'DataConnector)))
tableArgs' :: forall r (m :: * -> *) (n :: * -> *).
MonadBuildSchema 'DataConnector r m n =>
TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
tableArgs' TableInfo 'DataConnector
tableInfo = do
  InputFieldsParser
  n
  (Maybe
     (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector)))
whereParser <- TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (Maybe
           (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
(AggregationPredicatesSchema b, MonadBuildSchema b r m n) =>
TableInfo b
-> SchemaT
     r
     m
     (InputFieldsParser n (Maybe (AnnBoolExp b (UnpreparedValue b))))
GS.S.tableWhereArg TableInfo 'DataConnector
tableInfo
  InputFieldsParser
  n
  (Maybe
     (NonEmpty
        (AnnotatedOrderByItemG
           'DataConnector (UnpreparedValue 'DataConnector))))
orderByParser <- TableInfo 'DataConnector
-> SchemaT
     r
     m
     (InputFieldsParser
        n
        (Maybe
           (NonEmpty
              (AnnotatedOrderByItemG
                 'DataConnector (UnpreparedValue 'DataConnector)))))
forall (b :: BackendType) r (m :: * -> *) (n :: * -> *).
MonadBuildSchema b r m n =>
TableInfo b
-> SchemaT
     r
     m
     (InputFieldsParser
        n (Maybe (NonEmpty (AnnotatedOrderByItemG b (UnpreparedValue b)))))
GS.S.tableOrderByArg TableInfo 'DataConnector
tableInfo
  let mkSelectArgs :: Maybe (AnnBoolExp b v)
-> Maybe (NonEmpty (AnnotatedOrderByItemG b v))
-> Maybe Int
-> Maybe Int64
-> SelectArgsG b v
mkSelectArgs Maybe (AnnBoolExp b v)
whereArg Maybe (NonEmpty (AnnotatedOrderByItemG b v))
orderByArg Maybe Int
limitArg Maybe Int64
offsetArg =
        IR.SelectArgs
          { $sel:_saWhere:SelectArgs :: Maybe (AnnBoolExp b v)
_saWhere = Maybe (AnnBoolExp b v)
whereArg,
            $sel:_saOrderBy:SelectArgs :: Maybe (NonEmpty (AnnotatedOrderByItemG b v))
_saOrderBy = Maybe (NonEmpty (AnnotatedOrderByItemG b v))
orderByArg,
            $sel:_saLimit:SelectArgs :: Maybe Int
_saLimit = Maybe Int
limitArg,
            $sel:_saOffset:SelectArgs :: Maybe Int64
_saOffset = Maybe Int64
offsetArg,
            $sel:_saDistinct:SelectArgs :: Maybe (NonEmpty (AnnDistinctColumn b v))
_saDistinct = Maybe (NonEmpty (AnnDistinctColumn b v))
forall a. Maybe a
Nothing
          }
  InputFieldsParser
  n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
forall a. a -> SchemaT r m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (InputFieldsParser
   n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
 -> SchemaT
      r
      m
      (InputFieldsParser
         n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))))
-> InputFieldsParser
     n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> SchemaT
     r
     m
     (InputFieldsParser
        n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)))
forall a b. (a -> b) -> a -> b
$ Maybe (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector))
-> Maybe
     (NonEmpty
        (AnnotatedOrderByItemG
           'DataConnector (UnpreparedValue 'DataConnector)))
-> Maybe Int
-> Maybe Int64
-> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector)
forall {b :: BackendType} {v}.
Maybe (AnnBoolExp b v)
-> Maybe (NonEmpty (AnnotatedOrderByItemG b v))
-> Maybe Int
-> Maybe Int64
-> SelectArgsG b v
mkSelectArgs
    (Maybe (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector))
 -> Maybe
      (NonEmpty
         (AnnotatedOrderByItemG
            'DataConnector (UnpreparedValue 'DataConnector)))
 -> Maybe Int
 -> Maybe Int64
 -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (Maybe
        (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector)))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe
        (NonEmpty
           (AnnotatedOrderByItemG
              'DataConnector (UnpreparedValue 'DataConnector)))
      -> Maybe Int
      -> Maybe Int64
      -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InputFieldsParser
  n
  (Maybe
     (AnnBoolExp 'DataConnector (UnpreparedValue 'DataConnector)))
whereParser
    InputFieldsParser
  MetadataObjId
  n
  (Maybe
     (NonEmpty
        (AnnotatedOrderByItemG
           'DataConnector (UnpreparedValue 'DataConnector)))
   -> Maybe Int
   -> Maybe Int64
   -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (Maybe
        (NonEmpty
           (AnnotatedOrderByItemG
              'DataConnector (UnpreparedValue 'DataConnector))))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe Int
      -> Maybe Int64
      -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
forall a b.
InputFieldsParser MetadataObjId n (a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InputFieldsParser
  n
  (Maybe
     (NonEmpty
        (AnnotatedOrderByItemG
           'DataConnector (UnpreparedValue 'DataConnector))))
orderByParser
    InputFieldsParser
  MetadataObjId
  n
  (Maybe Int
   -> Maybe Int64
   -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> InputFieldsParser MetadataObjId n (Maybe Int)
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe Int64
      -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
forall a b.
InputFieldsParser MetadataObjId n (a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InputFieldsParser MetadataObjId n (Maybe Int)
forall (n :: * -> *).
MonadParse n =>
InputFieldsParser n (Maybe Int)
GS.S.tableLimitArg
    InputFieldsParser
  MetadataObjId
  n
  (Maybe Int64
   -> SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
-> InputFieldsParser MetadataObjId n (Maybe Int64)
-> InputFieldsParser
     n (SelectArgsG 'DataConnector (UnpreparedValue 'DataConnector))
forall a b.
InputFieldsParser MetadataObjId n (a -> b)
-> InputFieldsParser MetadataObjId n a
-> InputFieldsParser MetadataObjId n b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> InputFieldsParser MetadataObjId n (Maybe Int64)
forall (n :: * -> *).
MonadParse n =>
InputFieldsParser n (Maybe Int64)
GS.S.tableOffsetArg

countTypeInput' ::
  (MonadParse n) =>
  Maybe (P.Parser 'P.Both n (DC.ColumnName, IR.AnnRedactionExpUnpreparedValue 'DataConnector)) ->
  P.InputFieldsParser n (IR.CountDistinct -> DC.CountAggregate (IR.UnpreparedValue 'DataConnector))
countTypeInput' :: forall (n :: * -> *).
MonadParse n =>
Maybe
  (Parser
     'Both
     n
     (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
countTypeInput' = \case
  Just Parser
  'Both n (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
columnEnum -> Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector)
mkCountAggregate (Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
 -> CountDistinct
 -> CountAggregate (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name
-> Maybe Description
-> Parser
     'Both n (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> InputFieldsParser
     MetadataObjId
     n
     (Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
forall (m :: * -> *) (k :: Kind) origin a.
(MonadParse m, 'Input <: k) =>
Name
-> Maybe Description
-> Parser origin k m a
-> InputFieldsParser origin m (Maybe a)
P.fieldOptional Name
Name._column Maybe Description
forall a. Maybe a
Nothing Parser
  'Both n (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
columnEnum
  Maybe
  (Parser
     'Both
     n
     (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector))
Nothing -> (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
forall a. a -> InputFieldsParser MetadataObjId n a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
 -> InputFieldsParser
      n
      (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector)))
-> (CountDistinct
    -> CountAggregate (UnpreparedValue 'DataConnector))
-> InputFieldsParser
     n
     (CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector))
forall a b. (a -> b) -> a -> b
$ Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector)
mkCountAggregate Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
forall a. Maybe a
Nothing
  where
    mkCountAggregate :: Maybe (DC.ColumnName, IR.AnnRedactionExpUnpreparedValue 'DataConnector) -> IR.CountDistinct -> DC.CountAggregate (IR.UnpreparedValue 'DataConnector)
    mkCountAggregate :: Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> CountDistinct -> CountAggregate (UnpreparedValue 'DataConnector)
mkCountAggregate Maybe (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
Nothing CountDistinct
_ = CountAggregate (UnpreparedValue 'DataConnector)
forall v. CountAggregate v
DC.StarCount
    mkCountAggregate (Just (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
column) CountDistinct
IR.SelectCountDistinct = (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> CountAggregate (UnpreparedValue 'DataConnector)
forall v.
(ColumnName, AnnRedactionExp 'DataConnector v) -> CountAggregate v
DC.ColumnDistinctCount (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
column
    mkCountAggregate (Just (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
column) CountDistinct
IR.SelectCountNonDistinct = (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
-> CountAggregate (UnpreparedValue 'DataConnector)
forall v.
(ColumnName, AnnRedactionExp 'DataConnector v) -> CountAggregate v
DC.ColumnCount (ColumnName, AnnRedactionExpUnpreparedValue 'DataConnector)
column