[go: up one dir, main page]

Trait cynic::http::SurfExt

source ·
pub trait SurfExt {
    fn run_graphql<ResponseData, Vars>(
        self,
        operation: Operation<ResponseData, Vars>
    ) -> Pin<Box<dyn Future<Output = Result<GraphQlResponse<ResponseData>, Error>> + Send + 'static>>
    where
        Vars: Serialize,
        ResponseData: DeserializeOwned + 'static
; }
Available on crate features surf and http-surf only.
Expand description

An extension trait for surf::RequestBuilder.

use cynic::{http::SurfExt, QueryBuilder};

let operation = FilmDirectorQuery::build(());

let response = surf::post("https://swapi-graphql.netlify.app/.netlify/functions/index")
    .run_graphql(operation)
    .await
    .unwrap();

println!(
    "The director is {}",
    response.data
        .and_then(|d| d.film)
        .and_then(|f| f.director)
        .unwrap()
);

Required Methods§

Runs a GraphQL query with the parameters in RequestBuilder, deserializes the response and returns the result.

Implementations on Foreign Types§

Available on crate feature http-surf only.

Implementors§