@@ -658,29 +658,26 @@ impl SchemaDefinition {
658
658
. filter_map ( |( ty, maybe_op) | maybe_op. as_ref ( ) . map ( |op| ( ty, op) ) )
659
659
}
660
660
661
- /// Collect `schema` extensions that contribute any component
661
+ /// Iterate over the `origins` of all components
662
662
///
663
663
/// The order of the returned set is unspecified but deterministic
664
664
/// for a given apollo-compiler version.
665
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
665
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
666
666
self . directives
667
667
. iter ( )
668
- . flat_map ( |dir| dir. origin . extension_id ( ) )
669
- . chain (
670
- self . query
671
- . as_ref ( )
672
- . and_then ( |name| name. origin . extension_id ( ) ) ,
673
- )
674
- . chain (
675
- self . mutation
676
- . as_ref ( )
677
- . and_then ( |name| name. origin . extension_id ( ) ) ,
678
- )
679
- . chain (
680
- self . subscription
681
- . as_ref ( )
682
- . and_then ( |name| name. origin . extension_id ( ) ) ,
683
- )
668
+ . map ( |dir| & dir. origin )
669
+ . chain ( self . query . iter ( ) . map ( |name| & name. origin ) )
670
+ . chain ( self . mutation . iter ( ) . map ( |name| & name. origin ) )
671
+ . chain ( self . subscription . iter ( ) . map ( |name| & name. origin ) )
672
+ }
673
+
674
+ /// Collect `schema` extensions that contribute any component
675
+ ///
676
+ /// The order of the returned set is unspecified but deterministic
677
+ /// for a given apollo-compiler version.
678
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
679
+ self . iter_origins ( )
680
+ . filter_map ( |origin| origin. extension_id ( ) )
684
681
. collect ( )
685
682
}
686
683
}
@@ -857,128 +854,185 @@ impl ExtendedType {
857
854
}
858
855
}
859
856
857
+ /// Iterate over the `origins` of all components
858
+ ///
859
+ /// The order of the returned set is unspecified but deterministic
860
+ /// for a given apollo-compiler version.
861
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
862
+ match self {
863
+ Self :: Scalar ( ty) => Box :: new ( ty. iter_origins ( ) ) as Box < dyn Iterator < Item = _ > > ,
864
+ Self :: Object ( ty) => Box :: new ( ty. iter_origins ( ) ) ,
865
+ Self :: Interface ( ty) => Box :: new ( ty. iter_origins ( ) ) ,
866
+ Self :: Union ( ty) => Box :: new ( ty. iter_origins ( ) ) ,
867
+ Self :: Enum ( ty) => Box :: new ( ty. iter_origins ( ) ) ,
868
+ Self :: InputObject ( ty) => Box :: new ( ty. iter_origins ( ) ) ,
869
+ }
870
+ }
871
+
872
+ /// Collect `schema` extensions that contribute any component
873
+ ///
874
+ /// The order of the returned set is unspecified but deterministic
875
+ /// for a given apollo-compiler version.
876
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
877
+ self . iter_origins ( )
878
+ . filter_map ( |origin| origin. extension_id ( ) )
879
+ . collect ( )
880
+ }
881
+
860
882
serialize_method ! ( ) ;
861
883
}
862
884
863
885
impl ScalarType {
886
+ /// Iterate over the `origins` of all components
887
+ ///
888
+ /// The order of the returned set is unspecified but deterministic
889
+ /// for a given apollo-compiler version.
890
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
891
+ self . directives . iter ( ) . map ( |dir| & dir. origin )
892
+ }
893
+
864
894
/// Collect scalar type extensions that contribute any component
865
895
///
866
896
/// The order of the returned set is unspecified but deterministic
867
897
/// for a given apollo-compiler version.
868
898
pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
869
- self . directives
870
- . iter ( )
871
- . flat_map ( |dir| dir. origin . extension_id ( ) )
899
+ self . iter_origins ( )
900
+ . filter_map ( |origin| origin. extension_id ( ) )
872
901
. collect ( )
873
902
}
874
903
875
904
serialize_method ! ( ) ;
876
905
}
877
906
878
907
impl ObjectType {
879
- /// Collect object type extensions that contribute any component
908
+ /// Iterate over the `origins` of all components
880
909
///
881
910
/// The order of the returned set is unspecified but deterministic
882
911
/// for a given apollo-compiler version.
883
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
912
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
884
913
self . directives
885
914
. iter ( )
886
- . flat_map ( |dir| dir. origin . extension_id ( ) )
915
+ . map ( |dir| & dir. origin )
887
916
. chain (
888
917
self . implements_interfaces
889
918
. iter ( )
890
- . flat_map ( |component| component. origin . extension_id ( ) ) ,
891
- )
892
- . chain (
893
- self . fields
894
- . values ( )
895
- . flat_map ( |field| field. origin . extension_id ( ) ) ,
919
+ . map ( |component| & component. origin ) ,
896
920
)
921
+ . chain ( self . fields . values ( ) . map ( |field| & field. origin ) )
922
+ }
923
+
924
+ /// Collect object type extensions that contribute any component
925
+ ///
926
+ /// The order of the returned set is unspecified but deterministic
927
+ /// for a given apollo-compiler version.
928
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
929
+ self . iter_origins ( )
930
+ . filter_map ( |origin| origin. extension_id ( ) )
897
931
. collect ( )
898
932
}
899
933
900
934
serialize_method ! ( ) ;
901
935
}
902
936
903
937
impl InterfaceType {
904
- /// Collect interface type extensions that contribute any component
938
+ /// Iterate over the `origins` of all components
905
939
///
906
940
/// The order of the returned set is unspecified but deterministic
907
941
/// for a given apollo-compiler version.
908
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
942
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
909
943
self . directives
910
944
. iter ( )
911
- . flat_map ( |dir| dir. origin . extension_id ( ) )
945
+ . map ( |dir| & dir. origin )
912
946
. chain (
913
947
self . implements_interfaces
914
948
. iter ( )
915
- . flat_map ( |component| component. origin . extension_id ( ) ) ,
916
- )
917
- . chain (
918
- self . fields
919
- . values ( )
920
- . flat_map ( |field| field. origin . extension_id ( ) ) ,
949
+ . map ( |component| & component. origin ) ,
921
950
)
951
+ . chain ( self . fields . values ( ) . map ( |field| & field. origin ) )
952
+ }
953
+
954
+ /// Collect interface type extensions that contribute any component
955
+ ///
956
+ /// The order of the returned set is unspecified but deterministic
957
+ /// for a given apollo-compiler version.
958
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
959
+ self . iter_origins ( )
960
+ . filter_map ( |origin| origin. extension_id ( ) )
922
961
. collect ( )
923
962
}
924
963
925
964
serialize_method ! ( ) ;
926
965
}
927
966
928
967
impl UnionType {
929
- /// Collect union type extensions that contribute any component
968
+ /// Iterate over the `origins` of all components
930
969
///
931
970
/// The order of the returned set is unspecified but deterministic
932
971
/// for a given apollo-compiler version.
933
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
972
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
934
973
self . directives
935
974
. iter ( )
936
- . flat_map ( |dir| dir. origin . extension_id ( ) )
937
- . chain (
938
- self . members
939
- . iter ( )
940
- . flat_map ( |component| component. origin . extension_id ( ) ) ,
941
- )
975
+ . map ( |dir| & dir. origin )
976
+ . chain ( self . members . iter ( ) . map ( |component| & component. origin ) )
977
+ }
978
+
979
+ /// Collect union type extensions that contribute any component
980
+ ///
981
+ /// The order of the returned set is unspecified but deterministic
982
+ /// for a given apollo-compiler version.
983
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
984
+ self . iter_origins ( )
985
+ . filter_map ( |origin| origin. extension_id ( ) )
942
986
. collect ( )
943
987
}
944
988
945
989
serialize_method ! ( ) ;
946
990
}
947
991
948
992
impl EnumType {
949
- /// Collect enum type extensions that contribute any component
993
+ /// Iterate over the `origins` of all components
950
994
///
951
995
/// The order of the returned set is unspecified but deterministic
952
996
/// for a given apollo-compiler version.
953
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
997
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
954
998
self . directives
955
999
. iter ( )
956
- . flat_map ( |dir| dir. origin . extension_id ( ) )
957
- . chain (
958
- self . values
959
- . values ( )
960
- . flat_map ( |value| value. origin . extension_id ( ) ) ,
961
- )
1000
+ . map ( |dir| & dir. origin )
1001
+ . chain ( self . values . values ( ) . map ( |value| & value. origin ) )
1002
+ }
1003
+
1004
+ /// Collect enum type extensions that contribute any component
1005
+ ///
1006
+ /// The order of the returned set is unspecified but deterministic
1007
+ /// for a given apollo-compiler version.
1008
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
1009
+ self . iter_origins ( )
1010
+ . filter_map ( |origin| origin. extension_id ( ) )
962
1011
. collect ( )
963
1012
}
964
1013
965
1014
serialize_method ! ( ) ;
966
1015
}
967
1016
968
1017
impl InputObjectType {
969
- /// Collect input object type extensions that contribute any component
1018
+ /// Iterate over the `origins` of all components
970
1019
///
971
1020
/// The order of the returned set is unspecified but deterministic
972
1021
/// for a given apollo-compiler version.
973
- pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
1022
+ fn iter_origins ( & self ) -> impl Iterator < Item = & ComponentOrigin > {
974
1023
self . directives
975
1024
. iter ( )
976
- . flat_map ( |dir| dir. origin . extension_id ( ) )
977
- . chain (
978
- self . fields
979
- . values ( )
980
- . flat_map ( |field| field. origin . extension_id ( ) ) ,
981
- )
1025
+ . map ( |dir| & dir. origin )
1026
+ . chain ( self . fields . values ( ) . map ( |field| & field. origin ) )
1027
+ }
1028
+
1029
+ /// Collect input object type extensions that contribute any component
1030
+ ///
1031
+ /// The order of the returned set is unspecified but deterministic
1032
+ /// for a given apollo-compiler version.
1033
+ pub fn extensions ( & self ) -> IndexSet < & ExtensionId > {
1034
+ self . iter_origins ( )
1035
+ . filter_map ( |origin| origin. extension_id ( ) )
982
1036
. collect ( )
983
1037
}
984
1038
0 commit comments