mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
add a test for opendd object mapped to ndc scalar (#324)
V3_GIT_ORIGIN_REV_ID: 7972eda702c43c2a121c1333ae32c4252b1b44d2
This commit is contained in:
parent
8071b11194
commit
4f1276dac1
@ -545,7 +545,7 @@ pub enum TypeMappingValidationError {
|
||||
#[error(
|
||||
"the type {unknown_ndc_field_type_name:} is not defined as an object type in the connector's schema. This type is referenced by the field {ndc_field_name:} in the connector's schema type {ndc_type_name:}, which is mapped to the field {field_name:} in the type {type_name:}"
|
||||
)]
|
||||
UnknownNdcFieldType {
|
||||
UnknownNdcFieldObjectType {
|
||||
type_name: Qualified<CustomTypeName>,
|
||||
field_name: FieldName,
|
||||
ndc_type_name: String,
|
||||
|
@ -371,7 +371,7 @@ fn resolve_type_mapping(
|
||||
.map_err(TypeMappingValidationError::NDCValidationError)?;
|
||||
let ndc_field_object_type = ndc_object_types
|
||||
.get(underlying_ndc_field_named_type)
|
||||
.ok_or_else(|| TypeMappingValidationError::UnknownNdcFieldType {
|
||||
.ok_or_else(|| TypeMappingValidationError::UnknownNdcFieldObjectType {
|
||||
type_name: mapping_to_resolve.type_name.clone(),
|
||||
field_name: field_name.clone(),
|
||||
ndc_type_name: mapping_to_resolve.ndc_object_type_name.into(),
|
||||
|
@ -1,3 +1,5 @@
|
||||
use engine::metadata::resolved::error::Error::ModelTypeMappingValidationError;
|
||||
use engine::schema::Error::ResolveError;
|
||||
use engine::schema::GDS;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
@ -226,3 +228,20 @@ fn test_global_if_fields_present_in_object_type_but_no_model_has_global_id_sourc
|
||||
"metadata is not consistent: 'globalIdFields' for type actor (in subgraph default) found, but no model found with 'globalIdSource: true' for type actor (in subgraph default)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
// Remove this test (and add an execution test instead) if we ever support this use case
|
||||
fn test_disallow_object_mapped_to_scalar() {
|
||||
let metadata_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
|
||||
"tests/validate_metadata_artifacts/metadata_with_opendd_object_mapped_to_ndc_scalar.json",
|
||||
);
|
||||
let metadata =
|
||||
GDS::new(serde_json::from_str(&fs::read_to_string(metadata_path).unwrap()).unwrap());
|
||||
println!("{metadata:?}");
|
||||
assert!(matches!(
|
||||
metadata,
|
||||
Err(ResolveError {
|
||||
error: ModelTypeMappingValidationError { .. }
|
||||
})
|
||||
));
|
||||
}
|
||||
|
@ -0,0 +1,172 @@
|
||||
{
|
||||
"version": "v2",
|
||||
"subgraphs": [
|
||||
{
|
||||
"name": "default",
|
||||
"objects": [
|
||||
{
|
||||
"kind": "DataConnectorLink",
|
||||
"version": "v1",
|
||||
"definition": {
|
||||
"name": "db",
|
||||
"url": {
|
||||
"singleUrl": {
|
||||
"value": "http://foo"
|
||||
}
|
||||
},
|
||||
"headers": {},
|
||||
"schema": {
|
||||
"version": "v0.1",
|
||||
"schema": {
|
||||
"scalar_types": {
|
||||
"String": {
|
||||
"aggregate_functions": {},
|
||||
"comparison_operators": {
|
||||
"_eq": {
|
||||
"type": "equal"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"object_types": {
|
||||
"actor": {
|
||||
"description": "An actor",
|
||||
"fields": {
|
||||
"id": {
|
||||
"description": "The actor's primary key",
|
||||
"type": {
|
||||
"type": "named",
|
||||
"name": "String"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"collections": [
|
||||
{
|
||||
"name": "actors",
|
||||
"description": "Collection of actors",
|
||||
"arguments": {},
|
||||
"type": "actor",
|
||||
"deletable": false,
|
||||
"uniqueness_constraints": {},
|
||||
"foreign_keys": {}
|
||||
}
|
||||
],
|
||||
"functions": [],
|
||||
"procedures": []
|
||||
},
|
||||
"capabilities": {
|
||||
"capabilities": {
|
||||
"query": {
|
||||
"aggregates": {},
|
||||
"variables": {},
|
||||
"explain": {}
|
||||
},
|
||||
"relationships": {
|
||||
"relation_comparisons": {},
|
||||
"order_by_aggregate": {}
|
||||
},
|
||||
"mutation": {}
|
||||
},
|
||||
"version": "0.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "DataConnectorScalarRepresentation",
|
||||
"version": "v1",
|
||||
"definition": {
|
||||
"dataConnectorName": "db",
|
||||
"dataConnectorScalarType": "String",
|
||||
"representation": "String",
|
||||
"graphql": {
|
||||
"comparisonExpressionTypeName": "String_Comparison_Exp"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "ObjectType",
|
||||
"version": "v1",
|
||||
"definition": {
|
||||
"name": "IdObject",
|
||||
"fields": [
|
||||
{
|
||||
"name": "id_value",
|
||||
"type": "String!"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "ObjectType",
|
||||
"version": "v1",
|
||||
"definition": {
|
||||
"name": "Actor",
|
||||
"fields": [
|
||||
{
|
||||
"name": "id",
|
||||
"type": "IdObject!"
|
||||
}
|
||||
],
|
||||
"graphql": {
|
||||
"typeName": "Actor"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": "Model",
|
||||
"version": "v1",
|
||||
"definition": {
|
||||
"name": "Actors",
|
||||
"objectType": "Actor",
|
||||
"globalIdSource": false,
|
||||
"source": {
|
||||
"dataConnectorName": "db",
|
||||
"collection": "actors",
|
||||
"typeMapping": {
|
||||
"actor": {
|
||||
"fieldMapping": {
|
||||
"id": {
|
||||
"column": "id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"graphql": {
|
||||
"selectUniques": [
|
||||
{
|
||||
"queryRootField": "actorById",
|
||||
"uniqueIdentifier": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
],
|
||||
"selectMany": {
|
||||
"queryRootField": "actors"
|
||||
}
|
||||
},
|
||||
"filterableFields": [
|
||||
{
|
||||
"fieldName": "id",
|
||||
"operators": {
|
||||
"enableAll": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"orderableFields": [
|
||||
{
|
||||
"fieldName": "id",
|
||||
"orderByDirections": {
|
||||
"enableAll": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user