Revert "Reapply "subscriptions: Unhide OpenDd Metadata and lift from unstability" " (#1256)

I am sorry @rakeshkky , we will merge this again once we've done a
release, I promise.

Reverts hasura/v3-engine#1254

V3_GIT_ORIGIN_REV_ID: 74236d25d4e84658717531a55d87c8d3371b553c
This commit is contained in:
Daniel Harvey 2024-10-21 21:41:45 +01:00 committed by hasura-bot
parent 30d38fa599
commit 927268ae03
16 changed files with 45 additions and 120 deletions

View File

@ -19,6 +19,7 @@
pub enum UnstableFeature { pub enum UnstableFeature {
EnableOrderByExpressions, EnableOrderByExpressions,
EnableNdcV02Support, EnableNdcV02Support,
EnableSubscriptions,
EnableJsonApi, EnableJsonApi,
EnableAggregationPredicates, EnableAggregationPredicates,
} }
@ -36,6 +37,9 @@ pub fn resolve_unstable_features(
UnstableFeature::EnableNdcV02Support => { UnstableFeature::EnableNdcV02Support => {
features.enable_ndc_v02_support = true; features.enable_ndc_v02_support = true;
} }
UnstableFeature::EnableSubscriptions => {
features.enable_subscriptions = true;
}
UnstableFeature::EnableJsonApi => { UnstableFeature::EnableJsonApi => {
features.enable_jsonapi = true; features.enable_jsonapi = true;
} }

View File

@ -456,6 +456,7 @@ pub fn test_execute_explain(
unstable_features: metadata_resolve::configuration::UnstableFeatures { unstable_features: metadata_resolve::configuration::UnstableFeatures {
enable_order_by_expressions: false, enable_order_by_expressions: false,
enable_ndc_v02_support: true, enable_ndc_v02_support: true,
enable_subscriptions: false,
enable_jsonapi: false, enable_jsonapi: false,
..Default::default() ..Default::default()
}, },
@ -517,6 +518,7 @@ pub(crate) fn test_metadata_resolve_configuration() -> metadata_resolve::configu
unstable_features: metadata_resolve::configuration::UnstableFeatures { unstable_features: metadata_resolve::configuration::UnstableFeatures {
enable_order_by_expressions: false, enable_order_by_expressions: false,
enable_ndc_v02_support: true, enable_ndc_v02_support: true,
enable_subscriptions: true,
enable_jsonapi: false, enable_jsonapi: false,
..Default::default() ..Default::default()
}, },

View File

@ -59,7 +59,12 @@ pub(crate) async fn start_websocket_server() -> TestServer {
let metadata_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(METADATA_PATH); let metadata_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(METADATA_PATH);
let raw_metadata = std::fs::read_to_string(metadata_path).unwrap(); let raw_metadata = std::fs::read_to_string(metadata_path).unwrap();
let metadata = open_dds::Metadata::from_json_str(&raw_metadata).unwrap(); let metadata = open_dds::Metadata::from_json_str(&raw_metadata).unwrap();
let metadata_resolve_configuration = metadata_resolve::configuration::Configuration::default(); let metadata_resolve_configuration = metadata_resolve::configuration::Configuration {
unstable_features: metadata_resolve::configuration::UnstableFeatures {
enable_subscriptions: true,
..Default::default()
},
};
let (resolved_metadata, _warnings) = let (resolved_metadata, _warnings) =
metadata_resolve::resolve(metadata, &metadata_resolve_configuration).unwrap(); metadata_resolve::resolve(metadata, &metadata_resolve_configuration).unwrap();

View File

@ -179,6 +179,7 @@ fn get_metadata_resolve_configuration() -> metadata_resolve::configuration::Conf
let unstable_features = metadata_resolve::configuration::UnstableFeatures { let unstable_features = metadata_resolve::configuration::UnstableFeatures {
enable_order_by_expressions: false, enable_order_by_expressions: false,
enable_ndc_v02_support: false, enable_ndc_v02_support: false,
enable_subscriptions: true,
enable_jsonapi: true, enable_jsonapi: true,
enable_aggregation_predicates: false, enable_aggregation_predicates: false,
}; };

View File

@ -262,6 +262,7 @@ fn fallback_graphql_config() -> &'static graphql_config::GraphqlConfig {
mutation: graphql_config::MutationGraphqlConfig { mutation: graphql_config::MutationGraphqlConfig {
root_operation_type_name: GraphQlTypeName::from("Mutation"), root_operation_type_name: GraphQlTypeName::from("Mutation"),
}, },
// TODO: Subscriptions are still unsupported. No need to consider them for now.
subscription: None, subscription: None,
apollo_federation: None, apollo_federation: None,
}) })

