feat: add graphql support
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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)> {
|
||||
|
||||
Reference in New Issue
Block a user