Skip to content

Commit a19cb3b

Browse files
Add failing tests from #3257
1 parent 9928224 commit a19cb3b

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

packages/apollo-gateway/src/__tests__/__fixtures__/schemas/product.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export const typeDefs = gql`
2424
sku: String!
2525
name: String
2626
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
2742
}
2843
2944
type Furniture implements Product @key(fields: "upc") @key(fields: "sku") {
@@ -33,6 +48,7 @@ export const typeDefs = gql`
3348
price: String
3449
brand: Brand
3550
metadata: [MetadataOrError]
51+
details: ProductDetailsFurniture
3652
}
3753
3854
extend type Book implements Product @key(fields: "isbn") {
@@ -43,6 +59,7 @@ export const typeDefs = gql`
4359
sku: String!
4460
name(delimeter: String = " "): String @requires(fields: "title year")
4561
price: String
62+
details: ProductDetailsBook
4663
}
4764
4865
type Car @key(fields: "id") {

packages/apollo-gateway/src/__tests__/buildQueryPlan.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,4 +790,91 @@ describe('buildQueryPlan', () => {
790790
}
791791
`);
792792
});
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+
});
793880
});

0 commit comments

Comments
 (0)