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

Introduce a "wasmer_registry::queries" module with all GraphQL queries #3360

Merged
merged 2 commits into from
Nov 23, 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
40 changes: 0 additions & 40 deletions lib/registry/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,46 +106,6 @@ pub(crate) mod proxy {
}
}

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_package_version.graphql",
response_derives = "Debug"
)]
pub(crate) struct GetPackageVersionQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/whoami.graphql",
response_derives = "Debug"
)]
pub(crate) struct WhoAmIQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_package_by_command.graphql",
response_derives = "Debug"
)]
pub(crate) struct GetPackageByCommandQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/test_if_registry_present.graphql",
response_derives = "Debug"
)]
pub(crate) struct TestIfRegistryPresent;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_bindings.graphql",
response_derives = "Debug,Clone,PartialEq,Eq"
)]
pub(crate) struct GetBindingsQuery;

#[cfg(target_os = "wasi")]
pub fn whoami_distro() -> String {
whoami::os().to_lowercase()
Expand Down
21 changes: 14 additions & 7 deletions lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ use url::Url;
pub mod config;
pub mod graphql;
pub mod login;
pub mod queries;
pub mod utils;

pub use crate::{
config::{format_graphql, PartialWapmConfig},
graphql::get_bindings_query::ProgrammingLanguage,
queries::get_bindings_query::ProgrammingLanguage,
};

pub static GLOBAL_CONFIG_FILE_NAME: &str = if cfg!(target_os = "wasi") {
Expand Down Expand Up @@ -301,7 +302,10 @@ pub fn query_command_from_registry(
registry_url: &str,
command_name: &str,
) -> Result<PackageDownloadInfo, String> {
use crate::graphql::{execute_query, get_package_by_command_query, GetPackageByCommandQuery};
use crate::{
graphql::execute_query,
queries::{get_package_by_command_query, GetPackageByCommandQuery},
};
use graphql_client::GraphQLQuery;

let q = GetPackageByCommandQuery::build_query(get_package_by_command_query::Variables {
Expand Down Expand Up @@ -575,7 +579,10 @@ pub fn query_package_from_registry(
name: &str,
version: Option<&str>,
) -> Result<PackageDownloadInfo, QueryPackageError> {
use crate::graphql::{execute_query, get_package_version_query, GetPackageVersionQuery};
use crate::{
graphql::execute_query,
queries::{get_package_version_query, GetPackageVersionQuery},
};
use graphql_client::GraphQLQuery;

let q = GetPackageVersionQuery::build_query(get_package_version_query::Variables {
Expand Down Expand Up @@ -902,7 +909,7 @@ pub fn whoami(
#[cfg(test)] test_name: &str,
registry: Option<&str>,
) -> Result<(String, String), anyhow::Error> {
use crate::graphql::{who_am_i_query, WhoAmIQuery};
use crate::queries::{who_am_i_query, WhoAmIQuery};
use graphql_client::GraphQLQuery;

#[cfg(test)]
Expand Down Expand Up @@ -940,7 +947,7 @@ pub fn whoami(
}

pub fn test_if_registry_present(registry: &str) -> Result<bool, String> {
use crate::graphql::{test_if_registry_present, TestIfRegistryPresent};
use crate::queries::{test_if_registry_present, TestIfRegistryPresent};
use graphql_client::GraphQLQuery;

let q = TestIfRegistryPresent::build_query(test_if_registry_present::Variables {});
Expand Down Expand Up @@ -1283,7 +1290,7 @@ pub struct Bindings {
/// (typically as a `*.tar.gz` file).
pub url: String,
/// The programming language these bindings are written in.
pub language: graphql::get_bindings_query::ProgrammingLanguage,
pub language: ProgrammingLanguage,
/// The generator used to generate these bindings.
pub generator: BindingsGenerator,
}
Expand Down Expand Up @@ -1325,7 +1332,7 @@ pub fn list_bindings(
name: &str,
version: Option<&str>,
) -> Result<Vec<Bindings>, anyhow::Error> {
use crate::graphql::{
use crate::queries::{
get_bindings_query::{ResponseData, Variables},
GetBindingsQuery,
};
Expand Down
62 changes: 62 additions & 0 deletions lib/registry/src/queries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Low-level GraphQL queries used by this crate.
//!
//! If possible, users should prefer the high-level functions exposed under
//! [`crate`].
//!
//! This module is primarily used in combination with
//! [`crate::graphql::execute_query()`] as an "escape hatch" for accessing
//! information that may not be exposed via the high-level functions.
//!
//! # Backwards Compatibility
//!
//! Queries won't be deleted or have breaking changes to their inputs during
//! patch releases, however new fields may be added to the response types
//! generated by `graphql_client` at any time.
//!
//! Users should treat all response types as if they had the `#[non_exhaustive]`
//! attribute.

use graphql_client::*;

/// The GraphQL schema exposed by the WAPM backend.
pub const SCHEMA: &str = include_str!("../graphql/schema.graphql");

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_package_version.graphql",
response_derives = "Debug"
)]
pub struct GetPackageVersionQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/whoami.graphql",
response_derives = "Debug"
)]
pub struct WhoAmIQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_package_by_command.graphql",
response_derives = "Debug"
)]
pub struct GetPackageByCommandQuery;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/test_if_registry_present.graphql",
response_derives = "Debug"
)]
pub struct TestIfRegistryPresent;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "graphql/schema.graphql",
query_path = "graphql/queries/get_bindings.graphql",
response_derives = "Debug,Clone,PartialEq,Eq"
)]
pub struct GetBindingsQuery;