[][src]Struct cynic::selection_set::SelectionSet

pub struct SelectionSet<'a, DecodesTo, TypeLock> { /* fields omitted */ }

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 query_dsl functionality in cynic to annotate each SelectionSet it returns such that you can't build incorrect queries.

Implementations

impl<'a, DecodesTo, TypeLock> SelectionSet<'a, DecodesTo, TypeLock>[src]

pub fn map<F, R>(self, f: F) -> SelectionSet<'a, R, TypeLock> where
    F: Fn(DecodesTo) -> R + 'a + Sync + Send,
    DecodesTo: 'a,
    R: 'a, 
[src]

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, 
[src]

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>, 
[src]

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>

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> FlattenInto<U> for T where
    U: FlattenFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.