[][src]Struct warpgrapher::server::Server

pub struct Server<GlobalCtx = (), ReqCtx = ()> where
    GlobalCtx: 'static + Clone + Sync + Send + Debug,
    ReqCtx: 'static + Clone + Sync + Send + Debug + WarpgrapherRequestContext
{ pub config: WarpgrapherConfig, pub database: String, pub global_ctx: Option<GlobalCtx>, pub resolvers: WarpgrapherResolvers<GlobalCtx, ReqCtx>, pub validators: WarpgrapherValidators, pub extensions: WarpgrapherExtensions<GlobalCtx, ReqCtx>, pub bind_addr: String, pub bind_port: String, pub graphql_endpoint: String, pub playground_endpoint: Option<String>, pub version: Option<String>, // some fields omitted }

A WarpGrapher GraphQL server.

The Server struct wraps an Actix web server and a Juniper GraphQL service on top of it, with an auto-generated set of resolvers that cover basic CRUD operations, and potentially custom resolvers, on a set of data types and the relationships between them. The server includes handling of back-end communications with Neo4J.

Examples

use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

server.serve(false);
server.shutdown();

Fields

config: WarpgrapherConfigdatabase: Stringglobal_ctx: Option<GlobalCtx>resolvers: WarpgrapherResolvers<GlobalCtx, ReqCtx>validators: WarpgrapherValidatorsextensions: WarpgrapherExtensions<GlobalCtx, ReqCtx>bind_addr: Stringbind_port: Stringgraphql_endpoint: Stringplayground_endpoint: Option<String>version: Option<String>

Methods

impl<GlobalCtx, ReqCtx> Server<GlobalCtx, ReqCtx> where
    GlobalCtx: 'static + Clone + Sync + Send + Debug,
    ReqCtx: 'static + Clone + Sync + Send + Debug + WarpgrapherRequestContext
[src]

pub fn new(
    config: WarpgrapherConfig,
    database: String
) -> Server<GlobalCtx, ReqCtx>
[src]

Creates a new Server, with required parameters config and database and allows optional parameters to be added using a builder pattern.

Examples

use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::new(1, Vec::new(), Vec::new());
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_global_ctx(self, global_ctx: GlobalCtx) -> Server<GlobalCtx, ReqCtx>[src]

Adds a global context to the server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

#[derive(Clone, Debug)]
pub struct AppGlobalCtx {
    global_var: String    
}

let global_ctx = AppGlobalCtx { global_var: "Hello World".to_owned() };

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<AppGlobalCtx, ()>::new(config, db)
    .with_global_ctx(global_ctx)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_resolvers(
    self,
    resolvers: WarpgrapherResolvers<GlobalCtx, ReqCtx>
) -> Server<GlobalCtx, ReqCtx>
[src]

Adds resolvers to the server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint, WarpgrapherResolvers};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let resolvers = WarpgrapherResolvers::<(), ()>::new();

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_resolvers(resolvers)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_validators(
    self,
    validators: WarpgrapherValidators
) -> Server<GlobalCtx, ReqCtx>
[src]

Adds validators to the server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint, WarpgrapherValidators};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let validators = WarpgrapherValidators::new();

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_validators(validators)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_extensions(
    self,
    extensions: WarpgrapherExtensions<GlobalCtx, ReqCtx>
) -> Server<GlobalCtx, ReqCtx>
[src]

Adds extensions to server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint, WarpgrapherExtensions};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let extensions = WarpgrapherExtensions::<(), ()>::new();

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_extensions(extensions)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_bind_addr(self, bind_addr: String) -> Server<GlobalCtx, ReqCtx>[src]

Sets bind address on server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_bind_addr("127.0.0.1".to_owned())
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_bind_port(self, bind_port: String) -> Server<GlobalCtx, ReqCtx>[src]

Sets bind port on server

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn with_graphql_endpoint(
    self,
    graphql_endpoint: String
) -> Server<GlobalCtx, ReqCtx>
[src]

