feat: add graphql support

This commit is contained in:
a.tolmachev
2026-03-25 20:21:07 +03:00
parent 6296b04105
commit 1ea75eb824
16 changed files with 824 additions and 30 deletions
+1 -14
View File
@@ -69,20 +69,7 @@ fn empty_target_context(context: MappingTargetContext) -> Value {
}
fn read_path<'a>(value: &'a Value, path: &JsonPath) -> Option<&'a Value> {
let mut current = value;
for field in path.root.root_fields() {
current = current.get(*field)?;
}
for segment in &path.segments {
current = match segment {
JsonPathSegment::Field(field) => current.get(field)?,
JsonPathSegment::Index(index) => current.get(*index)?,
};
}
Some(current)
path.read(value)
}
fn write_path(target: &mut Value, path: &JsonPath, value: Value) -> Result<(), MappingError> {
+19
View File
@@ -1,3 +1,5 @@
use serde_json::Value;
use crate::MappingError;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -103,6 +105,23 @@ impl JsonPath {
path
}
pub fn read<'a>(&self, value: &'a Value) -> Option<&'a Value> {
let mut current = value;
for field in self.root.root_fields() {
current = current.get(*field)?;
}
for segment in &self.segments {
current = match segment {
JsonPathSegment::Field(field) => current.get(field)?,
JsonPathSegment::Index(index) => current.get(*index)?,
};
}
Some(current)
}
}
fn match_root(input: &str) -> Option<(JsonPathRoot, &str)> {