Merge pull request #575 from oeed/master
Implement `TryFrom<&[SelectionField<'a>]>` for `Lookahead<'a>`
This commit is contained in:
commit
5ff488fe68
|
@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- Add binary types to `ConstValue` and `Value`. [#569](https://github.com/async-graphql/async-graphql/issues/569)
|
- Add binary types to `ConstValue` and `Value`. [#569](https://github.com/async-graphql/async-graphql/issues/569)
|
||||||
- Changed Lookahead to support multiple fields. [#574](https://github.com/async-graphql/async-graphql/issues/547)
|
- Changed Lookahead to support multiple fields. [#574](https://github.com/async-graphql/async-graphql/issues/574)
|
||||||
|
- Implement `TryFrom<&[SelectionField<'a>]>` for `Lookahead<'a>`. [#575](https://github.com/async-graphql/async-graphql/issues/575)
|
||||||
|
|
||||||
- Attach custom HTTP headers to the response when an error occurs. [#572](https://github.com/async-graphql/async-graphql/issues/572)
|
- Attach custom HTTP headers to the response when an error occurs. [#572](https://github.com/async-graphql/async-graphql/issues/572)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use crate::parser::types::{Field, FragmentDefinition, Selection, SelectionSet};
|
use crate::parser::types::{Field, FragmentDefinition, Selection, SelectionSet};
|
||||||
use crate::{Name, Positioned, SelectionField};
|
use crate::{Name, Positioned, SelectionField};
|
||||||
|
@ -53,6 +54,28 @@ impl<'a> From<SelectionField<'a>> for Lookahead<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a slice of `SelectionField`s to a `Lookahead`.
|
||||||
|
/// Assumes all `SelectionField`s are from the same query and thus have the same fragments.
|
||||||
|
///
|
||||||
|
/// Fails if either no `SelectionField`s were provided.
|
||||||
|
impl<'a> TryFrom<&[SelectionField<'a>]> for Lookahead<'a> {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(selection_fields: &[SelectionField<'a>]) -> Result<Self, Self::Error> {
|
||||||
|
if selection_fields.is_empty() {
|
||||||
|
Err(())
|
||||||
|
} else {
|
||||||
|
Ok(Lookahead {
|
||||||
|
fragments: selection_fields[0].fragments,
|
||||||
|
fields: selection_fields
|
||||||
|
.iter()
|
||||||
|
.map(|selection_field| selection_field.field)
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn filter<'a>(
|
fn filter<'a>(
|
||||||
fields: &mut Vec<&'a Field>,
|
fields: &mut Vec<&'a Field>,
|
||||||
fragments: &'a HashMap<Name, Positioned<FragmentDefinition>>,
|
fragments: &'a HashMap<Name, Positioned<FragmentDefinition>>,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user