INNER CODE UNIT · Rust
create_schema_with_context
rkudryashov/graphql-rust-demo · satellites-service/src/lib.rs:36
pub fn create_schema_with_context(pool: PgPool) -> Schema<Query, EmptyMutation, EmptySubscription> {
Schema::build(Query, EmptyMutation, EmptySubscription)
.data(pool)
.finish()
}
pub fn run_migrations(conn: &mut PooledConnection<ConnectionManager<PgConnection>>) {
conn.run_pending_migrations(MIGRATIONS)
.expect("Failed to run database migrations");
}
pub fn get_conn_from_ctx(ctx: &Context<'_>) -> PooledConnection<ConnectionManager<PgConnection>> {
ctx.data::<PgPool>()
.expect("Can't get pool")
.get()
.expect("Can't get DB connection")
}