Skip to content

Commit

Permalink
Put / get now round trips, additional relations to add
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan <[email protected]>
  • Loading branch information
ryan-s-roberts committed Apr 9, 2024
1 parent e58e985 commit 87a160f
Show file tree
Hide file tree
Showing 29 changed files with 3,273 additions and 1,331 deletions.
1,363 changes: 814 additions & 549 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"crates/pallet-chronicle",
"crates/pallet-opa",
"crates/opactl",
"crates/chronicle-data",
"node/runtime-chronicle",
"node/node-chronicle",
"crates/embedded-substrate",
Expand All @@ -28,17 +29,13 @@ members = [
"crates/protocol-substrate-chronicle",
"crates/protocol-substrate-opa",
"crates/chronicle-test-infrastructure",
"crates/chronicle-arrow",
"crates/chronicle-persistence",
"crates/chronicle-data",
]

[workspace.dependencies]
Inflector = "0.11.4"
anyhow = { version = "^1", features = ["backtrace"] }
arrow-array = { versipn = "^0.50" }
arrow-flight = { versipn = "^0.50" }
arrow-ipc = { versipn = "^0.50" }
arrow-schema = { versipn = "^0.50" }
assert_fs = "1.0"
async-graphql = "^7"
async-graphql-poem = "^7"
Expand All @@ -56,7 +53,7 @@ clap_complete = "3.2.3"
clap_generate = "3.0.3"
collecting-hashmap = { version = "0.2" }
colored_json = "^3"
console-subscriber = "0.1"
console-subscriber = "0.2"
const_format = "0.2"
criterion = { version = "0.5.1", features = ["async_futures", "async_tokio"] }
crossbeam = "^0.8"
Expand Down Expand Up @@ -98,8 +95,8 @@ locspan = "0.7"
lru = "0.11"
macro-attr-2018 = "3.0.0"
maplit = "1.0.2"
metrics = "0.21.0"
metrics-exporter-prometheus = "0.12.1"
metrics = "^0.22"
metrics-exporter-prometheus = "^0.14"
mime = "0.3"
mobc = "0.8"
mockito = "1.1"
Expand All @@ -114,7 +111,7 @@ pin-project = "1.0.12"
pin-project-lite = "0.2"
pinvec = "0.1.0"
pkcs8 = { version = "0.10", features = ["std", "alloc"] }
poem = { version = "^2", features = ["opentelemetry", "websocket"] }
poem = { version = "^3", features = ["opentelemetry", "websocket"] }
poem-grpc = { version = "^0.3" }
portpicker = "0.1"
pow_of_2 = "0.1"
Expand Down
85 changes: 44 additions & 41 deletions crates/api/src/chronicle_graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use diesel::{
r2d2::{ConnectionManager, Pool, PooledConnection},
PgConnection, Queryable,
};
use futures::Stream;
use futures::{Future, Stream};
use lazy_static::lazy_static;
use poem::{
get, handler,
Expand Down Expand Up @@ -620,7 +620,6 @@ where
}
}

#[poem::async_trait]
impl<Q, M, S> Endpoint for QueryEndpoint<Q, M, S>
where
Q: ObjectType + 'static,
Expand All @@ -629,16 +628,18 @@ where
{
type Output = poem::Response;

async fn call(&self, req: poem::Request) -> poem::Result<Self::Output> {
let checked_claims = check_claims(&self.secconf, &req).await?;
self.respond(req, |api_req| {
if let Some(claims) = checked_claims {
api_req.0.data(claims)
} else {
api_req.0
}
})
.await
fn call(&self, req: poem::Request) -> impl Future<Output = poem::Result<Self::Output>> {
async move {
let checked_claims = check_claims(&self.secconf, &req).await?;
self.respond(req, |api_req| {
if let Some(claims) = checked_claims {
api_req.0.data(claims)
} else {
api_req.0
}
})
.await
}
}
}

Expand Down Expand Up @@ -673,7 +674,6 @@ where
}
}

