Skip to content

Commit a597e19

Browse files
authored
Merge branch 'main' into chore/toolchain-update
2 parents 033ea92 + 57c64a0 commit a597e19

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/core/jit/graphql_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct GraphQLError {
1515
pub locations: Vec<Pos>,
1616
/// If the error occurred in a resolver, the path to the error.
1717
#[serde(skip_serializing_if = "Vec::is_empty", default)]
18-
pub path: Vec<PathSegment>,
18+
pub path: Vec<PathSegment<'static>>,
1919
/// Extensions to the error.
2020
#[serde(skip_serializing_if = "error_extensions_is_empty", default)]
2121
pub extensions: Option<ErrorExtensionValues>,
@@ -75,7 +75,7 @@ impl GraphQLError {
7575

7676
#[doc(hidden)]
7777
#[must_use]
78-
pub fn with_path(self, path: Vec<PathSegment>) -> Self {
78+
pub fn with_path(self, path: Vec<PathSegment<'static>>) -> Self {
7979
Self { path, ..self }
8080
}
8181
}

src/core/jit/model.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::collections::HashMap;
23
use std::fmt::{Debug, Formatter};
34
use std::sync::Arc;
@@ -505,36 +506,27 @@ impl From<Pos> for async_graphql::Pos {
505506

506507
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
507508
#[serde(untagged)]
508-
pub enum PathSegment {
509+
pub enum PathSegment<'a> {
509510
/// A field in an object.
510-
Field(String),
511+
Field(Cow<'a, String>),
511512
/// An index in a list.
512513
Index(usize),
513514
}
514515

515-
impl From<async_graphql::PathSegment> for PathSegment {
516+
impl From<async_graphql::PathSegment> for PathSegment<'static> {
516517
fn from(value: async_graphql::PathSegment) -> Self {
517518
match value {
518-
async_graphql::PathSegment::Field(field) => PathSegment::Field(field),
519+
async_graphql::PathSegment::Field(field) => PathSegment::Field(Cow::Owned(field)),
519520
async_graphql::PathSegment::Index(index) => PathSegment::Index(index),
520521
}
521522
}
522523
}
523524

524-
impl From<PathSegment> for async_graphql::PathSegment {
525-
fn from(val: PathSegment) -> Self {
526-
match val {
527-
PathSegment::Field(field) => async_graphql::PathSegment::Field(field),
528-
PathSegment::Index(index) => async_graphql::PathSegment::Index(index),
529-
}
530-
}
531-
}
532-
533525
#[derive(Debug, Serialize, Clone)]
534526
pub struct Positioned<Value> {
535527
pub value: Value,
536528
pub pos: Pos,
537-
pub path: Vec<PathSegment>,
529+
pub path: Vec<PathSegment<'static>>,
538530
}
539531

540532
impl<Value> Positioned<Value> {
@@ -547,7 +539,7 @@ impl<Value> Positioned<Value>
547539
where
548540
Value: Clone,
549541
{
550-
pub fn with_path(&mut self, path: Vec<PathSegment>) -> Self {
542+
pub fn with_path(&mut self, path: Vec<PathSegment<'static>>) -> Self {
551543
Self { value: self.value.clone(), pos: self.pos, path }
552544
}
553545
}

src/core/jit/synth/synth.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ where
5959
node: &'a Field<Value>,
6060
value: Option<&'a Value>,
6161
data_path: &DataPath,
62-
path: &mut Vec<PathSegment>,
62+
path: &mut Vec<PathSegment<'a>>,
6363
root_name: Option<&'a str>,
6464
) -> Result<Value, Positioned<Error>> {
65-
path.push(PathSegment::Field(node.output_name.clone()));
65+
path.push(PathSegment::Field(Cow::Borrowed(&node.output_name)));
6666

6767
let result = match self.store.get(&node.id) {
6868
Some(value) => {
@@ -120,7 +120,7 @@ where
120120
node: &'a Field<Value>,
121121
value: &'a Value,
122122
data_path: &DataPath,
123-
path: &mut Vec<PathSegment>,
123+
path: &mut Vec<PathSegment<'a>>,
124124
) -> Result<Value, Positioned<Error>> {
125125
// skip the field if field is not included in schema
126126
if !self.include(node) {
@@ -222,7 +222,16 @@ where
222222
node: &'a Field<Value>,
223223
path: &[PathSegment],
224224
) -> Positioned<Error> {
225-
Positioned::new(error, node.pos).with_path(path.to_vec())
225+
Positioned::new(error, node.pos).with_path(
226+
path.iter()
227+
.map(|x| match x {
228+
PathSegment::Field(cow) => {
229+
PathSegment::Field(Cow::Owned(cow.clone().into_owned()))
230+
}
231+
PathSegment::Index(i) => PathSegment::Index(*i),
232+
})
233+
.collect(),
234+
)
226235
}
227236
}
228237

0 commit comments

Comments
 (0)