mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
Move MkTypename
and NamingCase
into their own modules.
This moves `MkTypename` and `NamingCase` into their own modules, with the intent of reducing the scope of the schema parsers code, and trying to reduce imports of large modules when small ones will do. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4978 GitOrigin-RevId: 19541257fe010035390f6183a4eaa37bae0d3ca1
This commit is contained in:
parent
6d2c8f1ec3
commit
c980af1b8f
@ -646,6 +646,7 @@ library
|
||||
, Hasura.RQL.Types.Allowlist
|
||||
, Hasura.RQL.Types.ApiLimit
|
||||
, Hasura.RQL.Types.Backend
|
||||
, Hasura.RQL.Types.BoolExp
|
||||
, Hasura.RQL.Types.Column
|
||||
, Hasura.RQL.Types.Common
|
||||
, Hasura.RQL.Types.ComputedField
|
||||
@ -655,10 +656,9 @@ library
|
||||
, Hasura.RQL.Types.EventTrigger
|
||||
, Hasura.RQL.Types.Eventing
|
||||
, Hasura.RQL.Types.Eventing.Backend
|
||||
, Hasura.RQL.Types.GraphqlSchemaIntrospection
|
||||
, Hasura.RQL.Types.Function
|
||||
, Hasura.RQL.Types.GraphqlSchemaIntrospection
|
||||
, Hasura.RQL.Types.Instances
|
||||
, Hasura.RQL.Types.BoolExp
|
||||
, Hasura.RQL.Types.Metadata
|
||||
, Hasura.RQL.Types.Metadata.Backend
|
||||
, Hasura.RQL.Types.Metadata.Instances
|
||||
@ -673,6 +673,8 @@ library
|
||||
, Hasura.RQL.Types.Relationships.ToSource
|
||||
, Hasura.RQL.Types.RemoteSchema
|
||||
, Hasura.RQL.Types.ResultCustomization
|
||||
, Hasura.RQL.Types.Roles
|
||||
, Hasura.RQL.Types.Roles.Internal
|
||||
, Hasura.RQL.Types.ScheduledTrigger
|
||||
, Hasura.RQL.Types.SchemaCache
|
||||
, Hasura.RQL.Types.SchemaCache.Build
|
||||
@ -681,8 +683,6 @@ library
|
||||
, Hasura.RQL.Types.SourceCustomization
|
||||
, Hasura.RQL.Types.Subscription
|
||||
, Hasura.RQL.Types.Table
|
||||
, Hasura.RQL.Types.Roles
|
||||
, Hasura.RQL.Types.Roles.Internal
|
||||
, Hasura.RQL.DDL.Action
|
||||
, Hasura.RQL.DDL.ApiLimit
|
||||
, Hasura.RQL.DDL.ComputedField
|
||||
@ -809,6 +809,7 @@ library
|
||||
, Hasura.GraphQL.Schema.Instances
|
||||
, Hasura.GraphQL.Schema.Introspect
|
||||
, Hasura.GraphQL.Schema.Mutation
|
||||
, Hasura.GraphQL.Schema.NamingCase
|
||||
, Hasura.GraphQL.Schema.Node
|
||||
, Hasura.GraphQL.Schema.OrderBy
|
||||
, Hasura.GraphQL.Schema.Parser
|
||||
@ -819,6 +820,7 @@ library
|
||||
, Hasura.GraphQL.Schema.Select
|
||||
, Hasura.GraphQL.Schema.SubscriptionStream
|
||||
, Hasura.GraphQL.Schema.Table
|
||||
, Hasura.GraphQL.Schema.Typename
|
||||
, Hasura.GraphQL.Schema.Update
|
||||
, Hasura.GraphQL.Transport.Backend
|
||||
, Hasura.GraphQL.Transport.HTTP
|
||||
|
@ -14,6 +14,7 @@ import Hasura.Backends.BigQuery.DDL.ComputedField as M
|
||||
import Hasura.Backends.BigQuery.DDL.Source as M
|
||||
import Hasura.Backends.BigQuery.Types qualified as BigQuery
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
import Hasura.RQL.Types.Backend
|
||||
@ -22,7 +23,6 @@ import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.EventTrigger
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.SQL.Types
|
||||
|
@ -18,6 +18,7 @@ import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.BoolExp
|
||||
import Hasura.GraphQL.Schema.Build qualified as GSB
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( FieldParser,
|
||||
InputFieldsParser,
|
||||
@ -29,6 +30,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
@ -40,7 +42,6 @@ import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.ComputedField
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.Source (SourceInfo)
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Hasura.SQL.Backend
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
@ -162,7 +163,7 @@ bqBuildFunctionMutationFields _ _ _ _ =
|
||||
-- Individual components
|
||||
|
||||
bqColumnParser ::
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r) =>
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r) =>
|
||||
ColumnType 'BigQuery ->
|
||||
G.Nullability ->
|
||||
m (Parser 'Both n (IR.ValueWithOrigin (ColumnValue 'BigQuery)))
|
||||
@ -392,7 +393,7 @@ bqCountTypeInput = \case
|
||||
|
||||
geographyWithinDistanceInput ::
|
||||
forall m n r.
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r, Has NamingCase r) =>
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r, Has NamingCase r) =>
|
||||
m (Parser 'Input n (DWithinGeogOp (IR.UnpreparedValue 'BigQuery)))
|
||||
geographyWithinDistanceInput = do
|
||||
geographyParser <- columnParser (ColumnScalar BigQuery.GeographyScalarType) (G.Nullability False)
|
||||
@ -442,7 +443,7 @@ bqComputedField sourceName ComputedFieldInfo {..} tableName tableInfo = runMaybe
|
||||
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
|
||||
guard $ Map.member _cfiName $ spiComputedFields selectPermissions
|
||||
objectTypeName <-
|
||||
P.mkTypename =<< do
|
||||
mkTypename =<< do
|
||||
computedFieldGQLName <- textToName $ computedFieldNameToText _cfiName
|
||||
pure $ computedFieldGQLName <> Name.__ <> Name.__fields
|
||||
selectionSetParser <- do
|
||||
@ -487,7 +488,7 @@ bqComputedField sourceName ComputedFieldInfo {..} tableName tableInfo = runMaybe
|
||||
<> _cfiName <<> " defined on table " <>> tableName
|
||||
|
||||
objectName <-
|
||||
P.mkTypename =<< do
|
||||
mkTypename =<< do
|
||||
computedFieldGQLName <- textToName $ computedFieldNameToText _cfiName
|
||||
tableGQLName <- getTableGQLName @'BigQuery tableInfo
|
||||
pure $ computedFieldGQLName <> Name.__ <> tableGQLName <> Name.__args
|
||||
|
@ -20,6 +20,7 @@ import Hasura.GraphQL.Schema.Backend (BackendSchema (..), BackendTableSelectSche
|
||||
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.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select qualified as GS.S
|
||||
import Hasura.Name qualified as Name
|
||||
@ -29,7 +30,6 @@ import Hasura.RQL.IR.Value qualified as IR
|
||||
import Hasura.RQL.Types.Backend qualified as RQL
|
||||
import Hasura.RQL.Types.Column qualified as RQL
|
||||
import Hasura.RQL.Types.Source qualified as RQL
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table qualified as RQL
|
||||
import Hasura.SQL.Backend (BackendType (..))
|
||||
import Language.GraphQL.Draft.Syntax qualified as GQL
|
||||
|
@ -21,6 +21,7 @@ import Hasura.Backends.MSSQL.DDL.BoolExp as M
|
||||
import Hasura.Backends.MSSQL.DDL.Source as M
|
||||
import Hasura.Backends.MSSQL.Types.Internal qualified as MT
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
import Hasura.RQL.Types.Backend
|
||||
@ -30,7 +31,6 @@ import Hasura.RQL.Types.ComputedField
|
||||
import Hasura.RQL.Types.EventTrigger
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.SQL.Types
|
||||
|
@ -22,6 +22,7 @@ import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.BoolExp
|
||||
import Hasura.GraphQL.Schema.Build qualified as GSB
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( FieldParser,
|
||||
InputFieldsParser,
|
||||
@ -33,6 +34,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (MkTypename)
|
||||
import Hasura.GraphQL.Schema.Update qualified as SU
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
@ -46,7 +48,6 @@ import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.Relationships.Local
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Hasura.SQL.Backend
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
@ -247,7 +248,7 @@ msMkRelationshipParser _sourceName _relationshipInfo = do
|
||||
-- * Individual components
|
||||
|
||||
msColumnParser ::
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r) =>
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r) =>
|
||||
ColumnType 'MSSQL ->
|
||||
G.Nullability ->
|
||||
m (Parser 'Both n (ValueWithOrigin (ColumnValue 'MSSQL)))
|
||||
@ -350,7 +351,7 @@ msComparisonExps ::
|
||||
MonadError QErr m,
|
||||
MonadReader r m,
|
||||
Has SchemaOptions r,
|
||||
Has P.MkTypename r,
|
||||
Has MkTypename r,
|
||||
Has NamingCase r
|
||||
) =>
|
||||
ColumnType 'MSSQL ->
|
||||
|
@ -27,6 +27,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
@ -76,7 +77,7 @@ ifMatchedObjectParser sourceInfo tableInfo = runMaybeT do
|
||||
lift do
|
||||
updateColumnsEnum <- updateColumnsPlaceholderParser tableInfo
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectName <- P.mkTypename $ tableGQLName <> Name.__if_matched
|
||||
objectName <- mkTypename $ tableGQLName <> Name.__if_matched
|
||||
let _imColumnPresets = partialSQLExpToUnpreparedValue <$> upiSet updatePerms
|
||||
updateFilter = fmap partialSQLExpToUnpreparedValue <$> upiFilter updatePerms
|
||||
objectDesc = G.Description $ "upsert condition type for table " <>> tableInfoName tableInfo
|
||||
@ -115,7 +116,7 @@ tableInsertMatchColumnsEnum ::
|
||||
tableInsertMatchColumnsEnum sourceInfo tableInfo = do
|
||||
tableGQLName <- getTableGQLName @'MSSQL tableInfo
|
||||
columns <- tableSelectColumns sourceInfo tableInfo
|
||||
enumName <- P.mkTypename $ tableGQLName <> Name.__insert_match_column
|
||||
enumName <- mkTypename $ tableGQLName <> Name.__insert_match_column
|
||||
let description =
|
||||
Just $
|
||||
G.Description $
|
||||
|
@ -17,6 +17,7 @@ import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Build qualified as GSB
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( InputFieldsParser,
|
||||
Kind (..),
|
||||
@ -26,6 +27,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Typename (MkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR
|
||||
@ -35,7 +37,6 @@ import Hasura.RQL.Types.Column as RQL
|
||||
import Hasura.RQL.Types.Function as RQL
|
||||
import Hasura.RQL.Types.SchemaCache as RQL
|
||||
import Hasura.RQL.Types.Source as RQL
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.SQL.Backend
|
||||
import Language.GraphQL.Draft.Syntax qualified as GQL
|
||||
|
||||
@ -168,7 +169,7 @@ bsParser :: MonadParse m => Parser 'Both m ByteString
|
||||
bsParser = encodeUtf8 <$> P.string
|
||||
|
||||
columnParser' ::
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r) =>
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r) =>
|
||||
ColumnType 'MySQL ->
|
||||
GQL.Nullability ->
|
||||
m (Parser 'Both n (ValueWithOrigin (ColumnValue 'MySQL)))
|
||||
@ -255,7 +256,7 @@ orderByOperators' _tCase =
|
||||
-- | TODO: Make this as thorough as the one for MSSQL/PostgreSQL
|
||||
comparisonExps' ::
|
||||
forall m n r.
|
||||
(BackendSchema 'MySQL, MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r, Has NamingCase r) =>
|
||||
(BackendSchema 'MySQL, MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r, Has NamingCase r) =>
|
||||
ColumnType 'MySQL ->
|
||||
m (Parser 'Input n [ComparisonExp 'MySQL])
|
||||
comparisonExps' = P.memoize 'comparisonExps $ \columnType -> do
|
||||
|
@ -18,13 +18,14 @@ import Data.Text.Extended
|
||||
import Hasura.Backends.Postgres.SQL.Types hiding (FunctionName)
|
||||
import Hasura.Backends.Postgres.Types.Function
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.SchemaCacheTypes
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase, applyFieldNameCaseCust)
|
||||
import Hasura.RQL.Types.SourceCustomization (applyFieldNameCaseCust)
|
||||
import Hasura.SQL.AnyBackend qualified as AB
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Utils
|
||||
|
@ -42,6 +42,7 @@ import Hasura.GraphQL.Schema.BoolExp
|
||||
import Hasura.GraphQL.Schema.Build qualified as GSB
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Mutation qualified as GSB
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( Definition,
|
||||
FieldParser,
|
||||
@ -55,6 +56,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.GraphQL.Schema.Update qualified as SU
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
@ -250,7 +252,7 @@ buildFunctionRelayQueryFields sourceName functionName functionInfo tableName pke
|
||||
-- Individual components
|
||||
|
||||
columnParser ::
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has P.MkTypename r, Has NamingCase r) =>
|
||||
(MonadSchema n m, MonadError QErr m, MonadReader r m, Has MkTypename r, Has NamingCase r) =>
|
||||
ColumnType ('Postgres pgKind) ->
|
||||
G.Nullability ->
|
||||
m (Parser 'Both n (IR.ValueWithOrigin (ColumnValue ('Postgres pgKind))))
|
||||
|
@ -29,6 +29,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp qualified as IR
|
||||
@ -82,7 +83,7 @@ conflictObjectParser sourceInfo tableInfo maybeUpdatePerms constraints = do
|
||||
constraintParser <- conflictConstraint constraints sourceInfo tableInfo
|
||||
whereExpParser <- boolExp sourceInfo tableInfo
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectName <- P.mkTypename $ tableGQLName <> Name.__on_conflict
|
||||
objectName <- mkTypename $ tableGQLName <> Name.__on_conflict
|
||||
|
||||
let objectDesc = G.Description $ "on_conflict condition type for table " <>> tableName
|
||||
(presetColumns, updateFilter) = fromMaybe (HM.empty, IR.gBoolExpTrue) $ do
|
||||
@ -149,7 +150,7 @@ conflictConstraint constraints sourceInfo tableInfo =
|
||||
P.EnumValueInfo,
|
||||
c
|
||||
)
|
||||
enumName <- P.mkTypename $ tableGQLName <> Name.__constraint
|
||||
enumName <- mkTypename $ tableGQLName <> Name.__constraint
|
||||
let enumDesc = G.Description $ "unique or primary key constraints on table " <>> tableName
|
||||
pure $ P.enum enumName (Just enumDesc) constraintEnumValues
|
||||
where
|
||||
|
@ -30,6 +30,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR
|
||||
@ -108,7 +109,7 @@ selectFunctionAggregate sourceInfo fi@FunctionInfo {..} description = runMaybeT
|
||||
tableArgsParser <- tableArguments sourceInfo tableInfo
|
||||
functionArgsParser <- customSQLFunctionArgs sourceInfo fi _fiGQLAggregateName _fiGQLArgsName
|
||||
aggregateParser <- tableAggregationFields sourceInfo tableInfo
|
||||
selectionName <- P.mkTypename =<< pure (tableGQLName <> Name.__aggregate)
|
||||
selectionName <- mkTypename =<< pure (tableGQLName <> Name.__aggregate)
|
||||
aggregateFieldName <- mkRootFieldName _fiGQLAggregateName
|
||||
let argsParser = liftA2 (,) functionArgsParser tableArgsParser
|
||||
aggregationParser =
|
||||
@ -314,7 +315,7 @@ functionArgs sourceInfo functionTrackedAs (toList -> inputArgs) = do
|
||||
-- There are user-provided arguments: we need to parse an args object.
|
||||
argumentParsers <- sequenceA $ optional <> mandatory
|
||||
objectName <-
|
||||
P.mkTypename
|
||||
mkTypename
|
||||
=<< case functionTrackedAs of
|
||||
FTAComputedField computedFieldName _sourceName tableName -> do
|
||||
tableInfo <- askTableInfo sourceInfo tableName
|
||||
|
@ -16,6 +16,7 @@ import Data.Aeson qualified as J
|
||||
import Data.HashMap.Strict.InsOrd qualified as OMap
|
||||
import Data.Text.Extended
|
||||
import Hasura.GraphQL.Schema.Parser as P
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Prelude
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
@ -85,7 +86,7 @@ customizeNamespace ::
|
||||
(MonadParse n) =>
|
||||
Maybe G.Name ->
|
||||
(G.Name -> P.ParsedSelection a -> a) ->
|
||||
P.MkTypename ->
|
||||
MkTypename ->
|
||||
[FieldParser n a] ->
|
||||
[FieldParser n (NamespacedField a)]
|
||||
customizeNamespace (Just _) _ _ [] = [] -- The nampespace doesn't contain any Field parsers, so returning empty list
|
||||
|
@ -1,16 +1,6 @@
|
||||
module Hasura.GraphQL.Parser.Names
|
||||
( MkTypename (..),
|
||||
mkTypename,
|
||||
withTypenameCustomization,
|
||||
HasName (..),
|
||||
)
|
||||
where
|
||||
module Hasura.GraphQL.Parser.Names (HasName (..)) where
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad.Reader (MonadReader, asks, local)
|
||||
import Data.Has
|
||||
import Data.Monoid
|
||||
import Language.GraphQL.Draft.Syntax (Name (..))
|
||||
import Language.GraphQL.Draft.Syntax (Name)
|
||||
import Prelude
|
||||
|
||||
class HasName a where
|
||||
@ -18,18 +8,3 @@ class HasName a where
|
||||
|
||||
instance HasName Name where
|
||||
getName = id
|
||||
|
||||
-- | Type name customization
|
||||
newtype MkTypename = MkTypename {runMkTypename :: Name -> Name}
|
||||
deriving (Semigroup, Monoid) via (Endo Name)
|
||||
|
||||
-- | Inject a new @MkTypename@ customization function into the environment.
|
||||
-- This can be used by schema-building code (with @MonadBuildSchema@ constraint) to ensure
|
||||
-- the correct type name customizations are applied.
|
||||
withTypenameCustomization :: forall m r a. (MonadReader r m, Has MkTypename r) => MkTypename -> m a -> m a
|
||||
withTypenameCustomization = local . set hasLens
|
||||
|
||||
-- | Apply the type name customization function from the current environment.
|
||||
mkTypename :: (MonadReader r m, Has MkTypename r) => Name -> m Name
|
||||
mkTypename name =
|
||||
($ name) . runMkTypename <$> asks getter
|
||||
|
@ -23,7 +23,9 @@ import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Parser.Monad (Parse, runSchemaT)
|
||||
import Hasura.GraphQL.Parser.Name qualified as GName
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Remote (buildRemoteParser)
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.GraphQL.Transport.HTTP.Protocol
|
||||
import Hasura.HTTP
|
||||
import Hasura.Prelude
|
||||
@ -117,7 +119,7 @@ fetchRemoteSchema env manager _rscName rsDef@ValidatedRemoteSchemaDef {..} = do
|
||||
mempty :: CustomizeRemoteFieldName,
|
||||
mempty :: MkTypename,
|
||||
mempty :: MkRootFieldName,
|
||||
HasuraCase :: NamingCase,
|
||||
HasuraCase,
|
||||
SchemaOptions
|
||||
{ -- doesn't apply to remote schemas
|
||||
soStringifyNum = LeaveNumbersAlone,
|
||||
|
@ -25,6 +25,7 @@ import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Instances ()
|
||||
import Hasura.GraphQL.Schema.Introspect
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( FieldParser,
|
||||
Kind (..),
|
||||
@ -39,6 +40,7 @@ import Hasura.GraphQL.Schema.Relay
|
||||
import Hasura.GraphQL.Schema.Remote (buildRemoteParser)
|
||||
import Hasura.GraphQL.Schema.RemoteRelationship
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (MkTypename (..))
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR
|
||||
@ -271,25 +273,25 @@ buildRoleContext options sources remotes allActionInfos customTypes role remoteS
|
||||
withSourceCustomization sourceCustomization (namingConventionSupport @b) globalDefaultNC do
|
||||
let validFunctions = takeValidFunctions functions
|
||||
validTables = takeValidTables tables
|
||||
mkTypename <- asks getter
|
||||
makeTypename <- asks getter
|
||||
(uncustomizedQueryRootFields, uncustomizedSubscriptionRootFields) <-
|
||||
buildQueryAndSubscriptionFields sourceInfo validTables validFunctions streamingSubscriptionsCtx
|
||||
(,,,)
|
||||
<$> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__query))
|
||||
(makeTypename <> MkTypename (<> Name.__query))
|
||||
(pure uncustomizedQueryRootFields)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__mutation_frontend))
|
||||
(makeTypename <> MkTypename (<> Name.__mutation_frontend))
|
||||
(buildMutationFields Frontend sourceInfo validTables validFunctions)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__mutation_backend))
|
||||
(makeTypename <> MkTypename (<> Name.__mutation_backend))
|
||||
(buildMutationFields Backend sourceInfo validTables validFunctions)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__subscription))
|
||||
(makeTypename <> MkTypename (<> Name.__subscription))
|
||||
(pure uncustomizedSubscriptionRootFields)
|
||||
where
|
||||
sourceCustomization =
|
||||
@ -391,23 +393,23 @@ buildRelayRoleContext options sources allActionInfos customTypes role expFeature
|
||||
|
||||
(uncustomizedQueryRootFields, uncustomizedSubscriptionRootFields) <-
|
||||
buildRelayQueryAndSubscriptionFields sourceInfo validTables validFunctions
|
||||
mkTypename <- asks getter
|
||||
makeTypename <- asks getter
|
||||
(,,,)
|
||||
<$> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__query))
|
||||
(makeTypename <> MkTypename (<> Name.__query))
|
||||
(pure uncustomizedQueryRootFields)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__mutation_frontend))
|
||||
(makeTypename <> MkTypename (<> Name.__mutation_frontend))
|
||||
(buildMutationFields Frontend sourceInfo validTables validFunctions)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__mutation_backend))
|
||||
(makeTypename <> MkTypename (<> Name.__mutation_backend))
|
||||
(buildMutationFields Backend sourceInfo validTables validFunctions)
|
||||
<*> customizeFields
|
||||
sourceCustomization
|
||||
(mkTypename <> P.MkTypename (<> Name.__subscription))
|
||||
(makeTypename <> MkTypename (<> Name.__subscription))
|
||||
(pure uncustomizedSubscriptionRootFields)
|
||||
where
|
||||
sourceCustomization =
|
||||
@ -796,7 +798,7 @@ customizeFields ::
|
||||
forall f n db remote action.
|
||||
(Functor f, MonadParse n) =>
|
||||
SourceCustomization ->
|
||||
P.MkTypename ->
|
||||
MkTypename ->
|
||||
f [FieldParser n (RootField db remote action JO.Value)] ->
|
||||
f [FieldParser n (NamespacedField (RootField db remote action JO.Value))]
|
||||
customizeFields SourceCustomization {..} =
|
||||
|
@ -28,6 +28,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
Parser,
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.Action qualified as IR
|
||||
@ -143,7 +144,7 @@ actionAsyncQuery objectTypes actionInfo = runMaybeT do
|
||||
errorsFieldParser <-
|
||||
lift $ columnParser @('Postgres 'Vanilla) (ColumnScalar PGJSON) (G.Nullability True)
|
||||
|
||||
outputTypeName <- P.mkTypename $ unActionName actionName
|
||||
outputTypeName <- mkTypename $ unActionName actionName
|
||||
let fieldName = unActionName actionName
|
||||
description = G.Description <$> comment
|
||||
actionIdInputField =
|
||||
@ -254,7 +255,7 @@ actionOutputFields ::
|
||||
actionOutputFields outputType annotatedObject objectTypes = do
|
||||
scalarOrEnumOrObjectFields <- forM (toList $ _aotFields annotatedObject) outputFieldParser
|
||||
relationshipFields <- traverse relationshipFieldParser $ _aotRelationships annotatedObject
|
||||
outputTypeName <- P.mkTypename $ unObjectTypeName $ _aotName annotatedObject
|
||||
outputTypeName <- mkTypename $ unObjectTypeName $ _aotName annotatedObject
|
||||
let allFieldParsers =
|
||||
scalarOrEnumOrObjectFields
|
||||
<> concat (catMaybes relationshipFields)
|
||||
|
@ -40,7 +40,9 @@ import Data.Has
|
||||
import Data.Text.Casing (GQLNameIdentifier)
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser hiding (Type)
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR
|
||||
import Hasura.RQL.IR.Insert qualified as IR
|
||||
@ -52,7 +54,6 @@ import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.Relationships.Local
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.Types (StreamingSubscriptionsCtx)
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
@ -15,6 +15,7 @@ import Data.Text.Extended
|
||||
import Hasura.GraphQL.Parser.Class
|
||||
import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common (askTableInfo, partialSQLExpToUnpreparedValue)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( InputFieldsParser,
|
||||
Kind (..),
|
||||
@ -22,6 +23,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
@ -33,7 +35,7 @@ import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.Relationships.Local
|
||||
import Hasura.RQL.Types.SchemaCache hiding (askTableInfo)
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase, applyFieldNameCaseIdentifier)
|
||||
import Hasura.RQL.Types.SourceCustomization (applyFieldNameCaseIdentifier)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
|
||||
@ -53,7 +55,7 @@ boolExp ::
|
||||
m (Parser 'Input n (AnnBoolExp b (UnpreparedValue b)))
|
||||
boolExp sourceInfo tableInfo = memoizeOn 'boolExp (_siName sourceInfo, tableName) $ do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
name <- P.mkTypename $ tableGQLName <> Name.__bool_exp
|
||||
name <- mkTypename $ tableGQLName <> Name.__bool_exp
|
||||
let description =
|
||||
G.Description $
|
||||
"Boolean expression to filter rows from the table " <> tableName
|
||||
|
@ -58,6 +58,7 @@ import Data.Text.Extended
|
||||
import Hasura.GraphQL.Schema.Backend (BackendTableSelectSchema (..), MonadBuildSchema)
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Mutation
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser hiding (EnumValueInfo, field)
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.SubscriptionStream (selectStreamTable)
|
||||
|
@ -54,8 +54,10 @@ import Hasura.Backends.Postgres.SQL.Types qualified as PG
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Namespace (NamespacedField)
|
||||
import Hasura.GraphQL.Parser.Internal.TypeChecking qualified as P
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Node
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR qualified as IR
|
||||
@ -249,9 +251,9 @@ parsedSelectionsToFields ::
|
||||
(Text -> a) ->
|
||||
OMap.InsOrdHashMap G.Name (P.ParsedSelection a) ->
|
||||
Fields a
|
||||
parsedSelectionsToFields mkTypename =
|
||||
parsedSelectionsToFields mkTypenameFromText =
|
||||
OMap.toList
|
||||
>>> map (FieldName . G.unName *** P.handleTypename (mkTypename . G.unName))
|
||||
>>> map (FieldName . G.unName *** P.handleTypename (mkTypenameFromText . G.unName))
|
||||
|
||||
numericAggOperators :: [G.Name]
|
||||
numericAggOperators =
|
||||
@ -319,7 +321,7 @@ mkEnumTypeName (EnumReference enumTableName _ enumTableCustomName) = do
|
||||
addEnumSuffix enumTableGQLName enumTableCustomName
|
||||
|
||||
addEnumSuffix :: (MonadReader r m, Has MkTypename r) => G.Name -> Maybe G.Name -> m G.Name
|
||||
addEnumSuffix enumTableGQLName enumTableCustomName = P.mkTypename $ (fromMaybe enumTableGQLName enumTableCustomName) <> Name.__enum
|
||||
addEnumSuffix enumTableGQLName enumTableCustomName = mkTypename $ (fromMaybe enumTableGQLName enumTableCustomName) <> Name.__enum
|
||||
|
||||
-- TODO: figure out what the purpose of this method is.
|
||||
peelWithOrigin :: P.MonadParse m => P.Parser 'P.Both m a -> P.Parser 'P.Both m (IR.ValueWithOrigin a)
|
||||
|
@ -28,6 +28,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
@ -168,7 +169,7 @@ tableFieldsInput sourceInfo tableInfo =
|
||||
memoizeOn 'tableFieldsInput (_siName sourceInfo, tableName) do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectFields <- traverse mkFieldParser (Map.elems allFields)
|
||||
objectName <- P.mkTypename $ tableGQLName <> Name.__insert_input
|
||||
objectName <- mkTypename $ tableGQLName <> Name.__insert_input
|
||||
let objectDesc = G.Description $ "input type for inserting data into table " <>> tableName
|
||||
pure $ P.object objectName (Just objectDesc) $ coalesceFields objectFields
|
||||
where
|
||||
@ -261,7 +262,7 @@ objectRelationshipInput backendInsertAction sourceInfo tableInfo = runMaybeT $ d
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectParser <- tableFieldsInput sourceInfo tableInfo
|
||||
backendInsertParser <- backendInsertAction sourceInfo tableInfo
|
||||
inputName <- P.mkTypename $ tableGQLName <> Name.__obj_rel_insert_input
|
||||
inputName <- mkTypename $ tableGQLName <> Name.__obj_rel_insert_input
|
||||
let objectName = Name._data
|
||||
inputDesc = G.Description $ "input type for inserting object relation for remote table " <>> tableName
|
||||
inputParser = do
|
||||
@ -294,7 +295,7 @@ arrayRelationshipInput backendInsertAction sourceInfo tableInfo = runMaybeT $ do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectParser <- tableFieldsInput sourceInfo tableInfo
|
||||
backendInsertParser <- backendInsertAction sourceInfo tableInfo
|
||||
inputName <- P.mkTypename $ tableGQLName <> Name.__arr_rel_insert_input
|
||||
inputName <- mkTypename $ tableGQLName <> Name.__arr_rel_insert_input
|
||||
let objectsName = Name._data
|
||||
inputDesc = G.Description $ "input type for inserting array relation for remote table " <>> tableName
|
||||
inputParser = do
|
||||
@ -435,7 +436,7 @@ mutationSelectionSet sourceInfo tableInfo =
|
||||
let returningName = Name._returning
|
||||
returningDesc = "data from the rows affected by the mutation"
|
||||
pure $ IR.MRet <$> P.subselection_ returningName (Just returningDesc) tableSet
|
||||
selectionName <- P.mkTypename $ tableGQLName <> Name.__mutation_response
|
||||
selectionName <- mkTypename $ tableGQLName <> Name.__mutation_response
|
||||
let affectedRowsName = Name._affected_rows
|
||||
affectedRowsDesc = "number of rows affected by the mutation"
|
||||
selectionDesc = G.Description $ "response of any mutation on the table " <>> tableName
|
||||
|
31
server/src-lib/Hasura/GraphQL/Schema/NamingCase.hs
Normal file
31
server/src-lib/Hasura/GraphQL/Schema/NamingCase.hs
Normal file
@ -0,0 +1,31 @@
|
||||
module Hasura.GraphQL.Schema.NamingCase
|
||||
( NamingCase (..),
|
||||
parseNamingConventionFromText,
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Aeson qualified as Aeson
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.Prelude
|
||||
|
||||
-- | Represents the different possible type cases for fields and types, i.e.
|
||||
-- @HasuraCase@ and @GraphqlCase@ (@CamelCase@ fields and @PascalCase@ types).
|
||||
data NamingCase = HasuraCase | GraphqlCase
|
||||
deriving (Eq, Show, Generic)
|
||||
|
||||
instance Cacheable NamingCase
|
||||
|
||||
instance Aeson.ToJSON NamingCase where
|
||||
toJSON HasuraCase = Aeson.String "hasura-default"
|
||||
toJSON GraphqlCase = Aeson.String "graphql-default"
|
||||
|
||||
instance Aeson.FromJSON NamingCase where
|
||||
parseJSON = Aeson.withText "NamingCase" $ \s -> case parseNamingConventionFromText s of
|
||||
(Right nc) -> pure nc
|
||||
(Left err) -> fail err
|
||||
|
||||
-- Used for both the environment variable and JSON.
|
||||
parseNamingConventionFromText :: Text -> Either String NamingCase
|
||||
parseNamingConventionFromText "hasura-default" = Right HasuraCase
|
||||
parseNamingConventionFromText "graphql-default" = Right GraphqlCase
|
||||
parseNamingConventionFromText _ = Left "naming_convention can either be \"hasura-default\" or \"graphql-default\""
|
@ -12,6 +12,7 @@ import Data.Text.Extended
|
||||
import Hasura.GraphQL.Parser.Class
|
||||
import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( InputFieldsParser,
|
||||
Kind (..),
|
||||
@ -19,6 +20,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.OrderBy qualified as IR
|
||||
@ -66,7 +68,7 @@ orderByExp ::
|
||||
orderByExp sourceInfo tableInfo = memoizeOn 'orderByExp (_siName sourceInfo, tableInfoName tableInfo) $ do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
tCase <- asks getter
|
||||
name <- P.mkTypename $ tableGQLName <> Name.__order_by
|
||||
name <- mkTypename $ tableGQLName <> Name.__order_by
|
||||
let description =
|
||||
G.Description $
|
||||
"Ordering options when selecting data from " <> tableInfoName tableInfo <<> "."
|
||||
@ -161,7 +163,7 @@ orderByAggregation sourceInfo tableInfo = memoizeOn 'orderByAggregation (_siName
|
||||
tableGQLName <- getTableGQLName @b tableInfo
|
||||
tCase <- asks getter
|
||||
allColumns <- tableSelectColumns sourceInfo tableInfo
|
||||
mkTypename <- asks getter
|
||||
makeTypename <- asks getter
|
||||
let numColumns = onlyNumCols allColumns
|
||||
compColumns = onlyComparableCols allColumns
|
||||
numFields = catMaybes <$> traverse (mkField tCase) numColumns
|
||||
@ -182,15 +184,15 @@ orderByAggregation sourceInfo tableInfo = memoizeOn 'orderByAggregation (_siName
|
||||
then Nothing
|
||||
else Just $
|
||||
for numericAggOperators \operator ->
|
||||
parseOperator mkTypename operator tableGQLName numFields,
|
||||
parseOperator makeTypename operator tableGQLName numFields,
|
||||
-- operators on comparable columns
|
||||
if null compColumns
|
||||
then Nothing
|
||||
else Just $
|
||||
for comparisonAggOperators \operator ->
|
||||
parseOperator mkTypename operator tableGQLName compFields
|
||||
parseOperator makeTypename operator tableGQLName compFields
|
||||
]
|
||||
objectName <- P.mkTypename $ tableGQLName <> Name.__aggregate_order_by
|
||||
objectName <- mkTypename $ tableGQLName <> Name.__aggregate_order_by
|
||||
let description = G.Description $ "order by aggregate values of table " <>> tableName
|
||||
pure $ P.object objectName (Just description) aggFields
|
||||
where
|
||||
@ -205,14 +207,14 @@ orderByAggregation sourceInfo tableInfo = memoizeOn 'orderByAggregation (_siName
|
||||
<&> fmap (columnInfo,) . join
|
||||
|
||||
parseOperator ::
|
||||
P.MkTypename ->
|
||||
MkTypename ->
|
||||
G.Name ->
|
||||
G.Name ->
|
||||
InputFieldsParser n [(ColumnInfo b, (BasicOrderType b, NullsOrderType b))] ->
|
||||
InputFieldsParser n (Maybe [IR.OrderByItemG b (IR.AnnotatedAggregateOrderBy b)])
|
||||
parseOperator mkTypename operator tableGQLName columns =
|
||||
parseOperator makeTypename operator tableGQLName columns =
|
||||
let opText = G.unName operator
|
||||
objectName = P.runMkTypename mkTypename $ tableGQLName <> Name.__ <> operator <> Name.__order_by
|
||||
objectName = runMkTypename makeTypename $ tableGQLName <> Name.__ <> operator <> Name.__order_by
|
||||
objectDesc = Just $ G.Description $ "order by " <> opText <> "() on columns of table " <>> tableName
|
||||
in P.fieldOptional operator Nothing (P.object objectName objectDesc columns)
|
||||
`mapField` map (\(col, info) -> mkOrderByItemG (IR.AAOOp opText col) info)
|
||||
|
@ -28,6 +28,7 @@ import Hasura.GraphQL.Schema.Parser (Kind (..), Parser, memoizeOn)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (withTypenameCustomization)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR qualified as IR
|
||||
@ -65,7 +66,7 @@ nodeInterface sourceCache = NodeInterfaceParserBuilder $ memoizeOn 'nodeInterfac
|
||||
selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
|
||||
annotatedFieldsParser <-
|
||||
MaybeT $
|
||||
P.withTypenameCustomization
|
||||
withTypenameCustomization
|
||||
(mkCustomizedTypename (_scTypeNames $ _siCustomization sourceInfo) tCase)
|
||||
(tableSelectionSet sourceInfo tableInfo)
|
||||
pure $
|
||||
|
@ -26,6 +26,7 @@ import Hasura.GraphQL.Parser.Internal.TypeChecking qualified as P
|
||||
import Hasura.GraphQL.Parser.Name qualified as GName
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Parser as P
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.RemoteSchema qualified as IR
|
||||
import Hasura.RQL.IR.Root qualified as IR
|
||||
|
@ -13,11 +13,13 @@ import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Instances ()
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser (FieldParser, MonadSchema)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Remote
|
||||
import Hasura.GraphQL.Schema.Select
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename (withTypenameCustomization)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.RemoteRelationship.Validate
|
||||
@ -182,7 +184,7 @@ remoteRelationshipToSourceField ::
|
||||
RemoteSourceFieldInfo tgt ->
|
||||
m [FieldParser n (IR.RemoteSourceSelect (IR.RemoteRelationshipField IR.UnpreparedValue) IR.UnpreparedValue tgt)]
|
||||
remoteRelationshipToSourceField sourceCache RemoteSourceFieldInfo {..} =
|
||||
P.withTypenameCustomization (mkCustomizedTypename (Just _rsfiSourceCustomization) HasuraCase) do
|
||||
withTypenameCustomization (mkCustomizedTypename (Just _rsfiSourceCustomization) HasuraCase) do
|
||||
tCase <- asks getter
|
||||
sourceInfo <-
|
||||
onNothing (unsafeSourceInfo @tgt =<< Map.lookup _rsfiSource sourceCache) $
|
||||
|
@ -53,6 +53,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR qualified as IR
|
||||
@ -262,7 +263,7 @@ defaultSelectTableAggregate sourceInfo tableInfo fieldName description = runMayb
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
tableArgsParser <- tableArguments sourceInfo tableInfo
|
||||
aggregateParser <- tableAggregationFields sourceInfo tableInfo
|
||||
selectionName <- P.mkTypename $ tableGQLName <> Name.__aggregate
|
||||
selectionName <- mkTypename $ tableGQLName <> Name.__aggregate
|
||||
let aggregationParser =
|
||||
P.nonNullableParser $
|
||||
parsedSelectionsToFields IR.TAFExp
|
||||
@ -368,7 +369,7 @@ defaultTableSelectionSet sourceInfo tableInfo = runMaybeT do
|
||||
guard $ isHasuraSchema schemaKind || isJust (relayExtension @b)
|
||||
lift $ memoizeOn 'defaultTableSelectionSet (sourceName, tableName) do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
objectTypename <- P.mkTypename tableGQLName
|
||||
objectTypename <- mkTypename tableGQLName
|
||||
let xRelay = relayExtension @b
|
||||
tableFields = Map.elems $ _tciFieldInfoMap tableCoreInfo
|
||||
tablePkeyColumns = _pkColumns <$> _tciPrimaryKey tableCoreInfo
|
||||
@ -451,7 +452,7 @@ tableConnectionSelectionSet sourceInfo tableInfo = runMaybeT do
|
||||
_selectPermissions <- MaybeT $ tableSelectPermissions tableInfo
|
||||
edgesParser <- MaybeT $ tableEdgesSelectionSet tableGQLName
|
||||
lift $ memoizeOn 'tableConnectionSelectionSet (_siName sourceInfo, tableName) do
|
||||
connectionTypeName <- P.mkTypename $ tableGQLName <> Name._Connection
|
||||
connectionTypeName <- mkTypename $ tableGQLName <> Name._Connection
|
||||
let pageInfo =
|
||||
P.subselection_
|
||||
Name._pageInfo
|
||||
@ -512,7 +513,7 @@ tableConnectionSelectionSet sourceInfo tableInfo = runMaybeT do
|
||||
G.Name -> m (Maybe (Parser 'Output n (EdgeFields b)))
|
||||
tableEdgesSelectionSet tableGQLName = runMaybeT do
|
||||
edgeNodeParser <- MaybeT $ fmap P.nonNullableParser <$> tableSelectionSet sourceInfo tableInfo
|
||||
edgesType <- lift $ P.mkTypename $ tableGQLName <> Name._Edge
|
||||
edgesType <- lift $ mkTypename $ tableGQLName <> Name._Edge
|
||||
let cursor =
|
||||
P.selection_
|
||||
Name._cursor
|
||||
@ -843,9 +844,9 @@ tableAggregationFields sourceInfo tableInfo =
|
||||
let numericColumns = onlyNumCols allColumns
|
||||
comparableColumns = onlyComparableCols allColumns
|
||||
description = G.Description $ "aggregate fields of " <>> tableInfoName tableInfo
|
||||
selectName <- P.mkTypename $ tableGQLName <> Name.__aggregate_fields
|
||||
selectName <- mkTypename $ tableGQLName <> Name.__aggregate_fields
|
||||
count <- countField
|
||||
mkTypename <- asks getter
|
||||
makeTypename <- asks getter
|
||||
numericAndComparable <-
|
||||
fmap concat $
|
||||
sequenceA $
|
||||
@ -857,7 +858,7 @@ tableAggregationFields sourceInfo tableInfo =
|
||||
for numericAggOperators $ \operator -> do
|
||||
let fieldNameCase = applyFieldNameCaseCust tCase operator
|
||||
numFields <- mkNumericAggFields operator numericColumns
|
||||
pure $ parseAggOperator mkTypename operator fieldNameCase tableGQLName numFields,
|
||||
pure $ parseAggOperator makeTypename operator fieldNameCase tableGQLName numFields,
|
||||
-- operators on comparable columns
|
||||
if null comparableColumns
|
||||
then Nothing
|
||||
@ -866,7 +867,7 @@ tableAggregationFields sourceInfo tableInfo =
|
||||
pure $
|
||||
comparisonAggOperators & map \operator ->
|
||||
let fieldNameCase = applyFieldNameCaseCust tCase operator
|
||||
in parseAggOperator mkTypename operator fieldNameCase tableGQLName comparableFields
|
||||
in parseAggOperator makeTypename operator fieldNameCase tableGQLName comparableFields
|
||||
]
|
||||
let aggregateFields = count : numericAndComparable
|
||||
pure $
|
||||
@ -911,15 +912,15 @@ tableAggregationFields sourceInfo tableInfo =
|
||||
pure $ IR.AFCount <$> P.selection Name._count Nothing args P.int
|
||||
|
||||
parseAggOperator ::
|
||||
P.MkTypename ->
|
||||
MkTypename ->
|
||||
G.Name ->
|
||||
G.Name ->
|
||||
G.Name ->
|
||||
[FieldParser n (IR.ColFld b)] ->
|
||||
FieldParser n (IR.AggregateField b)
|
||||
parseAggOperator mkTypename operator fieldName tableGQLName columns =
|
||||
parseAggOperator makeTypename operator fieldName tableGQLName columns =
|
||||
let opText = G.unName operator
|
||||
setName = P.runMkTypename mkTypename $ tableGQLName <> Name.__ <> operator <> Name.__fields
|
||||
setName = runMkTypename makeTypename $ tableGQLName <> Name.__ <> operator <> Name.__fields
|
||||
setDesc = Just $ G.Description $ "aggregate " <> opText <> " on columns"
|
||||
subselectionParser =
|
||||
P.selectionSet setName setDesc columns
|
||||
|
@ -14,6 +14,7 @@ import Hasura.Base.Error (QErr)
|
||||
import Hasura.GraphQL.Parser.Class
|
||||
import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser
|
||||
( InputFieldsParser,
|
||||
Kind (..),
|
||||
@ -22,6 +23,7 @@ import Hasura.GraphQL.Schema.Parser
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Select (tablePermissionsInfo, tableSelectionList, tableWhereArg)
|
||||
import Hasura.GraphQL.Schema.Table (getTableGQLName, tableSelectColumns, tableSelectPermissions)
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.Select qualified as IR
|
||||
@ -29,7 +31,7 @@ import Hasura.RQL.IR.Value qualified as IR
|
||||
import Hasura.RQL.Types.Column
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase, applyFieldNameCaseCust, applyTypeNameCaseCust)
|
||||
import Hasura.RQL.Types.SourceCustomization (applyFieldNameCaseCust, applyTypeNameCaseCust)
|
||||
import Hasura.RQL.Types.Subscription
|
||||
import Hasura.RQL.Types.Table
|
||||
import Language.GraphQL.Draft.Syntax qualified as G
|
||||
@ -55,11 +57,11 @@ cursorBatchSizeArg tCase =
|
||||
-- > }
|
||||
cursorOrderingArgParser ::
|
||||
forall n m r.
|
||||
(MonadSchema n m, Has P.MkTypename r, Has NamingCase r, MonadReader r m) =>
|
||||
(MonadSchema n m, Has MkTypename r, Has NamingCase r, MonadReader r m) =>
|
||||
m (Parser 'Both n CursorOrdering)
|
||||
cursorOrderingArgParser = do
|
||||
tCase <- asks getter
|
||||
enumName <- P.mkTypename $ applyTypeNameCaseCust tCase Name._cursor_ordering
|
||||
enumName <- mkTypename $ applyTypeNameCaseCust tCase Name._cursor_ordering
|
||||
let description =
|
||||
Just $
|
||||
G.Description $
|
||||
@ -81,7 +83,7 @@ cursorOrderingArgParser = do
|
||||
-- > ordering: cursor_ordering
|
||||
cursorOrderingArg ::
|
||||
forall n m r.
|
||||
(MonadSchema n m, Has P.MkTypename r, Has NamingCase r, MonadReader r m) =>
|
||||
(MonadSchema n m, Has MkTypename r, Has NamingCase r, MonadReader r m) =>
|
||||
m (InputFieldsParser n (Maybe CursorOrdering))
|
||||
cursorOrderingArg = do
|
||||
cursorOrderingParser' <- cursorOrderingArgParser
|
||||
@ -92,7 +94,7 @@ cursorOrderingArg = do
|
||||
-- > column_name: column_type
|
||||
streamColumnParserArg ::
|
||||
forall b n m r.
|
||||
(BackendSchema b, MonadSchema n m, Has P.MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
(BackendSchema b, MonadSchema n m, Has MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
ColumnInfo b ->
|
||||
m (InputFieldsParser n (Maybe (ColumnInfo b, ColumnValue b)))
|
||||
streamColumnParserArg colInfo = do
|
||||
@ -114,7 +116,7 @@ streamColumnParserArg colInfo = do
|
||||
-- > }
|
||||
streamColumnValueParser ::
|
||||
forall b n m r.
|
||||
(BackendSchema b, MonadSchema n m, Has P.MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
(BackendSchema b, MonadSchema n m, Has MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
SourceInfo b ->
|
||||
G.Name ->
|
||||
[ColumnInfo b] ->
|
||||
@ -123,7 +125,7 @@ streamColumnValueParser sourceInfo tableGQLName colInfos =
|
||||
memoizeOn 'streamColumnValueParser (_siName sourceInfo, tableGQLName) $ do
|
||||
tCase <- asks getter
|
||||
columnVals <- sequenceA <$> traverse streamColumnParserArg colInfos
|
||||
objName <- P.mkTypename $ tableGQLName <> applyTypeNameCaseCust tCase Name.__stream_cursor_value_input
|
||||
objName <- mkTypename $ tableGQLName <> applyTypeNameCaseCust tCase Name.__stream_cursor_value_input
|
||||
pure do
|
||||
let description = G.Description $ "Initial value of the column from where the streaming should start"
|
||||
P.object objName (Just description) columnVals <&> catMaybes
|
||||
@ -134,7 +136,7 @@ streamColumnValueParserArg ::
|
||||
forall b n m r.
|
||||
( BackendSchema b,
|
||||
MonadSchema n m,
|
||||
Has P.MkTypename r,
|
||||
Has MkTypename r,
|
||||
MonadReader r m,
|
||||
MonadError QErr m,
|
||||
Has NamingCase r
|
||||
@ -155,7 +157,7 @@ streamColumnValueParserArg sourceInfo tableGQLName colInfos = do
|
||||
-- >
|
||||
tableStreamColumnArg ::
|
||||
forall n m r b.
|
||||
(BackendSchema b, MonadSchema n m, Has P.MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
(BackendSchema b, MonadSchema n m, Has MkTypename r, MonadReader r m, MonadError QErr m, Has NamingCase r) =>
|
||||
SourceInfo b ->
|
||||
G.Name ->
|
||||
[ColumnInfo b] ->
|
||||
@ -185,7 +187,7 @@ tableStreamCursorExp sourceInfo tableInfo =
|
||||
tCase <- asks getter
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
columnInfos <- tableSelectColumns sourceInfo tableInfo
|
||||
objName <- P.mkTypename $ tableGQLName <> applyTypeNameCaseCust tCase Name.__stream_cursor_input
|
||||
objName <- mkTypename $ tableGQLName <> applyTypeNameCaseCust tCase Name.__stream_cursor_input
|
||||
let description =
|
||||
G.Description $ "Streaming cursor of the table " <>> tableGQLName
|
||||
columnParsers <- tableStreamColumnArg sourceInfo tableGQLName columnInfos
|
||||
|
@ -24,6 +24,7 @@ import Hasura.GraphQL.Schema.Backend
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.Parser (Kind (..), Parser)
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Typename (mkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Backend
|
||||
@ -90,7 +91,7 @@ tableSelectColumnsEnum ::
|
||||
tableSelectColumnsEnum sourceInfo tableInfo = do
|
||||
tableGQLName <- getTableGQLName @b tableInfo
|
||||
columns <- tableSelectColumns sourceInfo tableInfo
|
||||
enumName <- P.mkTypename $ tableGQLName <> Name.__select_column
|
||||
enumName <- mkTypename $ tableGQLName <> Name.__select_column
|
||||
let description =
|
||||
Just $
|
||||
G.Description $
|
||||
@ -120,7 +121,7 @@ tableUpdateColumnsEnum ::
|
||||
tableUpdateColumnsEnum tableInfo = do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
columns <- tableUpdateColumns tableInfo
|
||||
enumName <- P.mkTypename $ tableGQLName <> Name.__update_column
|
||||
enumName <- mkTypename $ tableGQLName <> Name.__update_column
|
||||
let tableName = tableInfoName tableInfo
|
||||
enumDesc = Just $ G.Description $ "update columns of table " <>> tableName
|
||||
enumValues = do
|
||||
@ -143,7 +144,7 @@ updateColumnsPlaceholderParser tableInfo = do
|
||||
Just e -> pure $ Just <$> e
|
||||
Nothing -> do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
enumName <- P.mkTypename $ tableGQLName <> Name.__update_column
|
||||
enumName <- mkTypename $ tableGQLName <> Name.__update_column
|
||||
pure $
|
||||
P.enum enumName (Just $ G.Description $ "placeholder for update columns of table " <> tableInfoName tableInfo <<> " (current role has no relevant permissions)") $
|
||||
pure
|
||||
|
27
server/src-lib/Hasura/GraphQL/Schema/Typename.hs
Normal file
27
server/src-lib/Hasura/GraphQL/Schema/Typename.hs
Normal file
@ -0,0 +1,27 @@
|
||||
module Hasura.GraphQL.Schema.Typename
|
||||
( MkTypename (..),
|
||||
withTypenameCustomization,
|
||||
mkTypename,
|
||||
)
|
||||
where
|
||||
|
||||
import Control.Lens (set)
|
||||
import Data.Has (Has (..))
|
||||
import Data.Monoid (Endo (..))
|
||||
import Hasura.Prelude
|
||||
import Language.GraphQL.Draft.Syntax (Name)
|
||||
|
||||
-- | Type name customization
|
||||
newtype MkTypename = MkTypename {runMkTypename :: Name -> Name}
|
||||
deriving (Semigroup, Monoid) via (Endo Name)
|
||||
|
||||
-- | Inject a new @MkTypename@ customization function into the environment.
|
||||
-- This can be used by schema-building code (with @MonadBuildSchema@ constraint) to ensure
|
||||
-- the correct type name customizations are applied.
|
||||
withTypenameCustomization :: forall m r a. (MonadReader r m, Has MkTypename r) => MkTypename -> m a -> m a
|
||||
withTypenameCustomization = local . set hasLens
|
||||
|
||||
-- | Apply the type name customization function from the current environment.
|
||||
mkTypename :: (MonadReader r m, Has MkTypename r) => Name -> m Name
|
||||
mkTypename name =
|
||||
($ name) . runMkTypename <$> asks getter
|
@ -25,8 +25,10 @@ import Hasura.GraphQL.Schema.Backend (BackendSchema (..), BackendTableSelectSche
|
||||
import Hasura.GraphQL.Schema.BoolExp (boolExp)
|
||||
import Hasura.GraphQL.Schema.Common (Scenario (..), mapField, partialSQLExpToUnpreparedValue)
|
||||
import Hasura.GraphQL.Schema.Mutation (mutationSelectionSet, primaryKeysArguments)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Table (getTableGQLName, tableColumns, tablePermissions, tableUpdateColumns)
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp (AnnBoolExp, annBoolExpTrue)
|
||||
import Hasura.RQL.IR.Returning (MutationOutputG (..))
|
||||
@ -36,7 +38,6 @@ import Hasura.RQL.IR.Value
|
||||
import Hasura.RQL.Types.Backend (Backend (..))
|
||||
import Hasura.RQL.Types.Column (ColumnInfo (..), isNumCol)
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Language.GraphQL.Draft.Syntax (Description (..), Name (..), Nullability (..), litName)
|
||||
|
||||
@ -169,7 +170,7 @@ mergeDisjoint parsedResults = do
|
||||
-- > M.fromList [("col1", MkOp (fp "x")), ("col2", MkOp (fp "y"))]
|
||||
updateOperator ::
|
||||
forall n r m b a.
|
||||
(P.MonadParse n, MonadReader r m, Has P.MkTypename r, Backend b) =>
|
||||
(P.MonadParse n, MonadReader r m, Has MkTypename r, Backend b) =>
|
||||
Name ->
|
||||
Name ->
|
||||
(ColumnInfo b -> m (P.Parser 'P.Both n a)) ->
|
||||
@ -187,7 +188,7 @@ updateOperator tableGQLName opName mkParser columns opDesc objDesc = do
|
||||
P.fieldOptional fieldName fieldDesc fieldParser
|
||||
`mapField` \value -> (ciColumn columnInfo, value)
|
||||
|
||||
objName <- P.mkTypename $ tableGQLName <> opName <> $$(litName "_input")
|
||||
objName <- mkTypename $ tableGQLName <> opName <> $$(litName "_input")
|
||||
|
||||
pure $
|
||||
fmap (M.fromList . (fold :: Maybe [(Column b, a)] -> [(Column b, a)])) $
|
||||
@ -200,7 +201,7 @@ setOp ::
|
||||
forall b n r m.
|
||||
( BackendSchema b,
|
||||
MonadReader r m,
|
||||
Has P.MkTypename r,
|
||||
Has MkTypename r,
|
||||
Has NamingCase r,
|
||||
MonadError QErr m,
|
||||
P.MonadSchema n m
|
||||
@ -232,7 +233,7 @@ incOp ::
|
||||
MonadError QErr m,
|
||||
P.MonadSchema n m,
|
||||
BackendSchema b,
|
||||
Has P.MkTypename r,
|
||||
Has MkTypename r,
|
||||
Has NamingCase r
|
||||
) =>
|
||||
UpdateOperator b m n (UnpreparedValue b)
|
||||
@ -326,7 +327,7 @@ updateTableByPk backendUpdate scenario sourceInfo tableInfo fieldName descriptio
|
||||
selection <- MaybeT $ tableSelectionSet sourceInfo tableInfo
|
||||
lift $ do
|
||||
tableGQLName <- getTableGQLName tableInfo
|
||||
pkObjectName <- P.mkTypename $ tableGQLName <> $$(litName "_pk_columns_input")
|
||||
pkObjectName <- mkTypename $ tableGQLName <> $$(litName "_pk_columns_input")
|
||||
let pkFieldName = $$(litName "pk_columns")
|
||||
pkObjectDesc = Description $ "primary key columns input for table: " <> unName tableGQLName
|
||||
pkParser = P.object pkObjectName (Just pkObjectDesc) pkArgs
|
||||
|
@ -40,6 +40,7 @@ import Data.These (These (..))
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Execute.Types
|
||||
import Hasura.GraphQL.Schema (buildGQLContext)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Incremental qualified as Inc
|
||||
import Hasura.Logging
|
||||
import Hasura.Metadata.Class
|
||||
|
@ -38,6 +38,7 @@ import Hasura.GraphQL.Context
|
||||
import Hasura.GraphQL.Namespace
|
||||
import Hasura.GraphQL.Parser.Name qualified as GName
|
||||
import Hasura.GraphQL.Schema.Common (textToName)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Incremental qualified as Inc
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.Schema.Cache.Common
|
||||
@ -53,7 +54,7 @@ import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.SchemaCache.Build
|
||||
import Hasura.RQL.Types.SchemaCacheTypes
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase, applyFieldNameCaseCust)
|
||||
import Hasura.RQL.Types.SourceCustomization (applyFieldNameCaseCust)
|
||||
import Hasura.RQL.Types.Table
|
||||
import Hasura.SQL.AnyBackend qualified as AB
|
||||
import Hasura.SQL.Backend
|
||||
|
@ -7,6 +7,7 @@ import Control.Monad.Trans.Control (MonadBaseControl)
|
||||
import Data.Aeson
|
||||
import Data.Environment qualified as Env
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Logging (Hasura, Logger)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.BoolExp
|
||||
|
@ -55,6 +55,7 @@ import Data.URL.Template (printURLTemplate)
|
||||
import Database.PG.Query qualified as Q
|
||||
import Hasura.Base.Error
|
||||
import Hasura.GraphQL.Parser.Variable
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Incremental (Cacheable)
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.DDL.Headers (HeaderConf (..))
|
||||
|
@ -2,8 +2,7 @@
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
|
||||
module Hasura.RQL.Types.SourceCustomization
|
||||
( MkTypename (..),
|
||||
SourceTypeCustomization,
|
||||
( SourceTypeCustomization,
|
||||
RootFieldsCustomization (..),
|
||||
mkCustomizedTypename,
|
||||
emptySourceCustomization,
|
||||
@ -17,7 +16,6 @@ module Hasura.RQL.Types.SourceCustomization
|
||||
withRemoteFieldNameCustomization,
|
||||
|
||||
-- * Naming Convention specific
|
||||
NamingCase (..),
|
||||
applyEnumValueCase,
|
||||
applyFieldNameCaseCust,
|
||||
applyTypeNameCaseCust,
|
||||
@ -26,7 +24,6 @@ module Hasura.RQL.Types.SourceCustomization
|
||||
getNamingConvention,
|
||||
getTextFieldName,
|
||||
getTextTypeName,
|
||||
parseNamingConventionFromText,
|
||||
|
||||
-- * Field name builders
|
||||
mkSelectField,
|
||||
@ -44,7 +41,6 @@ module Hasura.RQL.Types.SourceCustomization
|
||||
where
|
||||
|
||||
import Control.Lens
|
||||
import Data.Aeson qualified as J
|
||||
import Data.Aeson.Extended
|
||||
import Data.Has
|
||||
import Data.List.NonEmpty qualified as NE
|
||||
@ -53,7 +49,8 @@ import Data.Text qualified as T
|
||||
import Data.Text.Casing (GQLNameIdentifier (..))
|
||||
import Data.Text.Casing qualified as C
|
||||
import Hasura.Base.Error (Code (NotSupported), QErr, throw400)
|
||||
import Hasura.GraphQL.Parser.Names
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Incremental.Internal.Dependency (Cacheable)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
@ -96,31 +93,6 @@ instance FromJSON SourceTypeCustomization where
|
||||
emptySourceTypeCustomization :: SourceTypeCustomization
|
||||
emptySourceTypeCustomization = SourceTypeCustomization Nothing Nothing
|
||||
|
||||
-- | Represents the different possible type cases for fields and types, i.e.
|
||||
-- @HasuraCase@ and @GraphqlCase@ (@CamelCase@ fields and @PascalCase@ types).
|
||||
data NamingCase = HasuraCase | GraphqlCase
|
||||
deriving (Eq, Show, Generic)
|
||||
|
||||
instance Cacheable NamingCase
|
||||
|
||||
instance ToJSON NamingCase where
|
||||
toJSON HasuraCase = J.String "hasura-default"
|
||||
toJSON GraphqlCase = J.String "graphql-default"
|
||||
|
||||
instance FromJSON NamingCase where
|
||||
parseJSON = withText "NamingCase" $ \s -> case parseNamingConventionFromText s of
|
||||
(Right nc) -> pure nc
|
||||
(Left err) -> fail err
|
||||
|
||||
-- NOTE: This is used in parsing JSON as well as in parsing environment
|
||||
-- variable.
|
||||
|
||||
-- | parses naming convention from @Text@
|
||||
parseNamingConventionFromText :: Text -> Either String NamingCase
|
||||
parseNamingConventionFromText "hasura-default" = Right HasuraCase
|
||||
parseNamingConventionFromText "graphql-default" = Right GraphqlCase
|
||||
parseNamingConventionFromText _ = Left "naming_convention can either be \"hasura-default\" or \"graphql-default\""
|
||||
|
||||
mkCustomizedTypename :: Maybe SourceTypeCustomization -> NamingCase -> MkTypename
|
||||
mkCustomizedTypename stc tCase = MkTypename ((applyTypeNameCaseCust tCase) . (applyTypeCust stc tCase))
|
||||
|
||||
|
@ -53,6 +53,7 @@ import Hasura.GraphQL.Execute.Subscription.Poll qualified as ES
|
||||
import Hasura.GraphQL.Execute.Subscription.State qualified as ES
|
||||
import Hasura.GraphQL.Explain qualified as GE
|
||||
import Hasura.GraphQL.Logging (MonadQueryLog)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Transport.HTTP qualified as GH
|
||||
import Hasura.GraphQL.Transport.HTTP.Protocol qualified as GH
|
||||
import Hasura.GraphQL.Transport.WSServerApp qualified as WS
|
||||
@ -68,7 +69,6 @@ import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.RemoteSchema
|
||||
import Hasura.RQL.Types.SchemaCache
|
||||
import Hasura.RQL.Types.Source
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.SQL.Backend
|
||||
import Hasura.Server.API.Config (runGetConfig)
|
||||
import Hasura.Server.API.Metadata
|
||||
|
@ -26,13 +26,13 @@ import Hasura.Base.Error
|
||||
import Hasura.Cache.Bounded qualified as Cache (CacheSize, parseCacheSize)
|
||||
import Hasura.Eventing.EventTrigger (defaultFetchBatchSize)
|
||||
import Hasura.GraphQL.Execute.Subscription.Options qualified as ES
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Logging (defaultEnabledEngineLogTypes, userAllowedLogTypes)
|
||||
import Hasura.Logging qualified as L
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.RemoteSchema
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.Server.Auth
|
||||
import Hasura.Server.Cors
|
||||
import Hasura.Server.Init.Config
|
||||
|
@ -53,12 +53,12 @@ import Data.Time
|
||||
import Data.URL.Template
|
||||
import Database.PG.Query qualified as Q
|
||||
import Hasura.GraphQL.Execute.Subscription.Options qualified as ES
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Logging qualified as L
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.RemoteSchema
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase, parseNamingConventionFromText)
|
||||
import Hasura.Server.Auth
|
||||
import Hasura.Server.Cors
|
||||
import Hasura.Server.Logging
|
||||
|
@ -21,11 +21,11 @@ where
|
||||
import Data.Aeson
|
||||
import Data.HashSet qualified as Set
|
||||
import Database.PG.Query qualified as Q
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Common
|
||||
import Hasura.RQL.Types.Function
|
||||
import Hasura.RQL.Types.RemoteSchema
|
||||
import Hasura.RQL.Types.SourceCustomization (NamingCase)
|
||||
import Hasura.Server.Utils
|
||||
import Network.HTTP.Types qualified as HTTP
|
||||
|
||||
|
@ -22,8 +22,10 @@ import Hasura.GraphQL.Parser.Names
|
||||
import Hasura.GraphQL.Parser.TestUtils
|
||||
import Hasura.GraphQL.Parser.Variable
|
||||
import Hasura.GraphQL.Schema.Common
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Parser qualified as P
|
||||
import Hasura.GraphQL.Schema.Remote
|
||||
import Hasura.GraphQL.Schema.Typename (MkTypename)
|
||||
import Hasura.Name qualified as Name
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.IR.RemoteSchema
|
||||
|
@ -16,13 +16,14 @@ import Data.Has (Has (..))
|
||||
import Data.Text qualified as T
|
||||
import Hasura.Base.Error (Code, QErr)
|
||||
import Hasura.GraphQL.Parser.Class (MonadParse (..), MonadSchema (..))
|
||||
import Hasura.GraphQL.Parser.Names (MkTypename (..))
|
||||
import Hasura.GraphQL.Schema.Common (SchemaContext (..), SchemaKind (..), SchemaOptions (..), ignoreRemoteRelationship)
|
||||
import Hasura.GraphQL.Schema.NamingCase
|
||||
import Hasura.GraphQL.Schema.Typename
|
||||
import Hasura.Prelude
|
||||
import Hasura.RQL.Types.Common (StringifyNumbers (LeaveNumbersAlone))
|
||||
import Hasura.RQL.Types.Function (FunctionPermissionsCtx (..))
|
||||
import Hasura.RQL.Types.RemoteSchema (RemoteSchemaPermsCtx (..))
|
||||
import Hasura.RQL.Types.SourceCustomization (CustomizeRemoteFieldName, MkRootFieldName, NamingCase (..))
|
||||
import Hasura.RQL.Types.SourceCustomization (CustomizeRemoteFieldName, MkRootFieldName)
|
||||
import Hasura.Session (RoleName, adminRoleName)
|
||||
import Language.Haskell.TH.Syntax qualified as TH
|
||||
import Test.Hspec
|
||||
|
Loading…
Reference in New Issue
Block a user