diff --git a/lib/registry/src/graphql.rs b/lib/registry/src/graphql.rs index 987093e39de..09ad3e36dbf 100644 --- a/lib/registry/src/graphql.rs +++ b/lib/registry/src/graphql.rs @@ -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() 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..994d408c9d1 --- /dev/null +++ b/lib/registry/src/queries.rs @@ -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;