Sets the endpoint that will handle the graphql queries

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_graphql_endpoint("/graphql".to_owned())
    .build().unwrap();

pub fn with_playground_endpoint(
    self,
    playground_endpoint: String
) -> Server<GlobalCtx, ReqCtx>
[src]

Sets the endpoint where the UI playground in hosted

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_playground_endpoint("/playground".to_owned())
    .build().unwrap();

pub fn with_version(self, version: String) -> Server<GlobalCtx, ReqCtx>[src]

Sets the version of the app

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_version("1.0.0".to_owned())
    .build().unwrap();

pub fn build(self) -> Result<Server<GlobalCtx, ReqCtx>, Error>[src]

Builds a configured Server including generateing the data model, CRUD operations, and custom endpoints from the WarpgrapherConfiguration c. Sets the GraphQL endpoint to /graphql and the GraphIQL endpoint to /graphiql. Returns the Server.

Errors

Returns an Error of kind CouldNotResolveWarpgrapherType if there is an error in the configuration, specifically if the configuration of type A references type B, but type B cannot be found.

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::new(1, Vec::new(), Vec::new());
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

pub fn serve(&mut self, block: bool) -> Result<(), Error>[src]

Binds the server to addr and begins listening for and answering requests. If the block boolean is true, the server blocks the main thread, requiring the program to be killed to exit. If block is false, the server launches in a separate thread and this function returns () immediately. The server may then be shut down gracefully by calling shutdown.

Errors

Returns an Error of kind ServerAlreadyRunning if serve was already called to start a non-blocking server.

Returns an Error of kind AddrInUse if there is already another server bound to the port as a listener.

Returns an Error of kind AddrNotAvailable if the address provided cannot be bound, for example if it is not local.

Returns an Error of kind ServerStartupFailed if there is an internal error in setting up the server. Receiving this error would likely mean a bug in WarpGrapher.

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::default();
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<(), ()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

server.serve(false);
server.shutdown();

pub fn shutdown(&mut self) -> Result<(), Error>[src]

Shuts down a server previously started using the ['serve']: #method.serve method with a block argument of false.

Returns a result of Ok(()) if the server is shutdown successfully. Returns an error of kind ['ServerNotStarted']: ../enum.ServerNotStarted.html if there was no prior call to ['serve']: #method.serve to start the server. Returns an error of kind ['ServerShutdownFailed']: ../enum.ServerShutdownFailed.html if the server could not be shutdown successfully. This shouldn't happen, as it would indicate, for example, that the signal flag used to signal to the server to shutdown was deallocated prior to shutting down the server, or that the server thread panicked prior to shutting down in an orderly fashion.

Examples

use std::env::var_os;
use warpgrapher::{Server, Neo4jEndpoint};
use warpgrapher::server::config::WarpgrapherConfig;
use warpgrapher::server::{bind_port_from_env};

let config = WarpgrapherConfig::new(1, Vec::new(), Vec::new());
let db = Neo4jEndpoint::from_env("DB_URL").unwrap();

let mut server = Server::<()>::new(config, db)
    .with_bind_port(bind_port_from_env("WG_BIND_PORT"))
    .build().unwrap();

server.serve(false);
server.shutdown();

Auto Trait Implementations

impl<GlobalCtx = (), ReqCtx = ()> !RefUnwindSafe for Server<GlobalCtx, ReqCtx>

impl<GlobalCtx, ReqCtx> Send for Server<GlobalCtx, ReqCtx>

impl<GlobalCtx, ReqCtx> Sync for Server<GlobalCtx, ReqCtx>

impl<GlobalCtx, ReqCtx> Unpin for Server<GlobalCtx, ReqCtx> where
    GlobalCtx: Unpin

impl<GlobalCtx = (), ReqCtx = ()> !UnwindSafe for Server<GlobalCtx, ReqCtx>

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> Erased for T

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.

impl<T> Typeable for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,