13
13
)
14
14
15
15
from ..error import GraphQLError
16
- from ..language import ast , OperationType
16
+ from ..language import OperationType , ast
17
17
from ..pyutils import inspect , is_collection , is_description
18
18
from .definition import (
19
19
GraphQLAbstractType ,
20
- GraphQLInterfaceType ,
21
20
GraphQLInputObjectType ,
21
+ GraphQLInputType ,
22
+ GraphQLInterfaceType ,
22
23
GraphQLNamedType ,
23
24
GraphQLObjectType ,
24
- GraphQLUnionType ,
25
25
GraphQLType ,
26
+ GraphQLUnionType ,
26
27
GraphQLWrappingType ,
27
28
get_named_type ,
28
29
is_input_object_type ,
31
32
is_union_type ,
32
33
is_wrapping_type ,
33
34
)
34
- from .directives import GraphQLDirective , specified_directives , is_directive
35
+ from .directives import GraphQLDirective , is_directive , specified_directives
35
36
from .introspection import introspection_types
36
37
37
38
try :
@@ -310,8 +311,8 @@ def __copy__(self) -> "GraphQLSchema": # pragma: no cover
310
311
def __deepcopy__ (self , memo_ : Dict ) -> "GraphQLSchema" :
311
312
from ..type import (
312
313
is_introspection_type ,
313
- is_specified_scalar_type ,
314
314
is_specified_directive ,
315
+ is_specified_scalar_type ,
315
316
)
316
317
317
318
type_map : TypeMap = {
@@ -326,6 +327,8 @@ def __deepcopy__(self, memo_: Dict) -> "GraphQLSchema":
326
327
directive if is_specified_directive (directive ) else copy (directive )
327
328
for directive in self .directives
328
329
]
330
+ for directive in directives :
331
+ remap_directive (directive , type_map )
329
332
return self .__class__ (
330
333
self .query_type and cast (GraphQLObjectType , type_map [self .query_type .name ]),
331
334
self .mutation_type
@@ -461,12 +464,7 @@ def remapped_type(type_: GraphQLType, type_map: TypeMap) -> GraphQLType:
461
464
462
465
def remap_named_type (type_ : GraphQLNamedType , type_map : TypeMap ) -> None :
463
466
"""Change all references in the given named type to use this type map."""
464
- if is_union_type (type_ ):
465
- type_ = cast (GraphQLUnionType , type_ )
466
- type_ .types = [
467
- type_map .get (member_type .name , member_type ) for member_type in type_ .types
468
- ]
469
- elif is_object_type (type_ ) or is_interface_type (type_ ):
467
+ if is_object_type (type_ ) or is_interface_type (type_ ):
470
468
type_ = cast (Union [GraphQLObjectType , GraphQLInterfaceType ], type_ )
471
469
type_ .interfaces = [
472
470
type_map .get (interface_type .name , interface_type )
@@ -482,10 +480,23 @@ def remap_named_type(type_: GraphQLNamedType, type_map: TypeMap) -> None:
482
480
arg .type = remapped_type (arg .type , type_map )
483
481
args [arg_name ] = arg
484
482
fields [field_name ] = field
483
+ elif is_union_type (type_ ):
484
+ type_ = cast (GraphQLUnionType , type_ )
485
+ type_ .types = [
486
+ type_map .get (member_type .name , member_type ) for member_type in type_ .types
487
+ ]
485
488
elif is_input_object_type (type_ ):
486
489
type_ = cast (GraphQLInputObjectType , type_ )
487
490
fields = type_ .fields
488
491
for field_name , field in fields .items ():
489
492
field = copy (field )
490
493
field .type = remapped_type (field .type , type_map )
491
494
fields [field_name ] = field
495
+
496
+ def remap_directive (directive : GraphQLDirective , type_map : TypeMap ) -> None :
497
+ """Change all references in the given directive to use this type map."""
498
+ args = directive .args
499
+ for arg_name , arg in args .items ():
500
+ arg = copy (arg ) # noqa: PLW2901
501
+ arg .type = cast (GraphQLInputType , remapped_type (arg .type , type_map ))
502
+ args [arg_name ] = arg
0 commit comments