From ea77173a7f253242b83164684f2f766b60205c7e Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 23 Nov 2022 17:24:04 +0800 Subject: [PATCH 1/2] Introduced a "wasmer_registry::queries" module --- lib/registry/src/graphql.rs | 39 ----------------------------- lib/registry/src/lib.rs | 21 ++++++++++------ lib/registry/src/queries.rs | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 lib/registry/src/queries.rs diff --git a/lib/registry/src/graphql.rs b/lib/registry/src/graphql.rs index 987093e39de..69fe297504b 100644 --- a/lib/registry/src/graphql.rs +++ b/lib/registry/src/graphql.rs @@ -106,45 +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 { diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index 72b01a6c301..77f0e0a04dc 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -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") { @@ -301,7 +302,10 @@ pub fn query_command_from_registry( registry_url: &str, command_name: &str, ) -> Result { - 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 { @@ -575,7 +579,10 @@ pub fn query_package_from_registry( name: &str, version: Option<&str>, ) -> Result { - 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 { @@ -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)] @@ -940,7 +947,7 @@ pub fn whoami( } pub fn test_if_registry_present(registry: &str) -> Result { - 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 {}); @@ -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, } @@ -1325,7 +1332,7 @@ pub fn list_bindings( name: &str, version: Option<&str>, ) -> Result, anyhow::Error> { - use crate::graphql::{ + use crate::queries::{ get_bindings_query::{ResponseData, Variables}, GetBindingsQuery, }; diff --git a/lib/registry/src/queries.rs b/lib/registry/src/queries.rs new file mode 100644 index 00000000000..ea9ced3e8f1 --- /dev/null +++ b/lib/registry/src/queries.rs @@ -0,0 +1,50 @@ +//! The GraphQL queries used by this crate. +//! +//! This module can be useful if you want to query the WAPM backend directly +//! because the crate's high-level functions don't provide the exact +//! operations/data you need. + +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; From 2b9f62347f41321b2d1d2a2acf3287b52e506460 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Wed, 23 Nov 2022 18:09:58 +0800 Subject: [PATCH 2/2] Update the wasmer_registry::queries docs to mention backwards compatibility and its low level nature --- lib/registry/src/graphql.rs | 1 - lib/registry/src/queries.rs | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/registry/src/graphql.rs b/lib/registry/src/graphql.rs index 69fe297504b..09ad3e36dbf 100644 --- a/lib/registry/src/graphql.rs +++ b/lib/registry/src/graphql.rs @@ -106,7 +106,6 @@ pub(crate) mod proxy { } } - #[cfg(target_os = "wasi")] pub fn whoami_distro() -> String { whoami::os().to_lowercase() diff --git a/lib/registry/src/queries.rs b/lib/registry/src/queries.rs index ea9ced3e8f1..994d408c9d1 100644 --- a/lib/registry/src/queries.rs +++ b/lib/registry/src/queries.rs @@ -1,8 +1,20 @@ -//! The GraphQL queries used by this crate. +//! Low-level GraphQL queries used by this crate. //! -//! This module can be useful if you want to query the WAPM backend directly -//! because the crate's high-level functions don't provide the exact -//! operations/data you need. +//! 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::*;