[server]: feature flag to remove _stream fields from schema

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6698
GitOrigin-RevId: d2b80900d06353647505256fc351a07e6f7cd5f7
This commit is contained in:
Daniel Harvey 2022-11-04 13:08:40 +00:00 committed by hasura-bot
parent 381c81c806
commit e6c3113a43
9 changed files with 100 additions and 14 deletions

View File

@ -624,7 +624,9 @@ Interval in milliseconds to sleep before trying to fetch events again after a fe
<td>
List of experimental features to be enabled. A comma separated value is expected. Options: `inherited_roles`,
`naming_convention`, `streaming_subscriptions`, `hide_update_many_fields`.
`optimise_permission_filters`, `naming_convention`, `streaming_subscriptions`, `apollo_federation`, `hide_update_many_fields`,
`bigquery_string_numeric_input`, `hide_aggregation_predicates`,
`hide_stream_fields`.
_(Available for versions > v2.0.0)_

View File

@ -140,6 +140,7 @@ executable api-tests
Test.Regression.NullRemoteRelationship8345Spec
Test.Regression.NullsOrderParsing8780Spec
Test.Regression.ObjectRelationshipsLimit7936Spec
Test.Regression.StreamConflictSpec
Test.Regression.UsingTheSameFunctionForRootFieldAndComputedField8643Spec
Test.RemoteRelationship.FromRemoteSchemaSpec
Test.RemoteRelationship.MetadataAPI.ClearMetadataSpec

View File

@ -0,0 +1,60 @@
-- | Test the schema names conflict of <table_name>_stream
module Test.Regression.StreamConflictSpec (spec) where
import Data.List.NonEmpty qualified as NE
import Harness.Backend.Postgres qualified as Postgres
import Harness.Test.Fixture qualified as Fixture
import Harness.Test.Schema (Table (..), table)
import Harness.Test.Schema qualified as Schema
import Harness.TestEnvironment (TestEnvironment)
import Hasura.Prelude
import Test.Hspec (SpecWith, it)
spec :: SpecWith TestEnvironment
spec =
Fixture.run
( NE.fromList
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
{ Fixture.setupTeardown = \(testEnv, _) ->
[ Postgres.setupTablesAction schema testEnv
],
Fixture.customOptions =
Just $
Fixture.defaultOptions
{ Fixture.skipTests =
Just "Disabled until we can dynamically change server settings per test. To test, add EFHideStreamFields to soSubscriptions in Harness.Constants -> serveOptions"
}
}
]
)
tests
--------------------------------------------------------------------------------
-- Schema
schema :: [Schema.Table]
schema =
[ (table "author")
{ tableColumns =
[ Schema.column "id" Schema.defaultSerialType,
Schema.column "name" Schema.TStr
],
tablePrimaryKey = ["id"]
},
(table "author_stream")
{ tableColumns =
[ Schema.column "id" Schema.defaultSerialType,
Schema.column "name" Schema.TStr
],
tablePrimaryKey = ["id"]
}
]
--------------------------------------------------------------------------------
-- Tests
tests :: Fixture.Options -> SpecWith TestEnvironment
tests _ =
-- All of the testing is done during setup.
-- If setup succeeds and we have no conflicts, and this test will pass.
it "Creates a schema without conflicts" \_ -> pure @IO ()

View File

@ -409,7 +409,7 @@ pgkBuildTableUpdateMutationFields mkRootFieldName scenario sourceInfo tableName
pure $ case soIncludeUpdateManyFields of
Options.IncludeUpdateManyFields ->
singleUpdates ++ maybeToList multiUpdate
Options.DontIncludeUpdateManyFields ->
Options.Don'tIncludeUpdateManyFields ->
singleUpdates
-- | Create a parser for 'update_table_many'. This function is very similar to

View File

@ -189,12 +189,16 @@ buildSchemaOptions
soOptimizePermissionFilters = optimizePermissionFilters,
soIncludeUpdateManyFields =
if EFHideUpdateManyFields `Set.member` expFeatures
then Options.DontIncludeUpdateManyFields
then Options.Don'tIncludeUpdateManyFields
else Options.IncludeUpdateManyFields,
soIncludeAggregationPredicates =
if EFHideAggregationPredicates `Set.member` expFeatures
then Options.Don'tIncludeAggregationPredicates
else Options.IncludeAggregationPredicates,
soIncludeStreamFields =
if EFHideStreamFields `Set.member` expFeatures
then Options.Don'tIncludeStreamFields
else Options.IncludeStreamFields,
soBigQueryStringNumericInput = bigqueryStringNumericInput
}

