1
- use std:: collections:: HashMap ;
2
-
3
1
use apollo_compiler:: ast:: { FragmentDefinition , Selection } ;
4
2
use apollo_compiler:: {
5
3
Name , Node , Schema as GraphqlSchema ,
@@ -17,6 +15,7 @@ use rmcp::{
17
15
use rover_copy:: pq_manifest:: ApolloPersistedQueryManifest ;
18
16
use serde:: Serialize ;
19
17
18
+ use crate :: custom_scalar_map:: CustomScalarMap ;
20
19
use crate :: errors:: { McpError , OperationError } ;
21
20
use crate :: graphql;
22
21
use crate :: tree_shake:: TreeShaker ;
@@ -42,7 +41,7 @@ impl Operation {
42
41
pub fn from_document (
43
42
source_text : & str ,
44
43
graphql_schema : & GraphqlSchema ,
45
- custom_scalar_map : Option < & HashMap < String , SchemaObject > > ,
44
+ custom_scalar_map : Option < & CustomScalarMap > ,
46
45
) -> Result < Self , OperationError > {
47
46
let document = Parser :: new ( )
48
47
. parse_ast ( source_text, "operation.graphql" )
@@ -110,14 +109,15 @@ impl Operation {
110
109
pub fn from_manifest (
111
110
schema : & GraphqlSchema ,
112
111
manifest : ApolloPersistedQueryManifest ,
112
+ custom_scalar_map : Option < & CustomScalarMap > ,
113
113
) -> Result < Vec < Self > , OperationError > {
114
114
manifest
115
115
. operations
116
116
. into_iter ( )
117
117
. map ( |pq| {
118
118
tracing:: info!( pesisted_query = pq. name, "Loading persisted query" ) ;
119
119
120
- Self :: from_document ( & pq. body , schema, None )
120
+ Self :: from_document ( & pq. body , schema, custom_scalar_map )
121
121
} )
122
122
. collect :: < Result < Vec < _ > , _ > > ( )
123
123
}
@@ -230,7 +230,7 @@ impl Operation {
230
230
fn get_json_schema (
231
231
operation : & Node < OperationDefinition > ,
232
232
graphql_schema : & GraphqlSchema ,
233
- custom_scalar_map : Option < & HashMap < String , SchemaObject > > ,
233
+ custom_scalar_map : Option < & CustomScalarMap > ,
234
234
) -> RootSchema {
235
235
let mut obj = ObjectValidation :: default ( ) ;
236
236
@@ -321,7 +321,7 @@ fn type_to_schema(
321
321
description : Option < String > ,
322
322
variable_type : & Type ,
323
323
graphql_schema : & GraphqlSchema ,
324
- custom_scalar_map : Option < & HashMap < String , SchemaObject > > ,
324
+ custom_scalar_map : Option < & CustomScalarMap > ,
325
325
) -> Schema {
326
326
match variable_type {
327
327
Type :: NonNullNamed ( named) | Type :: Named ( named) => match named. as_str ( ) {
@@ -459,20 +459,13 @@ impl graphql::Executable for Operation {
459
459
460
460
#[ cfg( test) ]
461
461
mod tests {
462
- use std:: {
463
- collections:: { HashMap , HashSet } ,
464
- sync:: LazyLock ,
465
- } ;
462
+ use std:: { collections:: HashSet , str:: FromStr , sync:: LazyLock } ;
466
463
467
464
use apollo_compiler:: { Schema , parser:: Parser , validation:: Valid } ;
468
- use rmcp:: {
469
- model:: Tool ,
470
- schemars:: schema:: { InstanceType , SchemaObject , SingleOrVec } ,
471
- serde_json,
472
- } ;
465
+ use rmcp:: { model:: Tool , serde_json} ;
473
466
use rover_copy:: pq_manifest:: ApolloPersistedQueryManifest ;
474
467
475
- use crate :: operations:: Operation ;
468
+ use crate :: { custom_scalar_map :: CustomScalarMap , operations:: Operation } ;
476
469
477
470
// Example schema for tests
478
471
static SCHEMA : LazyLock < Valid < Schema > > = LazyLock :: new ( || {
@@ -1069,7 +1062,7 @@ mod tests {
1069
1062
let operation = Operation :: from_document (
1070
1063
"query QueryName($id: RealCustomScalar) { id }" ,
1071
1064
& SCHEMA ,
1072
- Some ( & HashMap :: new ( ) ) ,
1065
+ Some ( & CustomScalarMap :: from_str ( "{}" ) . unwrap ( ) ) ,
1073
1066
)
1074
1067
. unwrap ( ) ;
1075
1068
let tool = Tool :: from ( operation) ;
@@ -1092,18 +1085,13 @@ mod tests {
1092
1085
1093
1086
#[ test]
1094
1087
fn custom_scalar_with_map ( ) {
1095
- let custom_scalar_map = HashMap :: from ( [ (
1096
- "RealCustomScalar" . to_string ( ) ,
1097
- SchemaObject {
1098
- instance_type : Some ( SingleOrVec :: Single ( Box :: new ( InstanceType :: String ) ) ) ,
1099
- ..Default :: default ( )
1100
- } ,
1101
- ) ] ) ;
1088
+ let custom_scalar_map =
1089
+ CustomScalarMap :: from_str ( "{ \" RealCustomScalar\" : { \" type\" : \" string\" }}" ) ;
1102
1090
1103
1091
let operation = Operation :: from_document (
1104
1092
"query QueryName($id: RealCustomScalar) { id }" ,
1105
1093
& SCHEMA ,
1106
- Some ( & custom_scalar_map) ,
1094
+ custom_scalar_map. ok ( ) . as_ref ( ) ,
1107
1095
)
1108
1096
. unwrap ( ) ;
1109
1097
let tool = Tool :: from ( operation) ;
@@ -1355,7 +1343,7 @@ mod tests {
1355
1343
} ) )
1356
1344
. expect ( "apollo pq should be valid" ) ;
1357
1345
1358
- let operations = Operation :: from_manifest ( & SCHEMA , apollo_pq. clone ( ) )
1346
+ let operations = Operation :: from_manifest ( & SCHEMA , apollo_pq. clone ( ) , None )
1359
1347
. expect ( "operations from manifest should parse" ) ;
1360
1348
assert_eq ! (
1361
1349
operations
0 commit comments