View File

@ -274,6 +274,7 @@ pub fn resolve(
&order_by_expressions, &order_by_expressions,
&graphql_types, &graphql_types,
&graphql_config, &graphql_config,
configuration,
)?; )?;
all_issues.extend(issues); all_issues.extend(issues);

View File

@ -11,6 +11,7 @@ use super::types::{
SelectAggregateGraphQlDefinition, SelectManyGraphQlDefinition, SelectUniqueGraphQlDefinition, SelectAggregateGraphQlDefinition, SelectManyGraphQlDefinition, SelectUniqueGraphQlDefinition,
SubscriptionGraphQlDefinition, UniqueIdentifierField, SubscriptionGraphQlDefinition, UniqueIdentifierField,
}; };
use crate::configuration::Configuration;
use crate::helpers::types::{mk_name, store_new_graphql_type}; use crate::helpers::types::{mk_name, store_new_graphql_type};
use crate::stages::order_by_expressions::OrderByExpressions; use crate::stages::order_by_expressions::OrderByExpressions;
use crate::stages::{data_connector_scalar_types, graphql_config, models, object_types}; use crate::stages::{data_connector_scalar_types, graphql_config, models, object_types};
@ -35,6 +36,7 @@ pub(crate) fn resolve_model_graphql_api(
aggregate_expression_name: &Option<Qualified<AggregateExpressionName>>, aggregate_expression_name: &Option<Qualified<AggregateExpressionName>>,
order_by_expressions: &OrderByExpressions, order_by_expressions: &OrderByExpressions,
graphql_config: &graphql_config::GraphqlConfig, graphql_config: &graphql_config::GraphqlConfig,
configuration: &Configuration,
issues: &mut Vec<Warning>, issues: &mut Vec<Warning>,
) -> Result<ModelGraphQlApi, Error> { ) -> Result<ModelGraphQlApi, Error> {
let model_name = &model.name; let model_name = &model.name;
@ -92,7 +94,7 @@ pub(crate) fn resolve_model_graphql_api(
let subscription = select_unique let subscription = select_unique
.subscription .subscription
.as_ref() .as_ref()
.map(resolve_subscription_graphql_api) .map(|s| resolve_subscription_graphql_api(s, configuration))
.transpose()?; .transpose()?;
graphql_api graphql_api
.select_uniques .select_uniques
@ -169,7 +171,7 @@ pub(crate) fn resolve_model_graphql_api(
let subscription = gql_definition let subscription = gql_definition
.subscription .subscription
.as_ref() .as_ref()
.map(resolve_subscription_graphql_api) .map(|s| resolve_subscription_graphql_api(s, configuration))
.transpose()?; .transpose()?;
mk_name(gql_definition.query_root_field.as_str()).map(|f: ast::Name| { mk_name(gql_definition.query_root_field.as_str()).map(|f: ast::Name| {
let select_many_description = if gql_definition.description.is_some() { let select_many_description = if gql_definition.description.is_some() {
@ -240,7 +242,7 @@ pub(crate) fn resolve_model_graphql_api(
let subscription = graphql_aggregate let subscription = graphql_aggregate
.subscription .subscription
.as_ref() .as_ref()
.map(resolve_subscription_graphql_api) .map(|s| resolve_subscription_graphql_api(s, configuration))
.transpose()?; .transpose()?;
Some(SelectAggregateGraphQlDefinition { Some(SelectAggregateGraphQlDefinition {
@ -334,8 +336,12 @@ fn is_model_used_in_any_aggregate_relationship(
fn resolve_subscription_graphql_api( fn resolve_subscription_graphql_api(
subscription: &open_dds::models::SubscriptionGraphQlDefinition, subscription: &open_dds::models::SubscriptionGraphQlDefinition,
configuration: &Configuration,
) -> Result<SubscriptionGraphQlDefinition, Error> { ) -> Result<SubscriptionGraphQlDefinition, Error> {
// Subscriptions are currently unstable. // Subscriptions are currently unstable.
if !configuration.unstable_features.enable_subscriptions {
return Err(Error::UnstableFeatureSubscriptions);
}
let open_dds::models::SubscriptionGraphQlDefinition { let open_dds::models::SubscriptionGraphQlDefinition {
root_field, root_field,
description, description,

View File

@ -9,6 +9,7 @@ use std::collections::{BTreeMap, BTreeSet};
use lang_graphql::ast::common as ast; use lang_graphql::ast::common as ast;
use open_dds::{data_connector::DataConnectorName, models::ModelName, types::CustomTypeName}; use open_dds::{data_connector::DataConnectorName, models::ModelName, types::CustomTypeName};
use crate::configuration::Configuration;
use crate::stages::{ use crate::stages::{
boolean_expressions, data_connector_scalar_types, graphql_config, models, boolean_expressions, data_connector_scalar_types, graphql_config, models,
object_boolean_expressions, object_relationships, object_boolean_expressions, object_relationships,
@ -44,6 +45,7 @@ pub fn resolve(
order_by_expressions: &order_by_expressions::OrderByExpressions, order_by_expressions: &order_by_expressions::OrderByExpressions,
existing_graphql_types: &BTreeSet<ast::TypeName>, existing_graphql_types: &BTreeSet<ast::TypeName>,
graphql_config: &graphql_config::GraphqlConfig, graphql_config: &graphql_config::GraphqlConfig,
configuration: &Configuration,
) -> Result<ModelsWithGraphqlOutput, Error> { ) -> Result<ModelsWithGraphqlOutput, Error> {
let mut output = ModelsWithGraphqlOutput { let mut output = ModelsWithGraphqlOutput {
models_with_graphql: IndexMap::new(), models_with_graphql: IndexMap::new(),
@ -97,6 +99,7 @@ pub fn resolve(
&model.aggregate_expression, &model.aggregate_expression,
order_by_expressions, order_by_expressions,
graphql_config, graphql_config,
configuration,
&mut output.issues, &mut output.issues,
)?, )?,
None => types::ModelGraphQlApi::default(), None => types::ModelGraphQlApi::default(),

View File

@ -16,6 +16,7 @@ pub struct Configuration {
pub struct UnstableFeatures { pub struct UnstableFeatures {
pub enable_order_by_expressions: bool, pub enable_order_by_expressions: bool,
pub enable_ndc_v02_support: bool, pub enable_ndc_v02_support: bool,
pub enable_subscriptions: bool,
pub enable_jsonapi: bool, pub enable_jsonapi: bool,
pub enable_aggregation_predicates: bool, pub enable_aggregation_predicates: bool,
} }

View File

@ -345,6 +345,8 @@ pub enum Error {
CompatibilityError { CompatibilityError {
warnings_as_errors: SeparatedBy<crate::Warning>, warnings_as_errors: SeparatedBy<crate::Warning>,
}, },
#[error("Subscriptions are currently unstable. Please add 'subscriptions' to unstable features to enable them.")]
UnstableFeatureSubscriptions,
} }
pub trait ShouldBeAnError { pub trait ShouldBeAnError {

View File

@ -83,6 +83,7 @@ fn read_test_configuration(
let unstable_features = configuration::UnstableFeatures { let unstable_features = configuration::UnstableFeatures {
enable_order_by_expressions: false, enable_order_by_expressions: false,
enable_ndc_v02_support: false, enable_ndc_v02_support: false,
enable_subscriptions: false,
enable_jsonapi: false, enable_jsonapi: false,
enable_aggregation_predicates: true, enable_aggregation_predicates: true,
}; };

View File

@ -1948,16 +1948,6 @@
"mutation": { "mutation": {
"$ref": "#/definitions/MutationGraphqlConfig" "$ref": "#/definitions/MutationGraphqlConfig"
}, },
"subscription": {
"anyOf": [
{
"$ref": "#/definitions/SubscriptionGraphqlConfig"
},
{
"type": "null"
}
]
},
"apolloFederation": { "apolloFederation": {
"anyOf": [ "anyOf": [
{ {
@ -2332,17 +2322,6 @@
"type": "null" "type": "null"
} }
] ]
},
"subscription": {
"description": "Enable subscription on this aggregate root field.",
"anyOf": [
{
"$ref": "#/definitions/SubscriptionGraphQlDefinition"
},
{
"type": "null"
}
]
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -5266,17 +5245,6 @@
"type": "null" "type": "null"
} }
] ]
},
"subscription": {
"description": "Enable subscription on this select many root field.",
"anyOf": [
{
"$ref": "#/definitions/SubscriptionGraphQlDefinition"
},
{
"type": "null"
}
]
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -5305,11 +5273,6 @@
"items": { "items": {
"$ref": "#/definitions/ArgumentPreset" "$ref": "#/definitions/ArgumentPreset"
} }
},
"allowSubscriptions": {
"description": "Whether the role is allowed to subscribe to the root fields of this model.",
"default": false,
"type": "boolean"
} }
}, },
"additionalProperties": false "additionalProperties": false
@ -5356,82 +5319,6 @@
"type": "null" "type": "null"
} }
] ]
},
"subscription": {
"description": "Enable subscription on this select unique root field.",
"anyOf": [
{
"$ref": "#/definitions/SubscriptionGraphQlDefinition"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
"SubscriptionGraphQlDefinition": {
"$id": "https://hasura.io/jsonschemas/metadata/SubscriptionGraphQlDefinition",
"title": "SubscriptionGraphQlDefinition",
"description": "The definition of the GraphQL API for enabling subscription on query root fields.",
"type": "object",
"required": [
"rootField"
],
"properties": {
"rootField": {
"description": "The name of the subscription root field.",
"allOf": [
{
"$ref": "#/definitions/GraphQlFieldName"
}
]
},
"description": {
"description": "The description of the subscription graphql definition. Gets added to the description of the subscription root field in the graphql schema.",
"type": [
"string",
"null"
]
},
"deprecated": {
"description": "Whether this subscription root field is deprecated. If set, the deprecation status is added to the subscription root field's graphql schema.",
"anyOf": [
{
"$ref": "#/definitions/Deprecated"
},
{
"type": "null"
}
]
},
"pollingIntervalMs": {
"description": "Polling interval in milliseconds for the subscription.",
"default": 1000,
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
},
"SubscriptionGraphqlConfig": {
"$id": "https://hasura.io/jsonschemas/metadata/SubscriptionGraphqlConfig",
"title": "SubscriptionGraphqlConfig",
"description": "Configuration for the GraphQL schema of Hasura features for subscriptions.",
"type": "object",
"required": [
"rootOperationTypeName"
],
"properties": {
"rootOperationTypeName": {
"description": "The name of the root operation type name for subscriptions. Usually `subscription`.",
"allOf": [
{
"$ref": "#/definitions/GraphQlTypeName"
}
]
} }
}, },
"additionalProperties": false "additionalProperties": false

View File

@ -30,6 +30,8 @@ pub enum GraphqlConfig {
pub struct GraphqlConfigV1 { pub struct GraphqlConfigV1 {
pub query: QueryGraphqlConfig, pub query: QueryGraphqlConfig,
pub mutation: MutationGraphqlConfig, pub mutation: MutationGraphqlConfig,
#[opendd(hidden = true)]
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription: Option<SubscriptionGraphqlConfig>, pub subscription: Option<SubscriptionGraphqlConfig>,
pub apollo_federation: Option<GraphqlApolloFederationConfig>, pub apollo_federation: Option<GraphqlApolloFederationConfig>,
} }

View File

@ -385,6 +385,7 @@ pub struct SelectUniqueGraphQlDefinition {
/// If set, the deprecation status is added to the select unique root field's graphql schema. /// If set, the deprecation status is added to the select unique root field's graphql schema.
pub deprecated: Option<Deprecated>, pub deprecated: Option<Deprecated>,
/// Enable subscription on this select unique root field. /// Enable subscription on this select unique root field.
#[opendd(hidden = true)]
pub subscription: Option<SubscriptionGraphQlDefinition>, pub subscription: Option<SubscriptionGraphQlDefinition>,
} }
@ -402,10 +403,11 @@ pub struct SelectManyGraphQlDefinition {
/// If set, the deprecation status is added to the select many root field's graphql schema. /// If set, the deprecation status is added to the select many root field's graphql schema.
pub deprecated: Option<Deprecated>, pub deprecated: Option<Deprecated>,
/// Enable subscription on this select many root field. /// Enable subscription on this select many root field.
#[opendd(hidden = true)]
pub subscription: Option<SubscriptionGraphQlDefinition>, pub subscription: Option<SubscriptionGraphQlDefinition>,
} }
/// The definition of the GraphQL API for enabling subscription on query root fields. /// The definition of the GraphQL API for enabling subscription on select_many or select_uniques root fields.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, opendds_derive::OpenDd)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[opendd(json_schema(title = "SubscriptionGraphQlDefinition"))] #[opendd(json_schema(title = "SubscriptionGraphQlDefinition"))]
@ -500,5 +502,6 @@ pub struct ModelAggregateGraphQlDefinition {
/// If set, the deprecation status is added to the aggregate root field's graphql schema. /// If set, the deprecation status is added to the aggregate root field's graphql schema.
pub deprecated: Option<Deprecated>, pub deprecated: Option<Deprecated>,
/// Enable subscription on this aggregate root field. /// Enable subscription on this aggregate root field.
#[opendd(hidden = true)]
pub subscription: Option<SubscriptionGraphQlDefinition>, pub subscription: Option<SubscriptionGraphQlDefinition>,
} }

View File

@ -342,8 +342,12 @@ pub struct SelectPermission {
/// Preset values for arguments for this role /// Preset values for arguments for this role
#[opendd(default, json_schema(default_exp = "serde_json::json!([])"))] #[opendd(default, json_schema(default_exp = "serde_json::json!([])"))]
pub argument_presets: Vec<ArgumentPreset>, pub argument_presets: Vec<ArgumentPreset>,
/// Whether the role is allowed to subscribe to the root fields of this model. /// Whether to allow subscriptions for this role.
#[opendd(default, json_schema(default_exp = "serde_json::json!(false)"))] #[opendd(
hidden = true,
default,
json_schema(default_exp = "serde_json::json!(false)")
)]
pub allow_subscriptions: bool, pub allow_subscriptions: bool,
} }

View File

@ -85,6 +85,7 @@ watch: start-docker-test-deps start-docker-run-deps
--otlp-endpoint http://localhost:4317 \ --otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \ --authn-config-path static/auth/auth_config.json \
--metadata-path static/sample-schema.json \ --metadata-path static/sample-schema.json \
--unstable-feature enable-subscriptions \
--unstable-feature enable-json-api \ --unstable-feature enable-json-api \
--expose-internal-errors' --expose-internal-errors'
@ -174,5 +175,6 @@ run METADATA_PATH="static/sample-schema.json": start-docker-test-deps start-dock
--otlp-endpoint http://localhost:4317 \ --otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \ --authn-config-path static/auth/auth_config.json \
--metadata-path {{ METADATA_PATH }} \ --metadata-path {{ METADATA_PATH }} \
--unstable-feature enable-subscriptions \
--unstable-feature enable-json-api \ --unstable-feature enable-json-api \
--expose-internal-errors --expose-internal-errors