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

Use directives in graphql client #440

Merged
merged 30 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1b181d5
Use directives in graphql client
ja573 Sep 27, 2022
1cebcbd
Break long lines
ja573 Sep 27, 2022
346db80
Replace directives with limits
ja573 Sep 28, 2022
2ae9fdb
Abstract query parameters
ja573 Sep 28, 2022
d1b1ab6
Abstract query parameters
ja573 Sep 28, 2022
f0e2a7d
Use builder pattern for parameters
ja573 Sep 28, 2022
6abd2ba
Test query variables conversion
ja573 Sep 28, 2022
eb74786
Derive debug and partialeq on tests
ja573 Sep 28, 2022
488e510
Parse query parameters based on specification
ja573 Sep 28, 2022
c0b482f
Allow testing variables
ja573 Sep 28, 2022
6bf59f5
Move error to query
ja573 Sep 28, 2022
179c9ee
Move queries to specification module
ja573 Sep 28, 2022
fb97cb7
Move queries to specification module
ja573 Sep 28, 2022
180fc3d
Abstract query
ja573 Sep 28, 2022
17a5958
Remove relations from csv::thoth on publisher query
ja573 Sep 28, 2022
f2cdc79
Choose paramters for bibtex::thoth
ja573 Sep 28, 2022
71f40a7
Fix typo
ja573 Sep 28, 2022
11b7097
Choose parameters for doideposit::crossref
ja573 Sep 28, 2022
139cd59
Choose parameters for kbart::oclc
ja573 Sep 28, 2022
25fbb29
Choose parameters for onix specifications
ja573 Sep 28, 2022
3332c06
Fix typo
ja573 Sep 28, 2022
85849db
Fix typo
ja573 Sep 28, 2022
8b0bb3f
Do not use allocation on constants
ja573 Sep 28, 2022
e2eebc8
Do not use allocation on constants
ja573 Sep 28, 2022
25aab69
Remove moved value
ja573 Sep 28, 2022
cb97162
Fix doc test
ja573 Sep 29, 2022
702be5a
Remove redundant clone
ja573 Sep 29, 2022
b7b4817
Update changelog
ja573 Sep 29, 2022
57108eb
Ignore false positive warning
ja573 Sep 22, 2022
58e0f3f
Use constants in filter values
ja573 Sep 29, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- [#438](https://github.com/thoth-pub/thoth/issues/438) - Allow specifying query parameters based on the requested specification

## [[0.8.9]](https://github.com/thoth-pub/thoth/releases/tag/v0.8.9) - 2022-09-21
### Added
Expand Down
2 changes: 2 additions & 0 deletions thoth-app/src/component/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::let_unit_value)]

