Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: jq support #1801

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 91 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ convert_case = "0.6.0"
rand = "0.8.5"
tailcall-macros = { path = "tailcall-macros" }
tonic-types = "0.11.0"

jaq-core = "1.2.1"
jaq-parse = "1.0.2"
jaq-interpret = {version = "1.2.1",features = ["serde_json"]}
jaq-syn = "1.1.0"
jaq-std = "1.2.1"

[dev-dependencies]
tailcall-prettier = {path = "tailcall-prettier"}
Expand All @@ -161,6 +165,7 @@ temp-env = "0.3.6"
maplit = "1.0.2"
tailcall-fixtures = { path = "./tailcall-fixtures" }


[features]

# Feature Flag to enable V8.
Expand Down
4 changes: 4 additions & 0 deletions benches/request_template_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl PathString for Context {
fn path_string<T: AsRef<str>>(&self, parts: &[T]) -> Option<Cow<'_, str>> {
self.value.path_string(parts)
}

fn evaluate(&self, _filter: &jaq_interpret::Filter) -> Option<Cow<'_, str>> {
None
}
}
impl HasHeaders for Context {
fn headers(&self) -> &HeaderMap {
Expand Down
2 changes: 1 addition & 1 deletion examples/jsonplaceholder.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ type Post {
userId: Int!
title: String!
body: String!
user: User @call(steps: [{query: "user", args: {id: "{{.value.userId}}"}}])
user: User @call(steps: [{query: "user", args: {id: "{{.userId}}"}}])
ssddOnTop marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 6 additions & 0 deletions src/config/reader_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::borrow::Cow;
use std::collections::BTreeMap;
use std::sync::Arc;

use jaq_interpret::Filter;

use crate::path::PathString;
use crate::EnvIO;

Expand All @@ -23,6 +25,10 @@ impl<'a> PathString for ConfigReaderContext<'a> {
_ => None,
})
}

fn evaluate(&self, _filter: &Filter) -> Option<Cow<'_, str>> {
None
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions src/grpc/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
fn path_string<T: AsRef<str>>(&self, parts: &[T]) -> Option<Cow<'_, str>> {
self.value.path_string(parts)
}

fn evaluate(&self, _filter: &jaq_interpret::Filter) -> Option<Cow<'_, str>> {
todo!()
}

Check warning on line 195 in src/grpc/request_template.rs

View check run for this annotation

Codecov / codecov/patch

src/grpc/request_template.rs#L193-L195

Added lines #L193 - L195 were not covered by tests
}

impl crate::has_headers::HasHeaders for Context {
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ pub fn to_body(body: Option<&str>) -> Valid<Option<Mustache>, String> {
mod tests {
use super::to_body;
use crate::mustache::Mustache;
use crate::valid::Valid;
use crate::valid::{Valid, Validator};

#[test]
fn no_body() {
let result = to_body(None);
let result = to_body(None).map(|v| v.map(|v| v.to_string()));

assert_eq!(result, Valid::succeed(None));
}
Expand All @@ -31,8 +31,8 @@ mod tests {
let result = to_body(Some("content"));

assert_eq!(
result,
Valid::succeed(Some(Mustache::parse("content").unwrap()))
result.map(|v| v.map(|v| v.to_string())),
Valid::succeed(Some(Mustache::parse("content").unwrap().to_string()))
);
}
}
14 changes: 12 additions & 2 deletions src/helpers/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ mod tests {
)?;

let headers = to_mustache_headers(&input).to_result()?;
let headers = headers
.into_iter()
.map(|(k, v)| (k, v.to_string()))
.collect::<Vec<_>>();

assert_eq!(
headers,
vec![
(HeaderName::from_bytes(b"a")?, Mustache::parse("str")?),
(HeaderName::from_bytes(b"b")?, Mustache::parse("123")?)
(
HeaderName::from_bytes(b"a")?,
Mustache::parse("str")?.to_string()
),
(
HeaderName::from_bytes(b"b")?,
Mustache::parse("123")?.to_string()
)
]
);

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn to_url(url: &str) -> Valid<Mustache, String> {
#[cfg(test)]
mod tests {
use super::to_url;
use crate::valid::Validator;

#[test]
fn parse_url() {
Expand All @@ -17,8 +18,9 @@ mod tests {
let url = to_url("http://localhost:3000");

assert_eq!(
url,
url.map(|v| v.to_string()),
Valid::succeed(Mustache::parse("http://localhost:3000").unwrap())
.map(|v| v.to_string())
);
}
}
4 changes: 4 additions & 0 deletions src/http/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ mod tests {
fn path_string<T: AsRef<str>>(&self, parts: &[T]) -> Option<Cow<'_, str>> {
self.value.path_string(parts)
}

fn evaluate(&self, _filter: &jaq_interpret::Filter) -> Option<Cow<'_, str>> {
None
}
ssddOnTop marked this conversation as resolved.
Show resolved Hide resolved
}

impl crate::has_headers::HasHeaders for Context {
Expand Down
Loading
Loading