Skip to content

Commit

Permalink
Merge #3360
Browse files Browse the repository at this point in the history
3360: Introduce a "wasmer_registry::queries" module with all GraphQL queries r=fschutt a=Michael-F-Bryan

This makes all queries used in the `wasmer-registry` crate public. 

See #3355 (comment) for some more context.

Co-authored-by: Michael-F-Bryan <[email protected]>
  • Loading branch information
bors[bot] and Michael-F-Bryan authored Nov 23, 2022
2 parents a22b50a + 2b9f623 commit 2b49d1b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
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;

0 comments on commit 2b49d1b

Please sign in to comment.