#[poem::async_trait]
impl<Q, M, S> Endpoint for SubscriptionEndpoint<Q, M, S>
where
Q: ObjectType + 'static,
Expand All @@ -682,19 +682,21 @@ where
{
type Output = poem::Response;

async fn call(&self, req: poem::Request) -> poem::Result<Self::Output> {
let checked_claims = check_claims(&self.secconf, &req).await?;
self.respond(
req,
if let Some(claims) = checked_claims {
let mut data = async_graphql::Data::default();
data.insert(claims);
data
} else {
async_graphql::Data::default()
},
)
.await
fn call(&self, req: poem::Request) -> impl Future<Output = poem::Result<Self::Output>> {
async move {
let checked_claims = check_claims(&self.secconf, &req).await?;
self.respond(
req,
if let Some(claims) = checked_claims {
let mut data = async_graphql::Data::default();
data.insert(claims);
data
} else {
async_graphql::Data::default()
},
)
.await
}
}
}

Expand Down Expand Up @@ -805,12 +807,12 @@ impl IriEndpoint {
let (req, mut body) = req.split();

let ns_iri: poem::Result<Path<NamespacedIri>> =
FromRequest::from_request(&req, &mut body).await;
poem::web::Path::from_request(&req, &mut body).await;

let ns_iri: NamespacedIri = match ns_iri {
Ok(Path(nsi)) => nsi,
Err(_) => {
let path: Path<Iri> = FromRequest::from_request(&req, &mut body).await?;
let path: Path<Iri> = poem::web::Path::from_request(&req, &mut body).await?;
path.0.into()
},
};
Expand Down Expand Up @@ -852,29 +854,31 @@ impl IriEndpoint {
}
}

#[poem::async_trait]
impl Endpoint for IriEndpoint {
type Output = poem::Response;

async fn call(&self, req: poem::Request) -> poem::Result<Self::Output> {
let checked_claims = if let Some(secconf) = &self.secconf {
check_claims(secconf, &req).await?
} else {
None
};
self.respond(req, checked_claims.as_ref()).await
fn call(&self, req: poem::Request) -> impl Future<Output = poem::Result<Self::Output>> {
async move {
let checked_claims = if let Some(secconf) = &self.secconf {
check_claims(secconf, &req).await?
} else {
None
};
self.respond(req, checked_claims.as_ref()).await
}
}
}

struct LdContextEndpoint;

#[poem::async_trait]
impl Endpoint for LdContextEndpoint {
type Output = poem::Response;

async fn call(&self, _req: poem::Request) -> poem::Result<Self::Output> {
let context: &serde_json::Value = &common::context::PROV;
Ok(IntoResponse::into_response(poem::web::Json(context)))
fn call(&self, _req: poem::Request) -> impl Future<Output = poem::Result<Self::Output>> {
async move {
let context: &serde_json::Value = &common::context::PROV;
Ok(IntoResponse::into_response(poem::web::Json(context)))
}
}
}

Expand Down Expand Up @@ -918,7 +922,6 @@ impl async_graphql::extensions::Extension for AuthFromJwt {
}
}

#[async_trait::async_trait]
impl async_graphql::extensions::ExtensionFactory for AuthFromJwt {
fn create(&self) -> Arc<dyn async_graphql::extensions::Extension> {
Arc::new(AuthFromJwt {
Expand Down
10 changes: 4 additions & 6 deletions crates/api/src/chronicle_graphql/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ async fn transaction_context<'a>(
_ctx: &Context<'a>,
) -> async_graphql::Result<Submission> {
match res {
ApiResponse::Submission { subject, tx_id, .. } => {
Ok(Submission::from_submission(&subject, &tx_id))
},
ApiResponse::AlreadyRecorded { subject, .. } => {
Ok(Submission::from_already_recorded(&subject))
},
ApiResponse::Submission { subject, tx_id, .. } =>
Ok(Submission::from_submission(&subject, &tx_id)),
ApiResponse::AlreadyRecorded { subject, .. } =>
Ok(Submission::from_already_recorded(&subject)),
_ => unreachable!(),
}
}
Expand Down
Loading

0 comments on commit 87a160f

Please sign in to comment.