#[macro_export]
macro_rules! pagination_helpers {
($component:ident, $pagination_text:ident, $search_text:ident) => {
Expand Down
34 changes: 25 additions & 9 deletions thoth-client/assets/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fragment Work on Work {
publisherUrl
}
}
issues {
issues(limit: $issuesLimit) {
issueOrdinal
series {
seriesType
Expand Down Expand Up @@ -67,12 +67,12 @@ fragment Work on Work {
}
}
}
languages {
languages(limit: $languagesLimit) {
languageCode
languageRelation
mainLanguage
}
publications {
publications(limit: $publicationsLimit) {
publicationId
publicationType
isbn
Expand All @@ -98,12 +98,12 @@ fragment Work on Work {
canonical
}
}
subjects {
subjects(limit: $subjectsLimit) {
subjectCode
subjectType
subjectOrdinal
}
fundings {
fundings(limit: $fundingsLimit) {
program
projectName
projectShortname
Expand All @@ -116,7 +116,7 @@ fragment Work on Work {
countryCode
}
}
relations {
relations(limit: $relationsLimit) {
relationType
relationOrdinal
relatedWork {
Expand Down Expand Up @@ -157,13 +157,29 @@ fragment Work on Work {
}
}

query WorkQuery($workId: Uuid!) {
query WorkQuery(
$workId: Uuid!,
$issuesLimit: Int!,
$languagesLimit: Int!,
$publicationsLimit: Int!,
$subjectsLimit: Int!,
$fundingsLimit: Int!,
$relationsLimit: Int!
) {
work(workId: $workId) {
...Work
}
}
query WorksQuery($publishers: [Uuid!]) {
query WorksQuery(
$publishers: [Uuid!],
$issuesLimit: Int!,
$languagesLimit: Int!,
$publicationsLimit: Int!,
$subjectsLimit: Int!,
$fundingsLimit: Int!,
$relationsLimit: Int!
) {
works(limit: 99999, publishers: $publishers) {
...Work
}
}
}
26 changes: 18 additions & 8 deletions thoth-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod parameters;
// GraphQLQuery derive macro breaks this linting rule - ignore while awaiting fix
#[allow(clippy::derive_partial_eq_without_eq)]
mod queries;
Expand All @@ -9,6 +10,8 @@ use std::future::Future;
use thoth_errors::{ThothError, ThothResult};
use uuid::Uuid;

pub use crate::parameters::QueryParameters;
use crate::parameters::{WorkQueryVariables, WorksQueryVariables};
pub use crate::queries::work_query::*;
use crate::queries::{work_query, works_query, WorkQuery, WorksQuery};

Expand Down Expand Up @@ -50,18 +53,19 @@ impl ThothClient {
///
/// ```no_run
/// # use thoth_errors::ThothResult;
/// # use thoth_client::{ThothClient, Work};
/// # use thoth_client::{QueryParameters, ThothClient, Work};
/// # use uuid::Uuid;
///
/// # async fn run() -> ThothResult<Work> {
/// let thoth_client = ThothClient::new("https://api.thoth.pub/graphql".to_string());
/// let work_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?;
/// let work = thoth_client.get_work(work_id).await?;
/// let work = thoth_client.get_work(work_id, QueryParameters::new()).await?;
/// # Ok(work)
/// # }
/// ```
pub async fn get_work(&self, work_id: Uuid) -> ThothResult<Work> {
let request_body = WorkQuery::build_query(work_query::Variables { work_id });
pub async fn get_work(&self, work_id: Uuid, parameters: QueryParameters) -> ThothResult<Work> {
let variables: work_query::Variables = WorkQueryVariables::new(work_id, parameters).into();
let request_body = WorkQuery::build_query(variables);
let res = self.post_request(&request_body).await.await?;
let response_body: Response<work_query::ResponseData> = res.json().await?;
match response_body.data {
Expand All @@ -80,18 +84,24 @@ impl ThothClient {
///
/// ```no_run
/// # use thoth_errors::ThothResult;
/// # use thoth_client::{ThothClient, Work};
/// # use thoth_client::{QueryParameters, ThothClient, Work};
/// # use uuid::Uuid;
///
/// # async fn run() -> ThothResult<Vec<Work>> {
/// let thoth_client = ThothClient::new("https://api.thoth.pub/graphql".to_string());
/// let publisher_id = Uuid::parse_str("00000000-0000-0000-AAAA-000000000001")?;
/// let works = thoth_client.get_works(Some(vec![publisher_id])).await?;
/// let works = thoth_client.get_works(Some(vec![publisher_id]), QueryParameters::new()).await?;
/// # Ok(works)
/// # }
/// ```
pub async fn get_works(&self, publishers: Option<Vec<Uuid>>) -> ThothResult<Vec<Work>> {
let request_body = WorksQuery::build_query(works_query::Variables { publishers });
pub async fn get_works(
&self,
publishers: Option<Vec<Uuid>>,
parameters: QueryParameters,
) -> ThothResult<Vec<Work>> {
let variables: works_query::Variables =
WorksQueryVariables::new(publishers, parameters).into();
let request_body = WorksQuery::build_query(variables);
let res = self.post_request(&request_body).await.await?;
let response_body: Response<works_query::ResponseData> = res.json().await?;
match response_body.data {
Expand Down
Loading