Struct cynic::selection_set::SelectionSet [−][src]
pub struct SelectionSet<'a, DecodesTo, TypeLock> { /* fields omitted */ }
Expand description
A SelectionSet
is a combination of a set of fields to fetch as part of a
GraphQL query and a decoder function that will decode the results of that
query.
Each SelectionSet
has two generic parmeters:
DecodesTo
is the type that the selection set will decode when it is fed the results of it’s query.TypeLock
is used to enforce type safety. It allows the functions in aschema
module to annotate each SelectionSet it returns such that you can’t build incorrect queries.
Implementations
Maps a SelectionSet<_, DecodesTo, _>
to a SelectionSet<_, R, _>
by applying
the provided function f
to the decoded data when decoding query results.
For example, to fetch a string and then lowercase it:
string().map(|s| s.to_lowercase());
pub fn and_then<F, R>(self, f: F) -> SelectionSet<'a, R, TypeLock> where
F: Fn(DecodesTo) -> SelectionSet<'a, R, TypeLock> + 'a + Sync + Send,
DecodesTo: 'a,
R: 'a,
pub fn and_then<F, R>(self, f: F) -> SelectionSet<'a, R, TypeLock> where
F: Fn(DecodesTo) -> SelectionSet<'a, R, TypeLock> + 'a + Sync + Send,
DecodesTo: 'a,
R: 'a,
Creates a SelectionSet
that depends on previous resutls.
For example, to decode a different type depending on the value of another field:
field::<_, (), _>("__typename", vec![], string())
.and_then(|typename| match typename.as_ref() {
"Cat" => field("cat", vec![], string()),
"Dog" => field("dog", vec![], string()),
_ => fail("")
});
pub fn transform_typelock<NewLock>(self) -> SelectionSet<'a, DecodesTo, NewLock> where
NewLock: HasSubtype<TypeLock>,
pub fn transform_typelock<NewLock>(self) -> SelectionSet<'a, DecodesTo, NewLock> where
NewLock: HasSubtype<TypeLock>,
Changes the TypeLock
on a SelectionSet
.
This is used when querying for an interface or a union type where you have
a SelectionSet
type locked to a subtype of an interface and want to use
get a SelectionSet
compatible with a field that has the type of the
interface.
Auto Trait Implementations
impl<'a, DecodesTo, TypeLock> !RefUnwindSafe for SelectionSet<'a, DecodesTo, TypeLock>
impl<'a, DecodesTo, TypeLock> Send for SelectionSet<'a, DecodesTo, TypeLock> where
TypeLock: Send,
impl<'a, DecodesTo, TypeLock> Sync for SelectionSet<'a, DecodesTo, TypeLock> where
TypeLock: Sync,
impl<'a, DecodesTo, TypeLock> Unpin for SelectionSet<'a, DecodesTo, TypeLock> where
TypeLock: Unpin,
impl<'a, DecodesTo, TypeLock> !UnwindSafe for SelectionSet<'a, DecodesTo, TypeLock>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more