Skip to content

Commit

Permalink
Merge branch 'main' into chore/toolchain-update
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill authored Oct 26, 2024
2 parents 033ea92 + 57c64a0 commit a597e19
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/core/jit/graphql_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct GraphQLError {
pub locations: Vec<Pos>,
/// If the error occurred in a resolver, the path to the error.
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub path: Vec<PathSegment>,
pub path: Vec<PathSegment<'static>>,
/// Extensions to the error.
#[serde(skip_serializing_if = "error_extensions_is_empty", default)]
pub extensions: Option<ErrorExtensionValues>,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl GraphQLError {

#[doc(hidden)]
#[must_use]
pub fn with_path(self, path: Vec<PathSegment>) -> Self {
pub fn with_path(self, path: Vec<PathSegment<'static>>) -> Self {
Self { path, ..self }
}
}
Expand Down
22 changes: 7 additions & 15 deletions src/core/jit/model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
Expand Down Expand Up @@ -505,36 +506,27 @@ impl From<Pos> for async_graphql::Pos {

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PathSegment {
pub enum PathSegment<'a> {
/// A field in an object.
Field(String),
Field(Cow<'a, String>),
/// An index in a list.
Index(usize),
}

impl From<async_graphql::PathSegment> for PathSegment {
impl From<async_graphql::PathSegment> for PathSegment<'static> {
fn from(value: async_graphql::PathSegment) -> Self {
match value {
async_graphql::PathSegment::Field(field) => PathSegment::Field(field),
async_graphql::PathSegment::Field(field) => PathSegment::Field(Cow::Owned(field)),
async_graphql::PathSegment::Index(index) => PathSegment::Index(index),
}
}
}

impl From<PathSegment> for async_graphql::PathSegment {
fn from(val: PathSegment) -> Self {
match val {
PathSegment::Field(field) => async_graphql::PathSegment::Field(field),
PathSegment::Index(index) => async_graphql::PathSegment::Index(index),
}
}
}

#[derive(Debug, Serialize, Clone)]
pub struct Positioned<Value> {
pub value: Value,
pub pos: Pos,
pub path: Vec<PathSegment>,
pub path: Vec<PathSegment<'static>>,
}

impl<Value> Positioned<Value> {
Expand All @@ -547,7 +539,7 @@ impl<Value> Positioned<Value>
where
Value: Clone,
{
pub fn with_path(&mut self, path: Vec<PathSegment>) -> Self {
pub fn with_path(&mut self, path: Vec<PathSegment<'static>>) -> Self {
Self { value: self.value.clone(), pos: self.pos, path }
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/core/jit/synth/synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ where
node: &'a Field<Value>,
value: Option<&'a Value>,
data_path: &DataPath,
path: &mut Vec<PathSegment>,
path: &mut Vec<PathSegment<'a>>,
root_name: Option<&'a str>,
) -> Result<Value, Positioned<Error>> {
path.push(PathSegment::Field(node.output_name.clone()));
path.push(PathSegment::Field(Cow::Borrowed(&node.output_name)));

let result = match self.store.get(&node.id) {
Some(value) => {
Expand Down Expand Up @@ -120,7 +120,7 @@ where
node: &'a Field<Value>,
value: &'a Value,
data_path: &DataPath,
path: &mut Vec<PathSegment>,
path: &mut Vec<PathSegment<'a>>,
) -> Result<Value, Positioned<Error>> {
// skip the field if field is not included in schema
if !self.include(node) {
Expand Down Expand Up @@ -222,7 +222,16 @@ where
node: &'a Field<Value>,
path: &[PathSegment],
) -> Positioned<Error> {
Positioned::new(error, node.pos).with_path(path.to_vec())
Positioned::new(error, node.pos).with_path(
path.iter()
.map(|x| match x {
PathSegment::Field(cow) => {
PathSegment::Field(Cow::Owned(cow.clone().into_owned()))
}
PathSegment::Index(i) => PathSegment::Index(*i),
})
.collect(),
)
}
}

Expand Down

1 comment on commit a597e19

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 8.25ms 3.32ms 115.12ms 89.41%
Req/Sec 3.07k 381.75 4.15k 81.58%

367191 requests in 30.02s, 1.84GB read

Requests/sec: 12232.76

Transfer/sec: 62.79MB

Please sign in to comment.