View File

@ -212,16 +212,22 @@ buildTableStreamingSubscriptionFields ::
C.GQLNameIdentifier ->
SchemaT r m [FieldParser n (QueryDB b (RemoteRelationshipField UnpreparedValue) (UnpreparedValue b))]
buildTableStreamingSubscriptionFields mkRootFieldName sourceInfo tableName tableInfo tableIdentifier = do
tCase <- asks getter
let customRootFields = _tcCustomRootFields $ _tciCustomConfig $ _tiCoreInfo tableInfo
selectDesc = Just $ G.Description $ "fetch data from the table in a streaming manner: " <>> tableName
selectStreamName =
runMkRootFieldName mkRootFieldName $
setFieldNameCase tCase tableInfo (_tcrfSelectStream customRootFields) mkSelectStreamField tableIdentifier
catMaybes
<$> sequenceA
[ optionalFieldParser QDBStreamMultipleRows $ selectStreamTable sourceInfo tableInfo selectStreamName selectDesc
]
-- Check in schema options whether we should include streaming subscription
-- fields
include <- retrieve Options.soIncludeStreamFields
case include of
Options.Don'tIncludeStreamFields -> pure mempty
Options.IncludeStreamFields -> do
tCase <- asks getter
let customRootFields = _tcCustomRootFields $ _tciCustomConfig $ _tiCoreInfo tableInfo
selectDesc = Just $ G.Description $ "fetch data from the table in a streaming manner: " <>> tableName
selectStreamName =
runMkRootFieldName mkRootFieldName $
setFieldNameCase tCase tableInfo (_tcrfSelectStream customRootFields) mkSelectStreamField tableIdentifier
catMaybes
<$> sequenceA
[ optionalFieldParser QDBStreamMultipleRows $ selectStreamTable sourceInfo tableInfo selectStreamName selectDesc
]
buildTableInsertMutationFields ::
forall b r m n.

View File

@ -8,6 +8,7 @@ module Hasura.GraphQL.Schema.Options
RemoteSchemaPermissions (..),
OptimizePermissionFilters (..),
IncludeAggregationPredicates (..),
IncludeStreamFields (..),
IncludeUpdateManyFields (..),
BigQueryStringNumericInput (..),
)
@ -25,6 +26,7 @@ data SchemaOptions = SchemaOptions
soOptimizePermissionFilters :: OptimizePermissionFilters,
soIncludeUpdateManyFields :: IncludeUpdateManyFields,
soIncludeAggregationPredicates :: IncludeAggregationPredicates,
soIncludeStreamFields :: IncludeStreamFields,
soBigQueryStringNumericInput :: BigQueryStringNumericInput
}
@ -42,7 +44,15 @@ data StringifyNumbers
-- any tables that this may conflict with if needed
data IncludeUpdateManyFields
= IncludeUpdateManyFields
| DontIncludeUpdateManyFields
| Don'tIncludeUpdateManyFields
deriving (Eq, Show)
-- | Should we include `TABLE_stream` fields in schemas
-- This is a toggle so that users can opt-in, and so that we can rename
-- any tables that this may conflict with if needed
data IncludeStreamFields
= IncludeStreamFields
| Don'tIncludeStreamFields
deriving (Eq, Show)
-- | Should we include aggregation functions in where clauses?

View File

@ -82,6 +82,7 @@ data ExperimentalFeature
| EFHideUpdateManyFields
| EFBigQueryStringNumericInput
| EFHideAggregationPredicates
| EFHideStreamFields
deriving (Bounded, Enum, Eq, Generic, Show)
experimentalFeatureKey :: ExperimentalFeature -> Text
@ -94,6 +95,7 @@ experimentalFeatureKey = \case
EFHideUpdateManyFields -> "hide_update_many_fields"
EFBigQueryStringNumericInput -> "bigquery_string_numeric_input"
EFHideAggregationPredicates -> "hide_aggregation_predicates"
EFHideStreamFields -> "hide_stream_fields"
instance Hashable ExperimentalFeature

View File

@ -64,6 +64,7 @@ defaultSchemaOptions =
soOptimizePermissionFilters = Options.Don'tOptimizePermissionFilters,
soIncludeUpdateManyFields = Options.IncludeUpdateManyFields,
soIncludeAggregationPredicates = Options.IncludeAggregationPredicates,
soIncludeStreamFields = Options.IncludeStreamFields,
soBigQueryStringNumericInput = Options.EnableBigQueryStringNumericInput
}