Skip to content

Commit

Permalink
fix(jit): remove data nesting (tailcallhq#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop authored Jul 5, 2024
1 parent b55acbf commit e7c4fc7
Show file tree
Hide file tree
Showing 13 changed files with 1,810 additions and 1,861 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@ source: src/core/jit/synth/synth_const.rs
expression: val
---
{
"data": {
"posts": [
{
"posts": [
{
"id": 1,
"title": "Some Title",
"user": {
"id": 1,
"title": "Some Title",
"user": {
"id": 1,
"name": "foo"
}
},
{
"id": 2,
"title": "Not Some Title",
"user": {
"id": 2,
"name": "bar"
}
"name": "foo"
}
],
"users": [
{
"id": 1,
"name": "Leanne Graham"
},
{
},
{
"id": 2,
"title": "Not Some Title",
"user": {
"id": 2,
"name": "Ervin Howell"
"name": "bar"
}
]
}
}
],
"users": [
{
"id": 1,
"name": "Leanne Graham"
},
{
"id": 2,
"name": "Ervin Howell"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ source: src/core/jit/synth/synth_const.rs
expression: val
---
{
"data": {
"posts": [
{
"posts": [
{
"id": 1,
"title": "Some Title",
"user": {
"id": 1,
"title": "Some Title",
"user": {
"id": 1,
"name": "foo"
}
},
{
"name": "foo"
}
},
{
"id": 2,
"title": "Not Some Title",
"user": {
"id": 2,
"title": "Not Some Title",
"user": {
"id": 2,
"name": "bar"
}
"name": "bar"
}
]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ source: src/core/jit/synth/synth_const.rs
expression: val
---
{
"data": {
"posts": [
{
"id": 1
},
{
"id": 2
}
]
}
"posts": [
{
"id": 1
},
{
"id": 2
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ source: src/core/jit/synth/synth_const.rs
expression: val
---
{
"data": {
"user": {
"id": 1
}
"user": {
"id": 1
}
}
35 changes: 14 additions & 21 deletions src/core/jit/synth/synth_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ impl<'a> SynthBorrow<'a> {
data.insert(child.name.as_str(), val);
}

let mut output = ObjectAsVec::default();
output.insert("data", Value::Object(data));
Value::Object(output)
Value::Object(data)
}

/// checks if type_of is an array and value is an array
Expand Down Expand Up @@ -61,17 +59,7 @@ impl<'a> SynthBorrow<'a> {
}
self.iter(node, Some(val), None)
}
Data::Multiple(list) => {
if let Some(i) = index {
match list.get(i) {
Some(val) => self.iter(node, Some(val), None),
None => Value::Null,
}
} else {
Value::Null
}
}
Data::Pending => {
_ => {
// TODO: should bailout instead of returning Null
Value::Null
}
Expand Down Expand Up @@ -198,10 +186,15 @@ mod tests {
match self {
Self::Posts => Data::Single(serde_json::from_str(POSTS).unwrap()),
Self::User1 => Data::Single(serde_json::from_str(USER1).unwrap()),
TestData::UsersData => Data::Multiple(vec![
serde_json::from_str(USER1).unwrap(),
serde_json::from_str(USER2).unwrap(),
]),
TestData::UsersData => Data::Multiple(
vec![
Data::Single(serde_json::from_str(USER1).unwrap()),
Data::Single(serde_json::from_str(USER2).unwrap()),
]
.into_iter()
.enumerate()
.collect(),
),
TestData::Users => Data::Single(serde_json::from_str(USERS).unwrap()),
}
}
Expand All @@ -219,8 +212,8 @@ mod tests {

let store = store
.into_iter()
.fold(Store::new(plan.size()), |mut store, (id, data)| {
store.set(id, data);
.fold(Store::new(), |mut store, (id, data)| {
store.set_data(id, data);
store
});

Expand Down Expand Up @@ -301,7 +294,7 @@ mod tests {
#[test]
fn test_json_placeholder() {
let synth = JsonPlaceholder::init("{ posts { id title userId user { id name } } }");
let val = synth.synthesize();
let val = synth.synthesize().unwrap();
insta::assert_snapshot!(serde_json::to_string_pretty(&val).unwrap())
}
}
4 changes: 1 addition & 3 deletions src/core/jit/synth/synth_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ impl Synth {
data.insert(Name::new(child.name.as_str()), val);
}

let mut output = IndexMap::default();
output.insert(Name::new("data"), Value::Object(data));
Ok(Value::Object(output))
Ok(Value::Object(data))
}

/// checks if type_of is an array and value is an array
Expand Down
22 changes: 0 additions & 22 deletions tests/core/snapshots/recursive-types-no-resolver.md_merged.snap

This file was deleted.

94 changes: 46 additions & 48 deletions tests/snapshots/jit_spec__tests__executor.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,50 @@ source: tests/jit_spec.rs
expression: data
---
{
"data": {
"posts": [
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
},
{
"id": 2,
"title": "qui est esse"
},
{
"id": 3,
"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut"
},
{
"id": 4,
"title": "eum et est occaecati"
},
{
"id": 5,
"title": "nesciunt quas odio"
},
{
"id": 6,
"title": "dolorem eum magni eos aperiam quia"
},
{
"id": 7,
"title": "magnam facilis autem"
},
{
"id": 8,
"title": "dolorem dolore est ipsam"
},
{
"id": 9,
"title": "nesciunt iure omnis dolorem tempora et accusantium"
},
{
"id": 10,
"title": "optio molestias id quia eum"
},
{
"id": 11,
"title": "et ea vero quia laudantium autem"
}
]
}
"posts": [
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
},
{
"id": 2,
"title": "qui est esse"
},
{
"id": 3,
"title": "ea molestias quasi exercitationem repellat qui ipsa sit aut"
},
{
"id": 4,
"title": "eum et est occaecati"
},
{
"id": 5,
"title": "nesciunt quas odio"
},
{
"id": 6,
"title": "dolorem eum magni eos aperiam quia"
},
{
"id": 7,
"title": "magnam facilis autem"
},
{
"id": 8,
"title": "dolorem dolore est ipsam"
},
{
"id": 9,
"title": "nesciunt iure omnis dolorem tempora et accusantium"
},
{
"id": 10,
"title": "optio molestias id quia eum"
},
{
"id": 11,
"title": "et ea vero quia laudantium autem"
}
]
}
Loading

0 comments on commit e7c4fc7

Please sign in to comment.