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

Load DocumentId to be able to resolve it in meta field query #258

Merged
merged 2 commits into from
Sep 3, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Resolve implicit `__typename` field on dynamically generated GraphQL objects [#236](https://github.com/p2panda/aquadoggo/pull/236)
- Allow `Content-Type` header [#236](https://github.com/p2panda/aquadoggo/pull/236)
- Do not forget to register `DocumentIdScalar` [#252](https://github.com/p2panda/aquadoggo/pull/252)
- Load `DocumentId` to be able to resolve it in meta field query [#258](https://github.com/p2panda/aquadoggo/pull/258)

## [0.3.0]

Expand Down
12 changes: 10 additions & 2 deletions aquadoggo/src/graphql/client/dynamic_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use log::{debug, error, info};
use p2panda_rs::document::{DocumentId, DocumentView, DocumentViewId};
use p2panda_rs::operation::OperationValue;
use p2panda_rs::schema::SchemaId;
use p2panda_rs::storage_provider::traits::DocumentStore;
use p2panda_rs::storage_provider::traits::{DocumentStore, OperationStore};
use p2panda_rs::Human;

use crate::db::provider::SqlStorage;
Expand Down Expand Up @@ -53,6 +53,7 @@ impl ContainerType for DynamicQuery {
}
}
}

// Continue by trying to parse it as a schema and, if that's successful, checking whether
// this schema is available in the schema provider. If both are successfull, continue by
// resolving this query as a query for a single document.
Expand Down Expand Up @@ -143,6 +144,7 @@ impl DynamicQuery {
let selected_fields = ctx.field().selection_set().collect();
self.document_response(view, ctx, selected_fields).await
});

Ok(Some(Value::List(
future::try_join_all(documents_graphql_values).await?,
)))
Expand Down Expand Up @@ -256,9 +258,15 @@ impl DynamicQuery {
document_fields.insert(response_key, Value::String(schema_id));
}
dynamic_types::document::META_FIELD => {
let store = ctx.data_unchecked::<SqlStorage>();
let document_id = store
.get_document_by_operation_id(view.id().graph_tips().first().unwrap())
.await
.map_err(|err| ServerError::new(err.to_string(), None))?
.unwrap();
document_fields.insert(
response_key,
DocumentMeta::resolve(field, None, Some(view.id()))?,
DocumentMeta::resolve(field, Some(&document_id), Some(view.id()))?,
);
}
dynamic_types::document::FIELDS_FIELD => {
Expand Down
8 changes: 5 additions & 3 deletions aquadoggo/src/graphql/client/dynamic_types/document_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ impl DocumentMeta {

/// Generate an object type for generic metadata and register it in a GraphQL schema registry.
pub fn register_type(registry: &mut async_graphql::registry::Registry) {
// Important!
//
// Manually register scalar type in registry because it's not used in the static api.
DocumentIdScalar::create_type_info(registry);

let mut fields = IndexMap::new();

fields.insert(
Expand All @@ -36,9 +41,6 @@ impl DocumentMeta {
),
);

// Manually register scalar type in registry because it's not used in the static api.
DocumentIdScalar::create_type_info(registry);

fields.insert(
VIEW_ID_FIELD.to_string(),
metafield(
Expand Down