1
1
use crate :: blocking:: StudioClient ;
2
+ use crate :: query:: config:: who_am_i:: {
3
+ types:: { QueryActorType , QueryResponseData , RegistryIdentity } ,
4
+ Actor , ConfigWhoAmIInput ,
5
+ } ;
2
6
use crate :: RoverClientError ;
7
+
3
8
use houston:: CredentialOrigin ;
4
9
5
10
use graphql_client:: * ;
@@ -8,43 +13,28 @@ use graphql_client::*;
8
13
// The paths are relative to the directory where your `Cargo.toml` is located.
9
14
// Both json and the GraphQL schema language are supported as sources for the schema
10
15
#[ graphql(
11
- query_path = "src/query/config/whoami .graphql" ,
16
+ query_path = "src/query/config/who_am_i/who_am_i_query .graphql" ,
12
17
schema_path = ".schema/schema.graphql" ,
13
18
response_derives = "PartialEq, Debug, Serialize, Deserialize" ,
14
19
deprecated = "warn"
15
20
) ]
16
21
/// This struct is used to generate the module containing `Variables` and
17
22
/// `ResponseData` structs.
18
- /// Snake case of this name is the mod name. i.e. who_am_i_query
19
- pub struct WhoAmIQuery ;
20
-
21
- #[ derive( Debug , PartialEq ) ]
22
- pub struct RegistryIdentity {
23
- pub id : String ,
24
- pub graph_title : Option < String > ,
25
- pub key_actor_type : Actor ,
26
- pub credential_origin : CredentialOrigin ,
27
- }
28
-
29
- #[ derive( Debug , PartialEq ) ]
30
- pub enum Actor {
31
- GRAPH ,
32
- USER ,
33
- OTHER ,
34
- }
23
+ /// Snake case of this name is the mod name. i.e. config_who_am_i_query
24
+ pub struct ConfigWhoAmIQuery ;
35
25
36
26
/// Get info from the registry about an API key, i.e. the name/id of the
37
27
/// user/graph and what kind of key it is (GRAPH/USER/Other)
38
28
pub fn run (
39
- variables : who_am_i_query :: Variables ,
29
+ input : ConfigWhoAmIInput ,
40
30
client : & StudioClient ,
41
31
) -> Result < RegistryIdentity , RoverClientError > {
42
- let response_data = client. post :: < WhoAmIQuery > ( variables ) ?;
43
- get_identity_from_response_data ( response_data, client. credential . origin . clone ( ) )
32
+ let response_data = client. post :: < ConfigWhoAmIQuery > ( input . into ( ) ) ?;
33
+ get_identity_from_response_data ( response_data, client. get_credential_origin ( ) )
44
34
}
45
35
46
36
fn get_identity_from_response_data (
47
- response_data : who_am_i_query :: ResponseData ,
37
+ response_data : QueryResponseData ,
48
38
credential_origin : CredentialOrigin ,
49
39
) -> Result < RegistryIdentity , RoverClientError > {
50
40
if let Some ( me) = response_data. me {
@@ -54,13 +44,13 @@ fn get_identity_from_response_data(
54
44
// more here: https://studio-staging.apollographql.com/graph/engine/schema/reference/enums/ActorType?variant=prod
55
45
56
46
let key_actor_type = match me. as_actor . type_ {
57
- who_am_i_query :: ActorType :: GRAPH => Actor :: GRAPH ,
58
- who_am_i_query :: ActorType :: USER => Actor :: USER ,
47
+ QueryActorType :: GRAPH => Actor :: GRAPH ,
48
+ QueryActorType :: USER => Actor :: USER ,
59
49
_ => Actor :: OTHER ,
60
50
} ;
61
51
62
52
let graph_title = match me. on {
63
- who_am_i_query :: WhoAmIQueryMeOn :: Service ( s) => Some ( s. title ) ,
53
+ config_who_am_i_query :: ConfigWhoAmIQueryMeOn :: Service ( s) => Some ( s. title ) ,
64
54
_ => None ,
65
55
} ;
66
56
@@ -91,7 +81,8 @@ mod tests {
91
81
} ,
92
82
}
93
83
} ) ;
94
- let data: who_am_i_query:: ResponseData = serde_json:: from_value ( json_response) . unwrap ( ) ;
84
+ let data: config_who_am_i_query:: ResponseData =
85
+ serde_json:: from_value ( json_response) . unwrap ( ) ;
95
86
let output = get_identity_from_response_data ( data, CredentialOrigin :: EnvVar ) ;
96
87
97
88
let expected_identity = RegistryIdentity {
@@ -116,7 +107,8 @@ mod tests {
116
107
} ,
117
108
}
118
109
} ) ;
119
- let data: who_am_i_query:: ResponseData = serde_json:: from_value ( json_response) . unwrap ( ) ;
110
+ let data: config_who_am_i_query:: ResponseData =
111
+ serde_json:: from_value ( json_response) . unwrap ( ) ;
120
112
let output = get_identity_from_response_data ( data, CredentialOrigin :: EnvVar ) ;
121
113
122
114
let expected_identity = RegistryIdentity {
0 commit comments