File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use std::collections::{BTreeMap, HashMap};
5
5
use std:: ops:: { Deref , DerefMut } ;
6
6
use std:: sync:: Arc ;
7
7
8
+ use crate :: data:: graphql:: shape_hash:: shape_hash;
8
9
use crate :: data:: schema:: Schema ;
9
10
10
11
fn deserialize_number < ' de , D > ( deserializer : D ) -> Result < q:: Number , D :: Error >
@@ -109,6 +110,7 @@ pub struct Query {
109
110
pub schema : Arc < Schema > ,
110
111
pub document : q:: Document ,
111
112
pub variables : Option < QueryVariables > ,
113
+ pub shape_hash : u64 ,
112
114
_force_use_of_new : ( ) ,
113
115
}
114
116
@@ -118,10 +120,12 @@ impl Query {
118
120
document : q:: Document ,
119
121
variables : Option < QueryVariables > ,
120
122
) -> Self {
123
+ let shape_hash = shape_hash ( & document) ;
121
124
Query {
122
125
schema,
123
126
document,
124
127
variables,
128
+ shape_hash,
125
129
_force_use_of_new : ( ) ,
126
130
}
127
131
}
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ pub struct Query {
35
35
pub variables : HashMap < q:: Name , q:: Value > ,
36
36
/// The root selection set of the query
37
37
pub selection_set : q:: SelectionSet ,
38
+ /// The ShapeHash of the original query
39
+ pub shape_hash : u64 ,
40
+
38
41
pub ( crate ) fragments : HashMap < String , q:: FragmentDefinition > ,
39
42
kind : Kind ,
40
43
@@ -106,6 +109,7 @@ impl Query {
106
109
variables,
107
110
fragments,
108
111
selection_set,
112
+ shape_hash : query. shape_hash ,
109
113
kind,
110
114
query_text,
111
115
variables_text,
@@ -160,6 +164,7 @@ impl Query {
160
164
variables : self . variables . clone ( ) ,
161
165
fragments : self . fragments . clone ( ) ,
162
166
selection_set : self . selection_set . clone ( ) ,
167
+ shape_hash : self . shape_hash ,
163
168
kind : self . kind ,
164
169
query_text : self . query_text . clone ( ) ,
165
170
variables_text : self . variables_text . clone ( ) ,
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ where
146
146
}
147
147
148
148
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 ) {
150
150
Err ( vec ! [ QueryExecutionError :: TooExpensive ] )
151
151
} else {
152
152
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments