Skip to content

Commit fa9e165

Browse files
committed
graphql: Simplify constructing an ExecutionContext for introspection
1 parent 21388fd commit fa9e165

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

graphql/src/execution/execution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ where
264264
ExecutionContext {
265265
logger: self.logger.cheap_clone(),
266266
resolver: introspection_resolver,
267-
query: self.query.as_introspection_query(),
267+
query: self.query.cheap_clone(),
268268
deadline: self.deadline,
269269
max_first: std::u32::MAX,
270270
max_skip: std::u32::MAX,

graphql/src/execution/query.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use graph::data::schema::ApiSchema;
1818
use graph::prelude::{info, o, q, r, s, BlockNumber, CheapClone, Logger, TryFromValue};
1919

2020
use crate::execution::ast as a;
21-
use crate::introspection::introspection_schema;
2221
use crate::query::{ast as qast, ext::BlockConstraint};
2322
use crate::schema::ast as sast;
2423
use crate::{
@@ -135,7 +134,6 @@ pub struct Query {
135134
pub query_text: Arc<String>,
136135
pub variables_text: Arc<String>,
137136
pub query_id: String,
138-
pub(crate) complexity: u64,
139137
}
140138

141139
impl Query {
@@ -220,9 +218,11 @@ impl Query {
220218
fragments,
221219
};
222220

223-
// It's important to check complexity first, so `validate_fields` doesn't risk a stack
224-
// overflow from invalid queries.
225-
let complexity = raw_query.check_complexity(max_complexity, max_depth)?;
221+
// It's important to check complexity first, so `validate_fields`
222+
// doesn't risk a stack overflow from invalid queries. We don't
223+
// really care about the resulting complexity, only that all the
224+
// checks that `check_complexity` performs pass successfully
225+
let _ = raw_query.check_complexity(max_complexity, max_depth)?;
226226
raw_query.validate_fields()?;
227227
let (selection_set, fragments) = raw_query.expand_variables()?;
228228

@@ -238,7 +238,6 @@ impl Query {
238238
query_text: query.query_text.cheap_clone(),
239239
variables_text: query.variables_text.cheap_clone(),
240240
query_id,
241-
complexity,
242241
};
243242

244243
Ok(Arc::new(query))
@@ -311,26 +310,6 @@ impl Query {
311310
}
312311
}
313312

314-
/// Return this query, but use the introspection schema as its schema
315-
pub fn as_introspection_query(&self) -> Arc<Self> {
316-
let introspection_schema = introspection_schema(self.schema.id().clone());
317-
318-
Arc::new(Self {
319-
schema: Arc::new(introspection_schema),
320-
fragments: self.fragments.clone(),
321-
selection_set: self.selection_set.clone(),
322-
shape_hash: self.shape_hash,
323-
kind: self.kind,
324-
network: self.network.clone(),
325-
logger: self.logger.clone(),
326-
start: self.start,
327-
query_text: self.query_text.clone(),
328-
variables_text: self.variables_text.clone(),
329-
query_id: self.query_id.clone(),
330-
complexity: self.complexity,
331-
})
332-
}
333-
334313
/// Should only be called for fragments that exist in the query, and therefore have been
335314
/// validated to exist. Panics otherwise.
336315
pub fn get_fragment(&self, name: &str) -> &a::FragmentDefinition {

0 commit comments

Comments
 (0)