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

Conversation

ja573
Copy link
Member

@ja573 ja573 commented Sep 27, 2022

Fixes #438

  • thoth-client queries now accept parameters to toggle the inclusion of certain fragments (using limits: limit: 9999 or limit: 0)
  • Queries in thoth-export-server now live in thoth-export-server/src/specification_query.rs and can choose what parameters will be passed onto thoth-client based on the type of specification and wether the specification is being output for a single or multiple works

@ja573
Copy link
Member Author

ja573 commented Sep 28, 2022

Linting will fail until

#![allow(clippy::let_unit_value)]
is merged

@ja573 ja573 marked this pull request as ready for review September 28, 2022 15:47
@ja573 ja573 requested a review from rhigman September 28, 2022 15:47
@ja573
Copy link
Member Author

ja573 commented Sep 29, 2022

Linting will fail until

#![allow(clippy::let_unit_value)]

is merged

Now cherry-picked on 57108eb

type Error = ThothError;

fn try_from(q: QueryConfiguration) -> ThothResult<Self> {
match q.specification {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat, but we risk later updating one of the specifications so that it requires something omitted from the query, and then forgetting to update the corresponding parameters here.

For example, we might decide to add chapter data (where available) to one of the ONIX outputs, and not realise that the without_relations() toggle would mean no chapters were ever fetched. (Updating the unit tests would not catch this.)

It would be safer if we could also add something to the individual specification modules to encode what is/isn't being fetched here, and trigger some kind of error if the developer tried to access unfetched elements. (Optionally also if fetched elements were no longer being used, to keep the queries minimal 🙂 )

Is the actual query logged anywhere? That could help with debugging/give reassurance that the right parameters were being requested. Seemed a bit opaque when I tested it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a fair point. This change basically allows us to keep having a single struct that we can use (thoth_client::Work). The safer option you propose would entail having different queries, with associated structs, so that each specification depended on its particular one. This would indeed be preferred, but would require a major rewrite of both thoth-client and thoth-export-server...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't thinking of going that far - more like adding some list of fetched/unfetched elements in to each of the modules which would break if not updated by hand, as a reminder to update the TryFrom. At the very least, obvious commenting on the use thoth_client:: statements. It's going to be far too easy to unwittingly break behaviour otherwise, with the TryFrom being subtle and separated from the main logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that different from before, the specification modules have always being agnostic to the query. The best option is to make use of the type system, creating separate queries with associated structs for each specification that needs to be different, when we have the time. For the time being, this is currently breaking the distribution of publisher files, so I'm going to merge it

thoth-client/src/parameters.rs Outdated Show resolved Hide resolved
MetadataSpecification::CsvThoth(_) => match q.request {
SpecificationRequest::ByWork => Ok(QueryParameters::new().with_all()),
SpecificationRequest::ByPublisher => {
Ok(QueryParameters::new().with_all().without_relations())
Copy link
Member

@rhigman rhigman Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this always output a "relations" header for which all the cells are empty? To avoid possible confusion, could we output something like [omitted] in these cells (or just remove the header)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. It'd be great to flag it somehow, but this would require writing a separate CSV implementation just to handle it, which seems overkill

@ja573 ja573 merged commit 35bc4c5 into develop Sep 30, 2022
@ja573 ja573 deleted the feature/438_make_output_specific_queries branch September 30, 2022 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants