Struct async_graphql::extensions::NextExecute
source · pub struct NextExecute<'a> { /* private fields */ }
Expand description
The remainder of a extension chain for execute.
Implementations§
source§impl<'a> NextExecute<'a>
impl<'a> NextExecute<'a>
sourcepub async fn run(
self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>
) -> Response
pub async fn run(
self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>
) -> Response
Call the Extension::execute function of next extension.
Examples found in repository?
src/extensions/mod.rs (line 379)
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
async fn execute(
&self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>,
next: NextExecute<'_>,
) -> Response {
next.run(ctx, operation_name).await
}
/// Called at resolve field.
async fn resolve(
&self,
ctx: &ExtensionContext<'_>,
info: ResolveInfo<'_>,
next: NextResolve<'_>,
) -> ServerResult<Option<Value>> {
next.run(ctx, info).await
}
}
/// Extension factory
///
/// Used to create an extension instance.
pub trait ExtensionFactory: Send + Sync + 'static {
/// Create an extended instance.
fn create(&self) -> Arc<dyn Extension>;
}
#[derive(Clone)]
#[doc(hidden)]
pub struct Extensions {
extensions: Vec<Arc<dyn Extension>>,
schema_env: SchemaEnv,
session_data: Arc<Data>,
query_data: Option<Arc<Data>>,
}
#[doc(hidden)]
impl Extensions {
pub(crate) fn new(
extensions: impl IntoIterator<Item = Arc<dyn Extension>>,
schema_env: SchemaEnv,
session_data: Arc<Data>,
) -> Self {
Extensions {
extensions: extensions.into_iter().collect(),
schema_env,
session_data,
query_data: None,
}
}
#[inline]
pub fn attach_query_data(&mut self, data: Arc<Data>) {
self.query_data = Some(data);
}
#[inline]
pub(crate) fn is_empty(&self) -> bool {
self.extensions.is_empty()
}
#[inline]
fn create_context(&self) -> ExtensionContext {
ExtensionContext {
schema_env: &self.schema_env,
session_data: &self.session_data,
query_data: self.query_data.as_deref(),
}
}
pub async fn request(&self, request_fut: RequestFut<'_>) -> Response {
let next = NextRequest {
chain: &self.extensions,
request_fut,
};
next.run(&self.create_context()).await
}
pub fn subscribe<'s>(&self, stream: BoxStream<'s, Response>) -> BoxStream<'s, Response> {
let next = NextSubscribe {
chain: &self.extensions,
};
next.run(&self.create_context(), stream)
}
pub async fn prepare_request(&self, request: Request) -> ServerResult<Request> {
let next = NextPrepareRequest {
chain: &self.extensions,
};
next.run(&self.create_context(), request).await
}
pub async fn parse_query(
&self,
query: &str,
variables: &Variables,
parse_query_fut: ParseFut<'_>,
) -> ServerResult<ExecutableDocument> {
let next = NextParseQuery {
chain: &self.extensions,
parse_query_fut,
};
next.run(&self.create_context(), query, variables).await
}
pub async fn validation(
&self,
validation_fut: ValidationFut<'_>,
) -> Result<ValidationResult, Vec<ServerError>> {
let next = NextValidation {
chain: &self.extensions,
validation_fut,
};
next.run(&self.create_context()).await
}
pub async fn execute(
&self,
operation_name: Option<&str>,
execute_fut: ExecuteFut<'_>,
) -> Response {
let next = NextExecute {
chain: &self.extensions,
execute_fut,
};
next.run(&self.create_context(), operation_name).await
}
More examples
src/extensions/tracing.rs (line 127)
116 117 118 119 120 121 122 123 124 125 126 127 128
async fn execute(
&self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>,
next: NextExecute<'_>,
) -> Response {
let span = span!(
target: "async_graphql::graphql",
Level::INFO,
"execute"
);
next.run(ctx, operation_name).instrument(span).await
}
src/extensions/opentelemetry.rs (line 160)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
async fn execute(
&self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>,
next: NextExecute<'_>,
) -> Response {
let span = self
.tracer
.span_builder("execute")
.with_kind(SpanKind::Server)
.start(&*self.tracer);
next.run(ctx, operation_name)
.with_context(OpenTelemetryContext::current_with_span(span))
.await
}
src/extensions/apollo_tracing.rs (line 82)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
async fn execute(
&self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>,
next: NextExecute<'_>,
) -> Response {
self.inner.lock().await.start_time = Utc::now();
let resp = next.run(ctx, operation_name).await;
let mut inner = self.inner.lock().await;
inner.end_time = Utc::now();
inner
.resolves
.sort_by(|a, b| a.start_offset.cmp(&b.start_offset));
resp.extension(
"tracing",
value!({
"version": 1,
"startTime": inner.start_time.to_rfc3339(),
"endTime": inner.end_time.to_rfc3339(),
"duration": (inner.end_time - inner.start_time).num_nanoseconds(),
"execution": {
"resolvers": inner.resolves
}
}),
)
}
src/extensions/logger.rs (line 51)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
async fn execute(
&self,
ctx: &ExtensionContext<'_>,
operation_name: Option<&str>,
next: NextExecute<'_>,
) -> Response {
let resp = next.run(ctx, operation_name).await;
if resp.is_err() {
for err in &resp.errors {
if !err.path.is_empty() {
let mut path = String::new();
for (idx, s) in err.path.iter().enumerate() {
if idx > 0 {
path.push('.');
}
match s {
PathSegment::Index(idx) => {
let _ = write!(&mut path, "{}", idx);
}
PathSegment::Field(name) => {
let _ = write!(&mut path, "{}", name);
}
}
}
log::info!(
target: "async-graphql",
"[Error] path={} message={}", path, err.message,
);
} else {
log::info!(
target: "async-graphql",
"[Error] message={}", err.message,
);
}
}
}
resp
}