Skip to content

Commit 6848cc3

Browse files
authored
Nested field with argument in @requires (#132)
1 parent 2ed9bf4 commit 6848cc3

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

gateways/hive-gateway/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# https://github.com/graphql-hive/gateway/releases
2-
curl -sSL https://graphql-hive.com/install-gateway.sh | sh -s "1.14.2"
2+
curl -sSL https://graphql-hive.com/install-gateway.sh | sh -s "1.15.0"

src/test-suites/requires-with-argument/a.subgraph.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ export default createSubgraph("a", {
1919
price(currency: "USD") weight
2020
"""
2121
)
22+
category: Category @external
23+
isExpensiveCategory: Boolean
24+
@requires(
25+
fields: """
26+
category { averagePrice(currency: "USD") }
27+
"""
28+
)
29+
}
30+
31+
type Category @external {
32+
averagePrice(currency: String!): Int
2233
}
2334
`,
2435
resolvers: {
2536
Product: {
2637
__resolveReference(
27-
key: { upc: string; price: number; weight: number } | { upc: string },
38+
key: { upc: string; price: number; weight: number } | { upc: string }
2839
) {
2940
const product = products.find((p) => p.upc === key.upc);
3041

@@ -37,16 +48,21 @@ export default createSubgraph("a", {
3748
upc: product.upc,
3849
weight: key.weight,
3950
price: key.price,
51+
category: product.category,
4052
};
4153
}
4254

4355
return {
4456
upc: product.upc,
57+
category: product.category,
4558
};
4659
},
4760
shippingEstimate(product: { price: number; weight: number }) {
4861
return product.price * product.weight * 10;
4962
},
63+
isExpensiveCategory(product: { category: { averagePrice: number } }) {
64+
return product.category.averagePrice > 11;
65+
},
5066
},
5167
},
5268
});

src/test-suites/requires-with-argument/b.subgraph.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export default createSubgraph("b", {
1515
name: String
1616
price(currency: String!): Int
1717
weight: Int
18+
category: Category
19+
}
20+
21+
type Category {
22+
averagePrice(currency: String!): Int
1823
}
1924
`,
2025
resolvers: {
@@ -25,6 +30,7 @@ export default createSubgraph("b", {
2530
name: p.name,
2631
price: p.price,
2732
weight: p.weight,
33+
category: p.category,
2834
}));
2935
},
3036
},
@@ -41,6 +47,7 @@ export default createSubgraph("b", {
4147
name: product.name,
4248
price: product.price,
4349
weight: product.weight,
50+
category: product.category,
4451
};
4552
},
4653
},

src/test-suites/requires-with-argument/data.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ export const products = [
44
name: "p-name-1",
55
price: 11,
66
weight: 1,
7+
category: {
8+
averagePrice: 11,
9+
},
710
},
811
{
912
upc: "p2",
1013
name: "p-name-2",
1114
price: 22,
1215
weight: 2,
16+
category: {
17+
averagePrice: 22,
18+
},
1319
},
1420
];
1521

src/test-suites/requires-with-argument/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default [
88
upc
99
name
1010
shippingEstimate
11+
isExpensiveCategory
1112
}
1213
}
1314
`,
@@ -18,11 +19,13 @@ export default [
1819
upc: "p1",
1920
name: "p-name-1",
2021
shippingEstimate: 110,
22+
isExpensiveCategory: false,
2123
},
2224
{
2325
upc: "p2",
2426
name: "p-name-2",
2527
shippingEstimate: 440,
28+
isExpensiveCategory: true,
2629
},
2730
],
2831
},

0 commit comments

Comments
 (0)