Improve the performance of introspection queries.
This commit is contained in:
parent
1a6facea93
commit
68b5ed680f
|
@ -453,7 +453,7 @@ pub fn generate(
|
|||
impl #crate_name::SubscriptionType for #self_ty {
|
||||
fn create_field_stream<'__life>(
|
||||
&'__life self,
|
||||
ctx: &'__life #crate_name::Context<'__life>,
|
||||
ctx: &'__life #crate_name::Context<'_>,
|
||||
) -> ::std::option::Option<::std::pin::Pin<::std::boxed::Box<dyn #crate_name::futures_util::stream::Stream<Item = #crate_name::ServerResult<#crate_name::Value>> + ::std::marker::Send + '__life>>> {
|
||||
#(#create_stream)*
|
||||
::std::option::Option::None
|
||||
|
|
|
@ -74,12 +74,12 @@ pub struct __Directive<'a> {
|
|||
/// In some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.
|
||||
#[Object(internal, name = "__Directive")]
|
||||
impl<'a> __Directive<'a> {
|
||||
async fn name(&self) -> String {
|
||||
self.directive.name.to_string()
|
||||
async fn name(&self) -> &str {
|
||||
self.directive.name
|
||||
}
|
||||
|
||||
async fn description(&self) -> Option<String> {
|
||||
self.directive.description.map(ToString::to_string)
|
||||
async fn description(&self) -> Option<&str> {
|
||||
self.directive.description
|
||||
}
|
||||
|
||||
async fn locations(&self) -> &Vec<__DirectiveLocation> {
|
||||
|
|
|
@ -8,19 +8,19 @@ pub struct __EnumValue<'a> {
|
|||
/// One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.
|
||||
#[Object(internal, name = "__EnumValue")]
|
||||
impl<'a> __EnumValue<'a> {
|
||||
async fn name(&self) -> String {
|
||||
self.value.name.to_string()
|
||||
async fn name(&self) -> &str {
|
||||
self.value.name
|
||||
}
|
||||
|
||||
async fn description(&self) -> Option<String> {
|
||||
self.value.description.map(ToString::to_string)
|
||||
async fn description(&self) -> Option<&str> {
|
||||
self.value.description
|
||||
}
|
||||
|
||||
async fn is_deprecated(&self) -> bool {
|
||||
self.value.deprecation.is_some()
|
||||
}
|
||||
|
||||
async fn deprecation_reason(&self) -> Option<String> {
|
||||
self.value.deprecation.map(ToString::to_string)
|
||||
async fn deprecation_reason(&self) -> Option<&str> {
|
||||
self.value.deprecation
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ pub struct __Field<'a> {
|
|||
/// Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.
|
||||
#[Object(internal, name = "__Field")]
|
||||
impl<'a> __Field<'a> {
|
||||
async fn name(&self) -> String {
|
||||
self.field.name.to_string()
|
||||
async fn name(&self) -> &str {
|
||||
&self.field.name
|
||||
}
|
||||
|
||||
async fn description(&self) -> Option<String> {
|
||||
self.field.description.map(ToString::to_string)
|
||||
async fn description(&self) -> Option<&str> {
|
||||
self.field.description
|
||||
}
|
||||
|
||||
async fn args(&self, ctx: &Context<'_>) -> Vec<__InputValue<'a>> {
|
||||
|
@ -41,7 +41,7 @@ impl<'a> __Field<'a> {
|
|||
self.field.deprecation.is_some()
|
||||
}
|
||||
|
||||
async fn deprecation_reason(&self) -> Option<String> {
|
||||
self.field.deprecation.map(ToString::to_string)
|
||||
async fn deprecation_reason(&self) -> Option<&str> {
|
||||
self.field.deprecation
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ pub struct __InputValue<'a> {
|
|||
/// Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.
|
||||
#[Object(internal, name = "__InputValue")]
|
||||
impl<'a> __InputValue<'a> {
|
||||
async fn name(&self) -> String {
|
||||
self.input_value.name.to_string()
|
||||
async fn name(&self) -> &str {
|
||||
self.input_value.name
|
||||
}
|
||||
|
||||
async fn description(&self) -> Option<String> {
|
||||
self.input_value.description.map(ToString::to_string)
|
||||
async fn description(&self) -> Option<&str> {
|
||||
self.input_value.description
|
||||
}
|
||||
|
||||
#[graphql(name = "type")]
|
||||
|
@ -22,7 +22,7 @@ impl<'a> __InputValue<'a> {
|
|||
__Type::new(self.registry, &self.input_value.ty)
|
||||
}
|
||||
|
||||
async fn default_value(&self) -> Option<String> {
|
||||
self.input_value.default_value.clone()
|
||||
async fn default_value(&self) -> Option<&str> {
|
||||
self.input_value.default_value.as_deref()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,35 +58,23 @@ impl<'a> __Type<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn name(&self) -> Option<String> {
|
||||
async fn name(&self) -> Option<&str> {
|
||||
match &self.detail {
|
||||
TypeDetail::Named(ty) => Some(ty.name().to_string()),
|
||||
TypeDetail::Named(ty) => Some(ty.name()),
|
||||
TypeDetail::NonNull(_) => None,
|
||||
TypeDetail::List(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
async fn description(&self) -> Option<String> {
|
||||
async fn description(&self) -> Option<&str> {
|
||||
match &self.detail {
|
||||
TypeDetail::Named(ty) => match ty {
|
||||
registry::MetaType::Scalar { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::Object { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::Interface { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::Union { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::Enum { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::InputObject { description, .. } => {
|
||||
description.map(ToString::to_string)
|
||||
}
|
||||
registry::MetaType::Scalar { description, .. }
|
||||
| registry::MetaType::Object { description, .. }
|
||||
| registry::MetaType::Interface { description, .. }
|
||||
| registry::MetaType::Union { description, .. }
|
||||
| registry::MetaType::Enum { description, .. }
|
||||
| registry::MetaType::InputObject { description, .. } => description.as_deref(),
|
||||
},
|
||||
TypeDetail::NonNull(_) => None,
|
||||
TypeDetail::List(_) => None,
|
||||
|
|
|
@ -18,7 +18,7 @@ pub trait SubscriptionType: Type + Send + Sync {
|
|||
#[doc(hidden)]
|
||||
fn create_field_stream<'a>(
|
||||
&'a self,
|
||||
ctx: &'a Context<'a>,
|
||||
ctx: &'a Context<'_>,
|
||||
) -> Option<Pin<Box<dyn Stream<Item = ServerResult<Value>> + Send + 'a>>>;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ pub(crate) fn collect_subscription_streams<'a, T: SubscriptionType + 'static>(
|
|||
impl<T: SubscriptionType> SubscriptionType for &T {
|
||||
fn create_field_stream<'a>(
|
||||
&'a self,
|
||||
ctx: &'a Context<'a>,
|
||||
ctx: &'a Context<'_>,
|
||||
) -> Option<Pin<Box<dyn Stream<Item = ServerResult<Value>> + Send + 'a>>> {
|
||||
T::create_field_stream(*self, ctx)
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl SubscriptionType for EmptySubscription {
|
|||
|
||||
fn create_field_stream<'a>(
|
||||
&'a self,
|
||||
ctx: &'a Context<'a>,
|
||||
ctx: &'a Context<'_>,
|
||||
) -> Option<Pin<Box<dyn Stream<Item = ServerResult<Value>> + Send + 'a>>>
|
||||
where
|
||||
Self: Send + Sync + 'static + Sized,
|
||||
|
|
Loading…
Reference in New Issue
Block a user