Skip to content

Commit

Permalink
Merge branch 'main' into feat/watch-path
Browse files Browse the repository at this point in the history
  • Loading branch information
beelchester authored Sep 8, 2024
2 parents 354d2b7 + 36aba8f commit efc9515
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ jobs:
pull-requests: write
env:
GITHUB_TOKEN: ${{secrets.GITHUBTOKEN}}
GA_API_SECRET: ${{secrets.GA_API_SECRET}}
GA_MEASUREMENT_ID: ${{secrets.GA_MEASUREMENT_ID}}
APP_VERSION: ${{ needs.draft_release.outputs.create_release_name }}

steps:
Expand Down
6 changes: 3 additions & 3 deletions npm/package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ schema @server @upstream {
}

type Query {
usersAge(age: Int): Empty @http(baseURL: "https://example.com", path: "/users", query: [{key: "age", value: "{{.args.age}}"}])
usersAge(age: Int): JSON @http(baseURL: "https://example.com", path: "/users", query: [{key: "age", value: "{{.args.age}}"}])
}
8 changes: 6 additions & 2 deletions src/core/helpers/gql_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ pub fn is_valid_field_name(property_name: &str) -> bool {

pub fn to_gql_type(value: &Value) -> String {
match value {
Value::Null => "Empty",
Value::Null => {
// treat null values as JSON scalars as we don't know the exact shape of the
// output.
"JSON"
}
Value::Bool(_) => "Boolean",
Value::Number(_) => "Int",
Value::String(_) => "String",
Expand Down Expand Up @@ -81,7 +85,7 @@ mod test {
assert_eq!(to_gql_type(&json!(false)), "Boolean");
assert_eq!(to_gql_type(&json!([1, 2, 3])), "List");
assert_eq!(to_gql_type(&json!({"name":"test", "age": 12})), "Object");
assert_eq!(to_gql_type(&Value::Null), "Empty");
assert_eq!(to_gql_type(&Value::Null), "JSON");

assert_eq!(to_gql_type(&json!([])), "List");
assert_eq!(to_gql_type(&json!({})), "Object");
Expand Down
1 change: 0 additions & 1 deletion src/core/ir/discriminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const TYPENAME_FIELD: &str = "__typename";
impl<'json, T> TypedValue<'json> for T
where
T: JsonLike<'json>,
T::JsonObject<'json>: JsonObjectLike<'json, Value = T>,
{
type Error = anyhow::Error;

Expand Down
9 changes: 1 addition & 8 deletions src/core/jit/common/jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,7 @@ impl<'a, Value: JsonLike<'a> + Deserialize<'a> + Clone + 'a> TestData<Value> {
}
}

impl<
'a,
Value: Deserialize<'a>
+ Clone
+ 'a
+ JsonLike<'a, JsonObject<'a>: JsonObjectLike<'a, Value = Value>>,
> JP<Value>
{
impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a>> JP<Value> {
const CONFIG: &'static str = include_str!("../fixtures/jsonplaceholder-mutation.graphql");

fn plan(query: &str, variables: &Variables<async_graphql::Value>) -> OperationPlan<Value> {
Expand Down
3 changes: 1 addition & 2 deletions src/core/jit/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub struct Executor<IRExec, Input> {

impl<Input, Output, Exec> Executor<Exec, Input>
where
Output:
for<'b> JsonLike<'b, JsonObject<'b>: JsonObjectLike<'b, Value = Output>> + Debug + Clone,
Output: for<'b> JsonLike<'b> + Debug + Clone,
Input: Clone + Debug,
Exec: IRExecutor<Input = Input, Output = Output, Error = jit::Error>,
{
Expand Down
1 change: 0 additions & 1 deletion src/core/jit/synth/synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl<Value> Synth<Value> {
impl<'a, Value> Synth<Value>
where
Value: JsonLike<'a> + Clone + std::fmt::Debug,
Value::JsonObject<'a>: JsonObjectLike<'a, Value = Value>,
{
#[inline(always)]
fn include<T>(&self, field: &Field<T, Value>) -> bool {
Expand Down
12 changes: 6 additions & 6 deletions src/core/json/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<'ctx> JsonObjectLike<'ctx> for ObjectAsVec<'ctx> {
ObjectAsVec::default()
}

fn get_key(&'ctx self, key: &str) -> Option<&Value> {
fn get_key(&self, key: &str) -> Option<&Self::Value> {
self.get(key)
}

Expand All @@ -22,13 +22,13 @@ impl<'ctx> JsonObjectLike<'ctx> for ObjectAsVec<'ctx> {
}

impl<'ctx> JsonLike<'ctx> for Value<'ctx> {
type JsonObject<'obj> = ObjectAsVec<'obj>;
type JsonObject = ObjectAsVec<'ctx>;

fn null() -> Self {
Value::Null
}

fn object(obj: Self::JsonObject<'ctx>) -> Self {
fn object(obj: Self::JsonObject) -> Self {
Value::Object(obj)
}

Expand All @@ -54,18 +54,18 @@ impl<'ctx> JsonLike<'ctx> for Value<'ctx> {
}
}

fn as_object(&self) -> Option<&Self::JsonObject<'_>> {
fn as_object(&self) -> Option<&Self::JsonObject> {
self.as_object()
}

fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject<'ctx>> {
fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> {
match self {
Value::Object(obj) => Some(obj),
_ => None,
}
}

fn into_object(self) -> Option<Self::JsonObject<'ctx>> {
fn into_object(self) -> Option<Self::JsonObject> {
match self {
Value::Object(obj) => Some(obj),
_ => None,
Expand Down
12 changes: 6 additions & 6 deletions src/core/json/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl<'obj, Value: JsonLike<'obj> + Clone> JsonObjectLike<'obj> for IndexMap<Name
IndexMap::new()
}

fn get_key(&'obj self, key: &str) -> Option<&Self::Value> {
fn get_key(&self, key: &str) -> Option<&Self::Value> {
self.get(key)
}

Expand All @@ -24,7 +24,7 @@ impl<'obj, Value: JsonLike<'obj> + Clone> JsonObjectLike<'obj> for IndexMap<Name
}

impl<'json> JsonLike<'json> for ConstValue {
type JsonObject<'obj> = IndexMap<Name, ConstValue>;
type JsonObject = IndexMap<Name, ConstValue>;

fn as_array(&self) -> Option<&Vec<Self>> {
match self {
Expand Down Expand Up @@ -110,28 +110,28 @@ impl<'json> JsonLike<'json> for ConstValue {
Default::default()
}

fn as_object(&self) -> Option<&Self::JsonObject<'_>> {
fn as_object(&self) -> Option<&Self::JsonObject> {
match self {
ConstValue::Object(map) => Some(map),
_ => None,
}
}

fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject<'_>> {
fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> {
match self {
ConstValue::Object(map) => Some(map),
_ => None,
}
}

fn into_object(self) -> Option<Self::JsonObject<'json>> {
fn into_object(self) -> Option<Self::JsonObject> {
match self {
ConstValue::Object(map) => Some(map),
_ => None,
}
}

fn object(obj: Self::JsonObject<'json>) -> Self {
fn object(obj: Self::JsonObject) -> Self {
ConstValue::Object(obj)
}

Expand Down
27 changes: 6 additions & 21 deletions src/core/json/json_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,20 @@ impl<T> JsonLikeOwned for T where T: for<'json> JsonLike<'json> {}

/// A trait for objects that can be used as JSON values
pub trait JsonLike<'json>: Sized {
type JsonObject<'obj>: JsonObjectLike<
'obj,
// generally we want to specify `Self` instead of generic here
// and `Self` is used anyway through JsonObjectLike for
// current implementations.
// But `Self` means the very specific type with some specific lifetime
// which doesn't work in case we want to return self type but with different
// lifetime. Currently, it affects only `as_object` fn because `serde_json_borrow`
// returns smaller lifetime for Value in its `as_object` fn that either forces to
// use `&'json self` in the fn (that leads to error "variable does not live long enough")
// or generic like this.
// TODO: perhaps it could be fixed on `serde_json_borrow` side if we return `Value<'ctx>`
// instead of `Value<'_>` in its functions like `as_object`. In that case we can specify
// `Self` here and simplify usages of this trait
Value: JsonLike<'obj>,
>;
type JsonObject: JsonObjectLike<'json, Value = Self>;

// Constructors
fn null() -> Self;
fn object(obj: Self::JsonObject<'json>) -> Self;
fn object(obj: Self::JsonObject) -> Self;
fn array(arr: Vec<Self>) -> Self;
fn string(s: Cow<'json, str>) -> Self;

// Operators
fn as_array(&self) -> Option<&Vec<Self>>;
fn into_array(self) -> Option<Vec<Self>>;
fn as_object(&self) -> Option<&Self::JsonObject<'_>>;
fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject<'json>>;
fn into_object(self) -> Option<Self::JsonObject<'json>>;
fn as_object(&self) -> Option<&Self::JsonObject>;
fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject>;
fn into_object(self) -> Option<Self::JsonObject>;
fn as_str(&self) -> Option<&str>;
fn as_i64(&self) -> Option<i64>;
fn as_u64(&self) -> Option<u64>;
Expand All @@ -50,7 +35,7 @@ pub trait JsonLike<'json>: Sized {
pub trait JsonObjectLike<'obj>: Sized {
type Value;
fn new() -> Self;
fn get_key(&'obj self, key: &str) -> Option<&Self::Value>;
fn get_key(&self, key: &str) -> Option<&Self::Value>;
fn insert_key(&mut self, key: &'obj str, value: Self::Value);
}

Expand Down
12 changes: 6 additions & 6 deletions src/core/json/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl<'obj> JsonObjectLike<'obj> for serde_json::Map<String, serde_json::Value> {
serde_json::Map::new()
}

fn get_key(&'obj self, key: &str) -> Option<&serde_json::Value> {
fn get_key(&self, key: &str) -> Option<&serde_json::Value> {
self.get(key)
}

Expand All @@ -20,7 +20,7 @@ impl<'obj> JsonObjectLike<'obj> for serde_json::Map<String, serde_json::Value> {
}

impl<'json> JsonLike<'json> for serde_json::Value {
type JsonObject<'obj> = serde_json::Map<String, serde_json::Value>;
type JsonObject = serde_json::Map<String, serde_json::Value>;

fn as_array(&self) -> Option<&Vec<Self>> {
self.as_array()
Expand Down Expand Up @@ -89,23 +89,23 @@ impl<'json> JsonLike<'json> for serde_json::Value {
Self::Null
}

fn as_object(&self) -> Option<&Self::JsonObject<'_>> {
fn as_object(&self) -> Option<&Self::JsonObject> {
self.as_object()
}

fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject<'_>> {
fn as_object_mut(&mut self) -> Option<&mut Self::JsonObject> {
self.as_object_mut()
}

fn into_object(self) -> Option<Self::JsonObject<'json>> {
fn into_object(self) -> Option<Self::JsonObject> {
if let Self::Object(obj) = self {
Some(obj)
} else {
None
}
}

fn object(obj: Self::JsonObject<'json>) -> Self {
fn object(obj: Self::JsonObject) -> Self {
serde_json::Value::Object(obj)
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ pub enum Scalar {
Bytes,
}

fn eval_str<'a, Value: JsonLike<'a> + 'a, F: Fn(&str) -> bool>(val: &'a Value, fxn: F) -> bool {
fn eval_str<'a, Value: JsonLike<'a>, F: Fn(&str) -> bool>(val: &'a Value, fxn: F) -> bool {
val.as_str().map_or(false, fxn)
}

fn eval_signed<
'a,
Num,
Value: JsonLike<'a> + 'a,
Value: JsonLike<'a>,
F: Fn(i64) -> Result<Num, std::num::TryFromIntError>,
>(
val: &'a Value,
Expand All @@ -94,7 +94,7 @@ fn eval_signed<
fn eval_unsigned<
'a,
Num,
Value: JsonLike<'a> + 'a,
Value: JsonLike<'a>,
F: Fn(u64) -> Result<Num, std::num::TryFromIntError>,
>(
val: &'a Value,
Expand All @@ -114,7 +114,7 @@ impl Scalar {
}
}

pub fn validate<'a, Value: JsonLike<'a> + 'a>(&self, value: &'a Value) -> bool {
pub fn validate<'a, Value: JsonLike<'a>>(&self, value: &'a Value) -> bool {
match self {
Scalar::JSON => true,
Scalar::Empty => true,
Expand Down
Loading

0 comments on commit efc9515

Please sign in to comment.