Add context to ResolveInfo. #260

This commit is contained in:
Sunli 2020-09-09 18:42:10 +08:00
parent 175a48875e
commit a4a5847d4f
4 changed files with 8 additions and 2 deletions

View File

@ -201,7 +201,8 @@ impl<'a> std::fmt::Display for QueryPathNode<'a> {
} }
impl<'a> QueryPathNode<'a> { impl<'a> QueryPathNode<'a> {
pub(crate) fn field_name(&self) -> &str { /// Get the current field name.
pub fn field_name(&self) -> &str {
let mut p = self; let mut p = self;
loop { loop {
if let QueryPathSegment::Name(name) = &p.segment { if let QueryPathSegment::Name(name) = &p.segment {

View File

@ -5,7 +5,7 @@ mod logger;
mod tracing; mod tracing;
use crate::context::{QueryPathNode, ResolveId}; use crate::context::{QueryPathNode, ResolveId};
use crate::{Result, Variables}; use crate::{Context, Result, Variables};
pub use self::apollo_tracing::ApolloTracing; pub use self::apollo_tracing::ApolloTracing;
pub use self::logger::Logger; pub use self::logger::Logger;
@ -28,6 +28,9 @@ pub struct ResolveInfo<'a> {
/// Current path node, You can go through the entire path. /// Current path node, You can go through the entire path.
pub path_node: &'a QueryPathNode<'a>, pub path_node: &'a QueryPathNode<'a>,
/// Context
pub context: &'a Context<'a>,
/// Parent type /// Parent type
pub parent_type: &'a str, pub parent_type: &'a str,

View File

@ -64,6 +64,7 @@ fn do_resolve<'a, T: ObjectType + Send + Sync>(
let resolve_info = ResolveInfo { let resolve_info = ResolveInfo {
resolve_id: ctx_field.resolve_id, resolve_id: ctx_field.resolve_id,
path_node: ctx_field.path_node.as_ref().unwrap(), path_node: ctx_field.path_node.as_ref().unwrap(),
context: &ctx_field,
parent_type: &T::type_name(), parent_type: &T::type_name(),
return_type: match ctx_field return_type: match ctx_field
.schema_env .schema_env

View File

@ -83,6 +83,7 @@ pub fn collect_fields<'a, T: ObjectType + Send + Sync>(
let resolve_info = ResolveInfo { let resolve_info = ResolveInfo {
resolve_id: ctx_field.resolve_id, resolve_id: ctx_field.resolve_id,
path_node: ctx_field.path_node.as_ref().unwrap(), path_node: ctx_field.path_node.as_ref().unwrap(),
context: &ctx_field,
parent_type: &T::type_name(), parent_type: &T::type_name(),
return_type: match ctx_field return_type: match ctx_field
.schema_env .schema_env