-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
rover persisted-queries publish
(#1599)
Co-authored-by: David Glasser <[email protected]>
- Loading branch information
1 parent
373da09
commit f6166d5
Showing
29 changed files
with
760 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/rover-client/src/operations/persisted_queries/describe_pql/describe_pql_query.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# All fields in this query must be accessible by the `PERSISTED_QUERY_PUBLISHER` role | ||
query DescribePersistedQueryListQuery($graphId: ID!, $variant: String!) { | ||
frontendUrlRoot | ||
graph(id: $graphId) { | ||
variant(name: $variant) { | ||
persistedQueryList { | ||
id | ||
} | ||
} | ||
variants { | ||
name | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/rover-client/src/operations/persisted_queries/describe_pql/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod runner; | ||
mod types; | ||
|
||
pub use runner::run; | ||
pub use types::{DescribePQLInput, DescribePQLResponse}; |
58 changes: 58 additions & 0 deletions
58
crates/rover-client/src/operations/persisted_queries/describe_pql/runner.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use super::types::{DescribePQLInput, DescribePQLResponse}; | ||
use crate::blocking::StudioClient; | ||
use crate::shared::GraphRef; | ||
use crate::RoverClientError; | ||
use graphql_client::*; | ||
|
||
#[derive(GraphQLQuery, Debug)] | ||
// The paths are relative to the directory where your `Cargo.toml` is located. | ||
// Both json and the GraphQL schema language are supported as sources for the schema | ||
#[graphql( | ||
query_path = "src/operations/persisted_queries/describe_pql/describe_pql_query.graphql", | ||
schema_path = ".schema/schema.graphql", | ||
response_derives = "Eq, PartialEq, Debug, Serialize, Deserialize", | ||
deprecated = "warn" | ||
)] | ||
pub struct DescribePersistedQueryListQuery; | ||
|
||
pub fn run( | ||
input: DescribePQLInput, | ||
client: &StudioClient, | ||
) -> Result<DescribePQLResponse, RoverClientError> { | ||
let graph_ref = input.graph_ref.clone(); | ||
let data = client.post::<DescribePersistedQueryListQuery>(input.into())?; | ||
build_response(data, graph_ref) | ||
} | ||
|
||
fn build_response( | ||
data: describe_persisted_query_list_query::ResponseData, | ||
graph_ref: GraphRef, | ||
) -> Result<DescribePQLResponse, RoverClientError> { | ||
let graph = data.graph.ok_or(RoverClientError::GraphNotFound { | ||
graph_ref: graph_ref.clone(), | ||
})?; | ||
|
||
let valid_variants = graph | ||
.variants | ||
.iter() | ||
.map(|variant| variant.name.clone()) | ||
.collect(); | ||
|
||
let variant = graph.variant.ok_or(RoverClientError::NoSchemaForVariant { | ||
graph_ref: graph_ref.clone(), | ||
valid_variants, | ||
frontend_url_root: data.frontend_url_root.clone(), | ||
})?; | ||
|
||
if let Some(list) = variant.persisted_query_list { | ||
Ok(DescribePQLResponse { | ||
graph_ref, | ||
id: list.id, | ||
}) | ||
} else { | ||
Err(RoverClientError::NoPersistedQueryList { | ||
graph_ref, | ||
frontend_url_root: data.frontend_url_root, | ||
}) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/rover-client/src/operations/persisted_queries/describe_pql/types.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::operations::persisted_queries::describe_pql::runner::describe_persisted_query_list_query; | ||
use crate::shared::GraphRef; | ||
|
||
type QueryVariables = describe_persisted_query_list_query::Variables; | ||
|
||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub struct DescribePQLInput { | ||
pub graph_ref: GraphRef, | ||
} | ||
|
||
impl From<DescribePQLInput> for QueryVariables { | ||
fn from(input: DescribePQLInput) -> Self { | ||
Self { | ||
graph_id: input.graph_ref.name, | ||
variant: input.graph_ref.variant, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct DescribePQLResponse { | ||
pub graph_ref: GraphRef, | ||
pub id: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod describe_pql; | ||
pub mod publish; |
8 changes: 8 additions & 0 deletions
8
crates/rover-client/src/operations/persisted_queries/publish/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod runner; | ||
mod types; | ||
|
||
pub use runner::run; | ||
pub use types::{ | ||
PersistedQueriesOperationCounts, PersistedQueriesPublishInput, PersistedQueriesPublishResponse, | ||
PersistedQueryManifest, PersistedQueryPublishOperationResult, | ||
}; |
30 changes: 30 additions & 0 deletions
30
crates/rover-client/src/operations/persisted_queries/publish/publish_mutation.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
mutation PublishOperationsMutation($graphId: ID!, $listId: ID!, $operationManifest: [PersistedQueryInput!]) { | ||
graph(id: $graphId) { | ||
persistedQueryList(id: $listId) { | ||
publishOperations(operations: $operationManifest) { | ||
__typename | ||
... on PermissionError { | ||
message | ||
} | ||
... on PublishOperationsResult { | ||
build { | ||
revision | ||
publish { | ||
operationCounts { | ||
added | ||
identical | ||
updated | ||
unaffected | ||
removed | ||
} | ||
} | ||
list { | ||
name | ||
} | ||
} | ||
unchanged | ||
} | ||
} | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
crates/rover-client/src/operations/persisted_queries/publish/runner.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::blocking::StudioClient; | ||
use crate::operations::persisted_queries::publish::{ | ||
PersistedQueriesOperationCounts, PersistedQueriesPublishInput, PersistedQueriesPublishResponse, | ||
PersistedQueryPublishOperationResult, | ||
}; | ||
use crate::RoverClientError; | ||
use graphql_client::*; | ||
|
||
type GraphQLDocument = String; | ||
|
||
#[derive(GraphQLQuery, Debug)] | ||
// The paths are relative to the directory where your `Cargo.toml` is located. | ||
// Both json and the GraphQL schema language are supported as sources for the schema | ||
#[graphql( | ||
query_path = "src/operations/persisted_queries/publish/publish_mutation.graphql", | ||
schema_path = ".schema/schema.graphql", | ||
response_derives = "Eq, PartialEq, Debug, Serialize, Deserialize", | ||
deprecated = "warn" | ||
)] | ||
pub struct PublishOperationsMutation; | ||
|
||
pub fn run( | ||
input: PersistedQueriesPublishInput, | ||
client: &StudioClient, | ||
) -> Result<PersistedQueriesPublishResponse, RoverClientError> { | ||
let graph_id = input.graph_id.clone(); | ||
let list_id = input.list_id.clone(); | ||
let total_operations = input.operation_manifest.operations.len(); | ||
let data = client.post::<PublishOperationsMutation>(input.into())?; | ||
build_response(data, graph_id, list_id, total_operations) | ||
} | ||
|
||
fn build_response( | ||
data: publish_operations_mutation::ResponseData, | ||
graph_id: String, | ||
list_id: String, | ||
total_published_operations: usize, | ||
) -> Result<PersistedQueriesPublishResponse, RoverClientError> { | ||
let graph = data.graph.ok_or(RoverClientError::GraphIdNotFound { | ||
graph_id: graph_id.clone(), | ||
})?; | ||
|
||
match graph.persisted_query_list.publish_operations { | ||
PersistedQueryPublishOperationResult::PermissionError(error) => { | ||
Err(RoverClientError::PermissionError { msg: error.message }) | ||
} | ||
PersistedQueryPublishOperationResult::PublishOperationsResult(result) => { | ||
Ok(PersistedQueriesPublishResponse { | ||
revision: result.build.revision, | ||
graph_id, | ||
list_id, | ||
total_published_operations, | ||
list_name: result.build.list.name, | ||
unchanged: result.unchanged, | ||
operation_counts: PersistedQueriesOperationCounts { | ||
added: result.build.publish.operation_counts.added, | ||
updated: result.build.publish.operation_counts.updated, | ||
removed: result.build.publish.operation_counts.removed, | ||
identical: result.build.publish.operation_counts.identical, | ||
unaffected: result.build.publish.operation_counts.unaffected, | ||
}, | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.