Add `SchemaBuilder::enable_suggestions` method to enable or disable field suggestions. #1101
This commit is contained in:
parent
13a66a5013
commit
e50808888a
|
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
# [4.0.15] 2022-10-01
|
||||
|
||||
- Skip tracing for introspection queries. [#841](https://github.com/async-graphql/async-graphql/issues/841)
|
||||
- Add `SchemaBuilder::enable_suggestions` method to enable or disable field suggestions. [#1101](https://github.com/async-graphql/async-graphql/issues/1101)
|
||||
|
||||
# [4.0.14] 2022-09-25
|
||||
|
||||
|
|
|
@ -601,6 +601,7 @@ pub struct Registry {
|
|||
pub enable_federation: bool,
|
||||
pub federation_subscription: bool,
|
||||
pub ignore_name_conflicts: HashSet<String>,
|
||||
pub enable_suggestions: bool,
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
|
|
|
@ -219,6 +219,13 @@ impl<Query, Mutation, Subscription> SchemaBuilder<Query, Mutation, Subscription>
|
|||
self
|
||||
}
|
||||
|
||||
/// Enable field suggestions, default is `true`.
|
||||
#[must_use]
|
||||
pub fn enable_suggestions(mut self, enable: bool) -> Self {
|
||||
self.registry.enable_suggestions = enable;
|
||||
self
|
||||
}
|
||||
|
||||
/// Build schema.
|
||||
pub fn finish(mut self) -> Schema<Query, Mutation, Subscription> {
|
||||
// federation
|
||||
|
@ -381,6 +388,7 @@ where
|
|||
enable_federation: false,
|
||||
federation_subscription: false,
|
||||
ignore_name_conflicts,
|
||||
enable_suggestions: true,
|
||||
};
|
||||
|
||||
registry.add_directive(MetaDirective {
|
||||
|
|
|
@ -38,17 +38,21 @@ impl<'a> Visitor<'a> for FieldsOnCorrectType {
|
|||
"Unknown field \"{}\" on type \"{}\".{}",
|
||||
field.node.name,
|
||||
parent_type.name(),
|
||||
make_suggestion(
|
||||
" Did you mean",
|
||||
parent_type
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|fields| fields.keys())
|
||||
.flatten()
|
||||
.map(String::as_str),
|
||||
&field.node.name.node,
|
||||
)
|
||||
.unwrap_or_default()
|
||||
if ctx.registry.enable_suggestions {
|
||||
make_suggestion(
|
||||
" Did you mean",
|
||||
parent_type
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|fields| fields.keys())
|
||||
.flatten()
|
||||
.map(String::as_str),
|
||||
&field.node.name.node,
|
||||
)
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ impl<'a> Visitor<'a> for KnownArgumentNames<'a> {
|
|||
name,
|
||||
field_name,
|
||||
type_name,
|
||||
self.get_suggestion(name.node.as_str())
|
||||
if ctx.registry.enable_suggestions {
|
||||
self.get_suggestion(name.node.as_str())
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue