Skip to content

Commit bf5b62d

Browse files
committed
graphql: unlock GRAPHQL_VALIDATION_CACHE quickly
1 parent 7da9eb1 commit bf5b62d

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

graphql/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
crossbeam = "0.8"
88
graph = { path = "../graph" }
99
graphql-parser = "0.4.0"
10-
graphql-tools = "0.0.19"
10+
graphql-tools = { git = "https://github.com/dotansimha/graphql-tools-rs", branch = "kamilkisiela-patch-1" }
1111
indexmap = "1.9"
1212
Inflector = "0.11.3"
1313
lazy_static = "1.2.0"

graphql/src/execution/query.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ pub struct Query {
143143
pub query_id: String,
144144
}
145145

146+
fn validate_query(query: &GraphDataQuery, document: &s::Document) -> Vec<ValidationError> {
147+
let mut cache = GRAPHQL_VALIDATION_CACHE
148+
.lock()
149+
.unwrap_or_else(PoisonError::into_inner);
150+
151+
let errors = cache.entry(query.shape_hash)
152+
.or_insert_with(|| {
153+
validate(
154+
&document,
155+
&query.document,
156+
&GRAPHQL_VALIDATION_PLAN,
157+
)
158+
});
159+
160+
return errors.clone();
161+
}
162+
146163
impl Query {
147164
/// Process the raw GraphQL query `query` and prepare for executing it.
148165
/// The returned `Query` has already been validated and, if `max_complexity`
@@ -156,17 +173,7 @@ impl Query {
156173
max_complexity: Option<u64>,
157174
max_depth: u8,
158175
) -> Result<Arc<Self>, Vec<QueryExecutionError>> {
159-
GRAPHQL_VALIDATION_CACHE
160-
.lock()
161-
.unwrap_or_else(PoisonError::into_inner)
162-
.entry(query.shape_hash)
163-
.or_insert_with(|| {
164-
validate(
165-
&schema.document(),
166-
&query.document,
167-
&GRAPHQL_VALIDATION_PLAN,
168-
)
169-
});
176+
let validation_errors = validate_query(&query, &schema.document());
170177

171178
if !validation_errors.is_empty() {
172179
if !ENV_VARS.graphql.silent_graphql_validations {

0 commit comments

Comments
 (0)