Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: #77 Error Refactoring #78

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.18.0]

### Changed

- `nakago`: Errors were split into 3 - one for Injection, one for Providers, and one for Hooks.
- `nakago-derive`: Updated to use the updated error type for Providers.

## [0.17.0]

This is a big release! It includes updates from `http` to v1.0, `hyper` to v1.0, and `axum` to v0.7. It refactors the test utils to use `reqwest` instead of the minimal hyper Client that is changing in v1.0. There are a number of small behind-the-scenes changes to support these new versions, and Nakago is currently relying on a few temporary forks as the community catches up to the big releases in recent weeks.
Expand Down Expand Up @@ -300,6 +307,7 @@ Expect major changes to the Application and Lifecycle systems going forward, bui
- Injection Providers
- Documentation

[0.18.0]: https://github.com/bkonkle/nakago/compare/0.17.0...0.18.0
[0.17.0]: https://github.com/bkonkle/nakago/compare/0.16.0...0.17.0
[0.16.0]: https://github.com/bkonkle/nakago/compare/0.15.0...0.16.0
[0.15.0]: https://github.com/bkonkle/nakago/compare/0.14.1...0.15.0
Expand Down
10 changes: 5 additions & 5 deletions examples/async-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ figment = { version = "0.10", features = ["env", "toml", "yaml", "json"] }
futures = "0.3"
hyper = "1.0"
log = "0.4"
nakago = "0.17"
nakago-axum = "0.17"
nakago-derive = "0.8"
nakago-sea-orm = "0.17"
nakago-async-graphql = "0.17"
nakago = "0.18"
nakago-axum = "0.18"
nakago-derive = "0.18"
nakago-sea-orm = "0.18"
nakago-async-graphql = "0.18"
oso = "0.27"
pico-args = "0.5.0"
pretty_env_logger = "0.5"
Expand Down
6 changes: 3 additions & 3 deletions examples/async-graphql/src/authz.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use async_trait::async_trait;
use nakago::{inject, to_provider_error, Hook, Inject, Provider, Tag};
use nakago::{hooks, provider, to_provider_error, Hook, Inject, Provider, Tag};
use nakago_derive::Provider;
use oso::Oso;
use oso::PolarClass;
Expand All @@ -25,7 +25,7 @@ pub struct ProvideOso {}
#[Provider]
#[async_trait]
impl Provider<Oso> for ProvideOso {
async fn provide(self: Arc<Self>, _i: Inject) -> inject::Result<Arc<Oso>> {
async fn provide(self: Arc<Self>, _i: Inject) -> provider::Result<Arc<Oso>> {
Ok(Arc::new(Oso::new()))
}
}
Expand All @@ -39,7 +39,7 @@ pub struct Load {}

#[async_trait]
impl Hook for Load {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
// Set up authorization
let oso = i.get(&OSO).await?;
let mut oso = (*oso).clone();
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/episodes/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_graphql::{
};
use async_trait::async_trait;
use derive_new::new;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_derive::Provider;

use super::{
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<DataLoader<Loader>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<DataLoader<Loader>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<DataLoader<Loader>>> {
let episodes_service = i.get(&SERVICE).await?;

Ok(Arc::new(DataLoader::new(
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/episodes/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_trait::async_trait;
use derive_new::new;
use fake::{Dummy, Fake, Faker};
use hyper::StatusCode;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_async_graphql::utils::{as_graphql_error, dummy_maybe_undef, graphql_error};
use nakago_derive::Provider;
use oso::Oso;
Expand Down Expand Up @@ -243,7 +243,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<EpisodesMutation> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<EpisodesMutation>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<EpisodesMutation>> {
let service = i.get(&SERVICE).await?;
let shows = i.get(&shows::SERVICE).await?;

Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/episodes/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_graphql::{Context, Enum, InputObject, Object, Result, SimpleObject};
use async_trait::async_trait;
use derive_new::new;
use hyper::StatusCode;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_async_graphql::utils::as_graphql_error;
use nakago_axum::utils::{
ManyResponse,
Expand Down Expand Up @@ -170,7 +170,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<EpisodesQuery> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<EpisodesQuery>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<EpisodesQuery>> {
let service = i.get(&SERVICE).await?;

Ok(Arc::new(EpisodesQuery::new(service)))
Expand Down
10 changes: 5 additions & 5 deletions examples/async-graphql/src/domains/episodes/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use nakago::{inject, Hook, Inject};
use nakago::{hooks, Hook, Inject};

use crate::domains::graphql;

Expand All @@ -16,7 +16,7 @@ pub struct Load {}

#[async_trait]
impl Hook for Load {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
i.provide(&SERVICE, service::Provide::default()).await?;
i.provide(&LOADER, loaders::Provide::default()).await?;
i.provide(&QUERY, query::Provide::default()).await?;
Expand All @@ -32,7 +32,7 @@ pub struct Init {}

#[async_trait]
impl Hook for Init {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
let loader = i.get(&LOADER).await?;

i.modify(&graphql::SCHEMA_BUILDER, |builder| Ok(builder.data(loader)))
Expand All @@ -47,7 +47,7 @@ pub(crate) mod test {
use std::sync::Arc;

use async_graphql::{self, dataloader::DataLoader, EmptySubscription};
use nakago::{Provider, Tag};
use nakago::{provider, Provider, Tag};
use nakago_derive::Provider;

use crate::domains::{
Expand Down Expand Up @@ -77,7 +77,7 @@ pub(crate) mod test {
#[Provider]
#[async_trait]
impl Provider<Schema> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<Schema>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Schema>> {
let service = i.get(&SERVICE).await?;
let shows = i.get(&shows::SERVICE).await?;
let show_loader = i.get(&shows::LOADER).await?;
Expand Down
6 changes: 3 additions & 3 deletions examples/async-graphql/src/domains/episodes/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_trait::async_trait;
use derive_new::new;
#[cfg(test)]
use mockall::automock;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_axum::utils::{ManyResponse, Ordering};
use nakago_derive::Provider;
use nakago_sea_orm::{DatabaseConnection, CONNECTION};
Expand Down Expand Up @@ -285,7 +285,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<Box<dyn Service>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<Box<dyn Service>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Box<dyn Service>>> {
let db = i.get(&CONNECTION).await?;

Ok(Arc::new(Box::new(DefaultService::new(db))))
Expand All @@ -305,7 +305,7 @@ pub(crate) mod test {
#[Provider]
#[async_trait]
impl Provider<Box<dyn Service>> for ProvideMock {
async fn provide(self: Arc<Self>, _i: Inject) -> inject::Result<Arc<Box<dyn Service>>> {
async fn provide(self: Arc<Self>, _i: Inject) -> provider::Result<Arc<Box<dyn Service>>> {
Ok(Arc::new(Box::<MockService>::default()))
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/async-graphql/src/domains/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::{self, EmptySubscription, MergedObject};
use async_trait::async_trait;
use nakago::{inject, Hook, Inject, Tag};
use nakago::{hooks, Hook, Inject, Tag};
use nakago_async_graphql::schema;

use crate::{authz::OSO, config::CONFIG};
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct Load {}

#[async_trait]
impl Hook for Load {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
i.handle(users::schema::Load::default()).await?;
i.handle(profiles::schema::Load::default()).await?;
i.handle(role_grants::schema::Load::default()).await?;
Expand All @@ -55,7 +55,7 @@ pub struct Init {}

#[async_trait]
impl Hook for Init {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
let config = i.get(&CONFIG).await?;
let oso = i.get(&OSO).await?;

Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/profiles/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_graphql::{
};
use async_trait::async_trait;
use derive_new::new;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_derive::Provider;

use super::{
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<DataLoader<Loader>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<DataLoader<Loader>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<DataLoader<Loader>>> {
let service = i.get(&SERVICE).await?;

Ok(Arc::new(DataLoader::new(
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/profiles/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use async_trait::async_trait;
use derive_new::new;
use fake::{faker::internet::en::FreeEmail, Dummy, Fake, Faker};
use hyper::StatusCode;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_async_graphql::utils::{as_graphql_error, dummy_maybe_undef, graphql_error};
use nakago_derive::Provider;
use rand::Rng;
Expand Down Expand Up @@ -249,7 +249,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<ProfilesMutation> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<ProfilesMutation>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<ProfilesMutation>> {
let service = i.get(&SERVICE).await?;

Ok(Arc::new(ProfilesMutation::new(service)))
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/profiles/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_graphql::{Context, Enum, InputObject, Object, Result, SimpleObject};
use async_trait::async_trait;
use derive_new::new;
use hyper::StatusCode;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_async_graphql::utils::as_graphql_error;
use nakago_axum::utils::{
ManyResponse,
Expand Down Expand Up @@ -200,7 +200,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<ProfilesQuery> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<ProfilesQuery>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<ProfilesQuery>> {
let service = i.get(&SERVICE).await?;

Ok(Arc::new(ProfilesQuery::new(service)))
Expand Down
10 changes: 5 additions & 5 deletions examples/async-graphql/src/domains/profiles/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use nakago::{inject, Hook, Inject};
use nakago::{hooks, Hook, Inject};

use crate::domains::graphql;

Expand All @@ -16,7 +16,7 @@ pub struct Load {}

#[async_trait]
impl Hook for Load {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
i.provide(&SERVICE, service::Provide::default()).await?;
i.provide(&LOADER, loaders::Provide::default()).await?;
i.provide(&QUERY, query::Provide::default()).await?;
Expand All @@ -32,7 +32,7 @@ pub struct Init {}

#[async_trait]
impl Hook for Init {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
let loader = i.get(&LOADER).await?;

i.modify(&graphql::SCHEMA_BUILDER, |builder| {
Expand All @@ -49,7 +49,7 @@ pub(crate) mod test {
use std::sync::Arc;

use async_graphql::{self, dataloader::DataLoader, EmptySubscription};
use nakago::{Provider, Tag};
use nakago::{provider, Provider, Tag};

use crate::domains::{
profiles::{Mutation, Query},
Expand Down Expand Up @@ -77,7 +77,7 @@ pub(crate) mod test {

#[async_trait]
impl Provider<Schema> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<Schema>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Schema>> {
let service = i.get(&SERVICE).await?;
let user_loader = i.get(&users::LOADER).await?;

Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/profiles/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_trait::async_trait;
use derive_new::new;
#[cfg(test)]
use mockall::automock;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_axum::utils::{ManyResponse, Ordering};
use nakago_derive::Provider;
use nakago_sea_orm::{DatabaseConnection, CONNECTION};
Expand Down Expand Up @@ -355,7 +355,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<Box<dyn Service>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<Box<dyn Service>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Box<dyn Service>>> {
let db = i.get(&CONNECTION).await?;

Ok(Arc::new(Box::new(DefaultService::new(db))))
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/role_grants/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use async_graphql::{
};
use async_trait::async_trait;
use derive_new::new;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_derive::Provider;

use super::{
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<DataLoader<Loader>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<DataLoader<Loader>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<DataLoader<Loader>>> {
let service = i.get(&SERVICE).await?;

Ok(Arc::new(DataLoader::new(
Expand Down
6 changes: 3 additions & 3 deletions examples/async-graphql/src/domains/role_grants/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use nakago::{inject, Hook, Inject};
use nakago::{hooks, Hook, Inject};

use crate::domains::graphql;

Expand All @@ -14,7 +14,7 @@ pub struct Load {}

#[async_trait]
impl Hook for Load {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
i.provide(&SERVICE, service::Provide::default()).await?;
i.provide(&LOADER, loaders::Provide::default()).await?;

Expand All @@ -28,7 +28,7 @@ pub struct Init {}

#[async_trait]
impl Hook for Init {
async fn handle(&self, i: Inject) -> inject::Result<()> {
async fn handle(&self, i: Inject) -> hooks::Result<()> {
let loader = i.get(&LOADER).await?;

i.modify(&graphql::SCHEMA_BUILDER, |builder| {
Expand Down
4 changes: 2 additions & 2 deletions examples/async-graphql/src/domains/role_grants/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use derive_new::new;
#[cfg(test)]
use mockall::automock;
use nakago::{inject, Inject, Provider, Tag};
use nakago::{provider, Inject, Provider, Tag};
use nakago_derive::Provider;
use nakago_sea_orm::{DatabaseConnection, CONNECTION};
use sea_orm::{entity::*, query::*, Condition, EntityTrait};
Expand Down Expand Up @@ -104,7 +104,7 @@ pub struct Provide {}
#[Provider]
#[async_trait]
impl Provider<Box<dyn Service>> for Provide {
async fn provide(self: Arc<Self>, i: Inject) -> inject::Result<Arc<Box<dyn Service>>> {
async fn provide(self: Arc<Self>, i: Inject) -> provider::Result<Arc<Box<dyn Service>>> {
let db = i.get(&CONNECTION).await?;

Ok(Arc::new(Box::new(DefaultService::new(db))))
Expand Down
Loading
Loading