Skip to content

Commit aea14f7

Browse files
authored
feat(hql): add schema field type validation (#430)
## Description This PR adds validation for field types in schema definitions to prevent the use of unknown or custom types (identifiers) in node, vector, and edge fields. It enforces the use of built-in types only. Previously, invalid type definitions could still pass the Helix check ## Related Issues ### None ## Checklist when merging to main - [x] No compiler warnings (if applicable) - [x] Code is formatted with `rustfmt` - [x] No useless or dead code (if applicable) - [x] Code is easy to understand - [x] Doc comments are used for all functions, enums, structs, and fields (where appropriate) - [x] All tests pass - [x] Performance has not regressed (assuming change was not to fix a bug) - [ ] Version number has been updated in `helix-cli/Cargo.toml` and `helixdb/Cargo.toml` ## Additional Notes ### None
2 parents e8280dd + 546273b commit aea14f7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

helix-db/src/helixc/analyzer/methods/schema_methods.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ pub(crate) fn check_schema(ctx: &mut Ctx) {
158158
Some("rename the field".to_string()),
159159
);
160160
}
161+
if !is_valid_schema_field_type(&f.field_type) {
162+
push_schema_err(
163+
ctx,
164+
f.loc.clone(),
165+
ErrorCode::E209,
166+
format!("invalid type in schema field: `{}`", f.name),
167+
Some("use built-in types only (String, U32, etc.)".to_string()),
168+
);
169+
}
161170
})
162171
}
163172
ctx.output.edges.push(edge.clone().into());
@@ -173,6 +182,15 @@ pub(crate) fn check_schema(ctx: &mut Ctx) {
173182
Some("rename the field".to_string()),
174183
);
175184
}
185+
if !is_valid_schema_field_type(&f.field_type) {
186+
push_schema_err(
187+
ctx,
188+
f.loc.clone(),
189+
ErrorCode::E209,
190+
format!("invalid type in schema field: `{}`", f.name),
191+
Some("use built-in types only (String, U32, etc.)".to_string()),
192+
);
193+
}
176194
});
177195
ctx.output.nodes.push(node.clone().into());
178196
}
@@ -187,9 +205,27 @@ pub(crate) fn check_schema(ctx: &mut Ctx) {
187205
Some("rename the field".to_string()),
188206
);
189207
}
208+
if !is_valid_schema_field_type(&f.field_type) {
209+
push_schema_err(
210+
ctx,
211+
f.loc.clone(),
212+
ErrorCode::E209,
213+
format!("invalid type in schema field: `{}`", f.name),
214+
Some("use built-in types only (String, U32, etc.)".to_string()),
215+
);
216+
}
190217
});
191218
ctx.output.vectors.push(vector.clone().into());
192219
}
193220
}
194221

222+
fn is_valid_schema_field_type(ft: &FieldType) -> bool {
223+
match ft {
224+
FieldType::Identifier(_) => false,
225+
FieldType::Object(_) => false,
226+
FieldType::Array(inner) => is_valid_schema_field_type(inner),
227+
_ => true,
228+
}
229+
}
230+
195231
const RESERVED_FIELD_NAMES: &[&str] = &["id", "label", "to_node", "from_node", "data", "score"];

0 commit comments

Comments
 (0)