File tree 2 files changed +104
-0
lines changed
packages/apollo-gateway/src/__tests__
2 files changed +104
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,21 @@ export const typeDefs = gql`
24
24
sku: String!
25
25
name: String
26
26
price: String
27
+ details: ProductDetails
28
+ }
29
+
30
+ interface ProductDetails {
31
+ country: String
32
+ }
33
+
34
+ type ProductDetailsFurniture implements ProductDetails {
35
+ country: String
36
+ color: String
37
+ }
38
+
39
+ type ProductDetailsBook implements ProductDetails {
40
+ country: String
41
+ pages: Int
27
42
}
28
43
29
44
type Furniture implements Product @key(fields: "upc") @key(fields: "sku") {
@@ -33,6 +48,7 @@ export const typeDefs = gql`
33
48
price: String
34
49
brand: Brand
35
50
metadata: [MetadataOrError]
51
+ details: ProductDetailsFurniture
36
52
}
37
53
38
54
extend type Book implements Product @key(fields: "isbn") {
@@ -43,6 +59,7 @@ export const typeDefs = gql`
43
59
sku: String!
44
60
name(delimeter: String = " "): String @requires(fields: "title year")
45
61
price: String
62
+ details: ProductDetailsBook
46
63
}
47
64
48
65
type Car @key(fields: "id") {
Original file line number Diff line number Diff line change @@ -790,4 +790,91 @@ describe('buildQueryPlan', () => {
790
790
}
791
791
` ) ;
792
792
} ) ;
793
+
794
+ it ( `interface fragments should expand into possible types only` , ( ) => {
795
+ const query = gql `
796
+ query {
797
+ books {
798
+ ... on Product {
799
+ name
800
+ ... on Furniture {
801
+ upc
802
+ }
803
+ }
804
+ }
805
+ }
806
+ ` ;
807
+
808
+ const queryPlan = buildQueryPlan ( buildOperationContext ( schema , query ) ) ;
809
+
810
+ expect ( queryPlan ) . toMatchInlineSnapshot ( `
811
+ QueryPlan {
812
+ Sequence {
813
+ Fetch(service: "books") {
814
+ {
815
+ books {
816
+ __typename
817
+ isbn
818
+ title
819
+ year
820
+ }
821
+ }
822
+ },
823
+ Flatten(path: "books.@") {
824
+ Fetch(service: "product") {
825
+ {
826
+ ... on Book {
827
+ __typename
828
+ isbn
829
+ title
830
+ year
831
+ }
832
+ } =>
833
+ {
834
+ ... on Book {
835
+ name
836
+ }
837
+ }
838
+ },
839
+ },
840
+ },
841
+ }
842
+ ` ) ;
843
+ } ) ;
844
+
845
+ it ( `interface inside interface should expand into possible types only` , ( ) => {
846
+ const query = gql `
847
+ query {
848
+ product(upc: "") {
849
+ details {
850
+ country
851
+ }
852
+ }
853
+ }
854
+ ` ;
855
+
856
+ const queryPlan = buildQueryPlan ( buildOperationContext ( schema , query ) ) ;
857
+
858
+ expect ( queryPlan ) . toMatchInlineSnapshot ( `
859
+ QueryPlan {
860
+ Fetch(service: "product") {
861
+ {
862
+ product(upc: "") {
863
+ __typename
864
+ ... on Book {
865
+ details {
866
+ country
867
+ }
868
+ }
869
+ ... on Furniture {
870
+ details {
871
+ country
872
+ }
873
+ }
874
+ }
875
+ }
876
+ },
877
+ }
878
+ ` ) ;
879
+ } ) ;
793
880
} ) ;
You can’t perform that action at this time.
0 commit comments