1
- // PublishPartialSchemaMutation
1
+ use super :: types :: * ;
2
2
use crate :: blocking:: StudioClient ;
3
3
use crate :: query:: config:: is_federated;
4
4
use crate :: RoverClientError ;
@@ -8,38 +8,30 @@ use graphql_client::*;
8
8
// The paths are relative to the directory where your `Cargo.toml` is located.
9
9
// Both json and the GraphQL schema language are supported as sources for the schema
10
10
#[ graphql(
11
- query_path = "src/query/subgraph/publish.graphql" ,
11
+ query_path = "src/query/subgraph/publish/publish_mutation .graphql" ,
12
12
schema_path = ".schema/schema.graphql" ,
13
13
response_derives = "PartialEq, Debug, Serialize, Deserialize" ,
14
14
deprecated = "warn"
15
15
) ]
16
16
/// This struct is used to generate the module containing `Variables` and
17
17
/// `ResponseData` structs.
18
- /// Snake case of this name is the mod name. i.e. publish_partial_schema_mutation
19
- pub struct PublishPartialSchemaMutation ;
20
-
21
- #[ derive( Debug , PartialEq ) ]
22
- pub struct PublishPartialSchemaResponse {
23
- pub schema_hash : Option < String > ,
24
- pub did_update_gateway : bool ,
25
- pub service_was_created : bool ,
26
- pub composition_errors : Option < Vec < String > > ,
27
- }
18
+ /// Snake case of this name is the mod name. i.e. subgraph_publish_mutation
19
+ pub struct SubgraphPublishMutation ;
28
20
29
21
pub fn run (
30
- variables : publish_partial_schema_mutation :: Variables ,
22
+ input : SubgraphPublishInput ,
31
23
client : & StudioClient ,
32
- convert_to_federated_graph : bool ,
33
- ) -> Result < PublishPartialSchemaResponse , RoverClientError > {
34
- let graph = variables . graph_id . clone ( ) ;
24
+ ) -> Result < SubgraphPublishResponse , RoverClientError > {
25
+ let variables : MutationVariables = input . clone ( ) . into ( ) ;
26
+ let graph = input . graph_id . clone ( ) ;
35
27
// We don't want to implicitly convert non-federated graph to supergraphs.
36
28
// Error here if no --convert flag is passed _and_ the current context
37
29
// is non-federated. Add a suggestion to require a --convert flag.
38
- if !convert_to_federated_graph {
30
+ if !input . convert_to_federated_graph {
39
31
let is_federated = is_federated:: run (
40
32
is_federated:: is_federated_graph:: Variables {
41
- graph_id : variables . graph_id . clone ( ) ,
42
- graph_variant : variables . graph_variant . clone ( ) ,
33
+ graph_id : input . graph_id . clone ( ) ,
34
+ graph_variant : input . variant ,
43
35
} ,
44
36
& client,
45
37
) ?;
@@ -51,24 +43,21 @@ pub fn run(
51
43
} ) ;
52
44
}
53
45
}
54
- let data = client. post :: < PublishPartialSchemaMutation > ( variables) ?;
46
+ let data = client. post :: < SubgraphPublishMutation > ( variables) ?;
55
47
let publish_response = get_publish_response_from_data ( data, graph) ?;
56
48
Ok ( build_response ( publish_response) )
57
49
}
58
50
59
- // alias this return type since it's disgusting
60
- type UpdateResponse = publish_partial_schema_mutation:: PublishPartialSchemaMutationServiceUpsertImplementingServiceAndTriggerComposition ;
61
-
62
51
fn get_publish_response_from_data (
63
- data : publish_partial_schema_mutation :: ResponseData ,
52
+ data : ResponseData ,
64
53
graph : String ,
65
54
) -> Result < UpdateResponse , RoverClientError > {
66
55
let service_data = data. service . ok_or ( RoverClientError :: NoService { graph } ) ?;
67
56
68
57
Ok ( service_data. upsert_implementing_service_and_trigger_composition )
69
58
}
70
59
71
- fn build_response ( publish_response : UpdateResponse ) -> PublishPartialSchemaResponse {
60
+ fn build_response ( publish_response : UpdateResponse ) -> SubgraphPublishResponse {
72
61
let composition_errors: Vec < String > = publish_response
73
62
. errors
74
63
. iter ( )
@@ -82,7 +71,7 @@ fn build_response(publish_response: UpdateResponse) -> PublishPartialSchemaRespo
82
71
None
83
72
} ;
84
73
85
- PublishPartialSchemaResponse {
74
+ SubgraphPublishResponse {
86
75
schema_hash : match publish_response. composition_config {
87
76
Some ( config) => Some ( config. schema_hash ) ,
88
77
None => None ,
@@ -114,7 +103,7 @@ mod tests {
114
103
115
104
assert_eq ! (
116
105
output,
117
- PublishPartialSchemaResponse {
106
+ SubgraphPublishResponse {
118
107
schema_hash: Some ( "5gf564" . to_string( ) ) ,
119
108
composition_errors: Some ( vec![
120
109
"[Accounts] User -> composition error" . to_string( ) ,
@@ -139,7 +128,7 @@ mod tests {
139
128
140
129
assert_eq ! (
141
130
output,
142
- PublishPartialSchemaResponse {
131
+ SubgraphPublishResponse {
143
132
schema_hash: Some ( "5gf564" . to_string( ) ) ,
144
133
composition_errors: None ,
145
134
did_update_gateway: true ,
@@ -163,7 +152,7 @@ mod tests {
163
152
164
153
assert_eq ! (
165
154
output,
166
- PublishPartialSchemaResponse {
155
+ SubgraphPublishResponse {
167
156
schema_hash: None ,
168
157
composition_errors: Some (
169
158
vec![ "[Accounts] -> Things went really wrong" . to_string( ) ]
0 commit comments