mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
Use DataConnectorScalarType
everywhere (#628)
<!-- Thank you for submitting this PR! :) --> ## Description In https://github.com/hasura/v3-engine/pull/599 we added new `BooleanExpressionType` to OpenDD. It included a number of helpful newtypes such as `DataConnectorScalarType` that replace uses of raw string and make intent inside engine code easier to follow. This change uses that newtype everywhere in `metadata-resolve`. <!-- Questions to consider answering: 1. What user-facing changes are being made? 2. What are issues related to this PR? (Consider adding `(close #<issue-no>)` to the PR title) 3. What is the conceptual design behind this PR? 4. How can this PR be tested/verified? 5. Does the PR have limitations? 6. Does the PR introduce breaking changes? --> ## Changelog - Add a changelog entry (in the "Changelog entry" section below) if the changes in this PR have any user-facing impact. See [changelog guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide). - If no changelog is required ignore/remove this section and add a `no-changelog-required` label to the PR. ### Product _(Select all products this will be available in)_ - [X] community-edition - [X] cloud <!-- product : end : DO NOT REMOVE --> ### Type <!-- See changelog structure: https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog --> _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [X] enhancement - [ ] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix <!-- type : end : DO NOT REMOVE --> ### Changelog entry <!-- - Add a user understandable changelog entry - Include all details needed to understand the change. Try including links to docs or issues if relevant - For Highlights start with a H4 heading (#### <entry title>) - Get the changelog entry reviewed by your team --> Use `DataConnectorScalarType` string newtype internallly and in OpenDD types. <!-- changelog-entry : end : DO NOT REMOVE --> <!-- changelog : end : DO NOT REMOVE --> V3_GIT_ORIGIN_REV_ID: b44709f39b30f25908106110f62c72e3d13b4eb6
This commit is contained in:
parent
44ad07eeab
commit
7bc6755686
@ -1,6 +1,6 @@
|
||||
use crate::stages::data_connector_scalar_types;
|
||||
|
||||
use crate::types::error::Error;
|
||||
use ref_cast::RefCast;
|
||||
|
||||
use crate::types::subgraph::{
|
||||
mk_qualified_type_name, Qualified, QualifiedBaseType, QualifiedTypeReference,
|
||||
@ -8,7 +8,7 @@ use crate::types::subgraph::{
|
||||
|
||||
use ndc_models;
|
||||
|
||||
use open_dds::data_connector::DataConnectorName;
|
||||
use open_dds::data_connector::{DataConnectorName, DataConnectorScalarType};
|
||||
|
||||
// helper function to resolve ndc types to dds type based on scalar type representations
|
||||
pub(crate) fn resolve_ndc_type(
|
||||
@ -19,13 +19,14 @@ pub(crate) fn resolve_ndc_type(
|
||||
) -> Result<QualifiedTypeReference, Error> {
|
||||
match source_type {
|
||||
ndc_models::Type::Named { name } => {
|
||||
let scalar_type_name = DataConnectorScalarType::ref_cast(name);
|
||||
let scalar_type =
|
||||
scalars
|
||||
.0
|
||||
.get(name.as_str())
|
||||
.get(scalar_type_name)
|
||||
.ok_or(Error::UnknownScalarTypeInDataConnector {
|
||||
data_connector: data_connector.clone(),
|
||||
scalar_type: name.clone(),
|
||||
scalar_type: scalar_type_name.clone(),
|
||||
})?;
|
||||
scalar_type
|
||||
.representation
|
||||
|
@ -1,13 +1,13 @@
|
||||
pub mod types;
|
||||
use ref_cast::RefCast;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
pub use types::{ScalarTypeWithRepresentationInfo, ScalarTypeWithRepresentationInfoMap};
|
||||
|
||||
use lang_graphql::ast::common as ast;
|
||||
|
||||
use open_dds::types::{CustomTypeName, TypeName};
|
||||
|
||||
use open_dds::data_connector::DataConnectorName;
|
||||
use open_dds::data_connector::{DataConnectorName, DataConnectorScalarType};
|
||||
|
||||
use crate::helpers::types::mk_name;
|
||||
use crate::types::error::Error;
|
||||
@ -40,7 +40,7 @@ pub fn resolve<'a>(
|
||||
object: scalar_type_representation,
|
||||
} in &metadata_accessor.data_connector_scalar_representations
|
||||
{
|
||||
let scalar_type_name: &String = &scalar_type_representation.data_connector_scalar_type;
|
||||
let scalar_type_name = &scalar_type_representation.data_connector_scalar_type;
|
||||
|
||||
let qualified_data_connector_name = Qualified::new(
|
||||
subgraph.to_string(),
|
||||
@ -56,11 +56,7 @@ pub fn resolve<'a>(
|
||||
|
||||
let scalar_type = scalars
|
||||
.0
|
||||
.get_mut(
|
||||
scalar_type_representation
|
||||
.data_connector_scalar_type
|
||||
.as_str(),
|
||||
)
|
||||
.get_mut(&scalar_type_representation.data_connector_scalar_type)
|
||||
.ok_or_else(|| Error::UnknownScalarTypeInDataConnector {
|
||||
scalar_type: scalar_type_name.clone(),
|
||||
data_connector: qualified_data_connector_name.clone(),
|
||||
@ -125,7 +121,7 @@ fn convert_data_connectors_contexts<'a>(
|
||||
let mut new_scalars = BTreeMap::new();
|
||||
for (scalar_name, scalar) in scalars {
|
||||
new_scalars.insert(
|
||||
*scalar_name,
|
||||
scalar_name.clone(),
|
||||
ScalarTypeWithRepresentationInfo {
|
||||
scalar_type: scalar.scalar_type,
|
||||
comparison_expression_name: None,
|
||||
@ -149,7 +145,10 @@ pub fn get_simple_scalar<'a>(
|
||||
scalars: &'a ScalarTypeWithRepresentationInfoMap<'a>,
|
||||
) -> Option<(String, &'a ScalarTypeWithRepresentationInfo<'a>)> {
|
||||
match t {
|
||||
ndc_models::Type::Named { name } => scalars.0.get(name.as_str()).map(|info| (name, info)),
|
||||
ndc_models::Type::Named { name } => scalars
|
||||
.0
|
||||
.get(DataConnectorScalarType::ref_cast(&name))
|
||||
.map(|info| (name, info)),
|
||||
ndc_models::Type::Nullable { underlying_type } => {
|
||||
get_simple_scalar(*underlying_type, scalars)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use crate::stages::data_connectors;
|
||||
use lang_graphql::ast::common as ast;
|
||||
|
||||
use ndc_models;
|
||||
use open_dds::data_connector::DataConnectorScalarType;
|
||||
use open_dds::types::TypeName;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@ -14,5 +15,5 @@ pub struct ScalarTypeWithRepresentationInfo<'a> {
|
||||
}
|
||||
|
||||
pub struct ScalarTypeWithRepresentationInfoMap<'a>(
|
||||
pub BTreeMap<&'a str, ScalarTypeWithRepresentationInfo<'a>>,
|
||||
pub BTreeMap<DataConnectorScalarType, ScalarTypeWithRepresentationInfo<'a>>,
|
||||
);
|
||||
|
@ -7,7 +7,8 @@ use indexmap::IndexMap;
|
||||
use open_dds::{
|
||||
commands::{FunctionName, ProcedureName},
|
||||
data_connector::{
|
||||
self, DataConnectorName, DataConnectorUrl, ReadWriteUrls, VersionedSchemaAndCapabilities,
|
||||
self, DataConnectorName, DataConnectorScalarType, DataConnectorUrl, ReadWriteUrls,
|
||||
VersionedSchemaAndCapabilities,
|
||||
},
|
||||
EnvironmentValue,
|
||||
};
|
||||
@ -51,7 +52,7 @@ pub struct DataConnectorSchema {
|
||||
/// currently this contains partial ScalarTypeInfo, which we add to later
|
||||
pub struct DataConnectorContext<'a> {
|
||||
pub inner: DataConnectorCoreInfo<'a>,
|
||||
pub scalars: BTreeMap<&'a str, ScalarTypeInfo<'a>>,
|
||||
pub scalars: BTreeMap<DataConnectorScalarType, ScalarTypeInfo<'a>>,
|
||||
}
|
||||
|
||||
fn create_data_connector_schema(schema: &ndc_models::SchemaResponse) -> DataConnectorSchema {
|
||||
@ -102,7 +103,7 @@ impl<'a> DataConnectorContext<'a> {
|
||||
.schema
|
||||
.scalar_types
|
||||
.iter()
|
||||
.map(|(k, v)| (k.as_str(), ScalarTypeInfo::new(v)))
|
||||
.map(|(k, v)| (DataConnectorScalarType(k.clone()), ScalarTypeInfo::new(v)))
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use lang_graphql::ast::common as ast;
|
||||
use open_dds::{
|
||||
arguments::ArgumentName,
|
||||
commands::{CommandName, FunctionName, ProcedureName},
|
||||
data_connector::DataConnectorName,
|
||||
data_connector::{DataConnectorName, DataConnectorScalarType},
|
||||
models::ModelName,
|
||||
relationships::RelationshipName,
|
||||
types::{CustomTypeName, FieldName, OperatorName, TypeReference},
|
||||
@ -429,22 +429,22 @@ pub enum Error {
|
||||
#[error("unknown data connector {data_connector:} referenced in scalar type representation of {scalar_type:}")]
|
||||
ScalarTypeFromUnknownDataConnector {
|
||||
data_connector: Qualified<DataConnectorName>,
|
||||
scalar_type: String,
|
||||
scalar_type: DataConnectorScalarType,
|
||||
},
|
||||
#[error("cannot find scalar type {scalar_type:} in data connector {data_connector:}")]
|
||||
UnknownScalarTypeInDataConnector {
|
||||
data_connector: Qualified<DataConnectorName>,
|
||||
scalar_type: String,
|
||||
scalar_type: DataConnectorScalarType,
|
||||
},
|
||||
#[error("unknown type represented for scalar type {scalar_type:}: {type_name:}")]
|
||||
ScalarTypeUnknownRepresentation {
|
||||
scalar_type: String,
|
||||
scalar_type: DataConnectorScalarType,
|
||||
type_name: Qualified<CustomTypeName>,
|
||||
},
|
||||
#[error("multiple type representations defined for scalar {scalar_type:} from data connector {data_connector:}")]
|
||||
DuplicateDataConnectorScalarRepresentation {
|
||||
data_connector: Qualified<DataConnectorName>,
|
||||
scalar_type: String,
|
||||
scalar_type: DataConnectorScalarType,
|
||||
},
|
||||
#[error(
|
||||
"scalar type representation required for type {scalar_type:} in data connector {data_connector:}"
|
||||
|
@ -1412,7 +1412,11 @@
|
||||
},
|
||||
"dataConnectorScalarType": {
|
||||
"description": "The name of the scalar type coming from the data connector.",
|
||||
"type": "string"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/DataConnectorScalarType"
|
||||
}
|
||||
]
|
||||
},
|
||||
"representation": {
|
||||
"description": "The name of the Open DD type that this data connector scalar type should be represented as.",
|
||||
@ -1436,6 +1440,12 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"DataConnectorScalarType": {
|
||||
"$id": "https://hasura.io/jsonschemas/metadata/DataConnectorScalarType",
|
||||
"title": "DataConnectorScalarType",
|
||||
"description": "The name of a scalar type in a data connector.",
|
||||
"type": "string"
|
||||
},
|
||||
"TypeName": {
|
||||
"$id": "https://hasura.io/jsonschemas/metadata/TypeName",
|
||||
"title": "TypeName",
|
||||
|
@ -9,8 +9,9 @@ use serde::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
data_connector::DataConnectorName, data_connector::DataConnectorObjectType,
|
||||
identifier::Identifier, impl_JsonSchema_with_OpenDd_for, impl_OpenDd_default_for,
|
||||
data_connector::{DataConnectorName, DataConnectorObjectType, DataConnectorScalarType},
|
||||
identifier::Identifier,
|
||||
impl_JsonSchema_with_OpenDd_for, impl_OpenDd_default_for,
|
||||
models::EnableAllOrSpecific,
|
||||
};
|
||||
|
||||
@ -547,7 +548,7 @@ pub struct DataConnectorScalarRepresentationV1 {
|
||||
/// The name of the data connector that this scalar type comes from.
|
||||
pub data_connector_name: DataConnectorName,
|
||||
/// The name of the scalar type coming from the data connector.
|
||||
pub data_connector_scalar_type: String,
|
||||
pub data_connector_scalar_type: DataConnectorScalarType,
|
||||
/// The name of the Open DD type that this data connector scalar type should be represented as.
|
||||
pub representation: TypeName,
|
||||
/// Configuration for how this scalar's operators should appear in the GraphQL schema.
|
||||
|
Loading…
Reference in New Issue
Block a user