Skip to content

Commit 38e21b3

Browse files
committed
graph, graphql: Store the shape_hash in our Query structs
1 parent 6f309c4 commit 38e21b3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

graph/src/data/query/query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::{BTreeMap, HashMap};
55
use std::ops::{Deref, DerefMut};
66
use std::sync::Arc;
77

8+
use crate::data::graphql::shape_hash::shape_hash;
89
use crate::data::schema::Schema;
910

1011
fn deserialize_number<'de, D>(deserializer: D) -> Result<q::Number, D::Error>
@@ -109,6 +110,7 @@ pub struct Query {
109110
pub schema: Arc<Schema>,
110111
pub document: q::Document,
111112
pub variables: Option<QueryVariables>,
113+
pub shape_hash: u64,
112114
_force_use_of_new: (),
113115
}
114116

@@ -118,10 +120,12 @@ impl Query {
118120
document: q::Document,
119121
variables: Option<QueryVariables>,
120122
) -> Self {
123+
let shape_hash = shape_hash(&document);
121124
Query {
122125
schema,
123126
document,
124127
variables,
128+
shape_hash,
125129
_force_use_of_new: (),
126130
}
127131
}

graphql/src/execution/query.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ pub struct Query {
3535
pub variables: HashMap<q::Name, q::Value>,
3636
/// The root selection set of the query
3737
pub selection_set: q::SelectionSet,
38+
/// The ShapeHash of the original query
39+
pub shape_hash: u64,
40+
3841
pub(crate) fragments: HashMap<String, q::FragmentDefinition>,
3942
kind: Kind,
4043

@@ -106,6 +109,7 @@ impl Query {
106109
variables,
107110
fragments,
108111
selection_set,
112+
shape_hash: query.shape_hash,
109113
kind,
110114
query_text,
111115
variables_text,
@@ -160,6 +164,7 @@ impl Query {
160164
variables: self.variables.clone(),
161165
fragments: self.fragments.clone(),
162166
selection_set: self.selection_set.clone(),
167+
shape_hash: self.shape_hash,
163168
kind: self.kind,
164169
query_text: self.query_text.clone(),
165170
variables_text: self.variables_text.clone(),

graphql/src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
}
147147

148148
pub fn check_too_expensive(&self, query: &Query) -> Result<(), Vec<QueryExecutionError>> {
149-
if self.expensive.contains_key(&shape_hash(&query.document)) {
149+
if self.expensive.contains_key(&query.shape_hash) {
150150
Err(vec![QueryExecutionError::TooExpensive])
151151
} else {
152152
Ok(())

0 commit comments

Comments
 (0)