Implements Debug for SelectionField. #364

This commit is contained in:
Sunli 2021-01-01 12:03:30 +08:00
parent e13d1a3f03
commit 6b540c3845

View File

@ -623,6 +623,7 @@ impl<'a> ContextBase<'a, &'a Positioned<Field>> {
}
/// Selection field.
#[derive(Clone, Copy)]
pub struct SelectionField<'a> {
fragments: &'a HashMap<Name, Positioned<FragmentDefinition>>,
field: &'a Field,
@ -643,6 +644,26 @@ impl<'a> SelectionField<'a> {
}
}
struct DebugSelectionSet<'a>(Vec<SelectionField<'a>>);
impl<'a> Debug for DebugSelectionSet<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.0.clone()).finish()
}
}
impl<'a> Debug for SelectionField<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct(self.name())
.field("name", &self.name())
.field(
"selection_set",
&DebugSelectionSet(self.selection_set().collect()),
)
.finish()
}
}
struct SelectionFieldsIter<'a> {
fragments: &'a HashMap<Name, Positioned<FragmentDefinition>>,
iter: Vec<std::slice::Iter<'a, Positioned<Selection>>>,