-
Hi, we are experiencing different behaviour between how Apollo Router and Hive Gateway handle subgraph execution. To describe the issue simply, I will use the following example. Please expand the sections to see the details. We have Schema and gateway informationorder schema""" ... other lines """
type Product @key(fields: "id", resolvable: false) {
id: String!
}
type Query {
getOrderData(input: GetOrderDataRequest!): OrderData
}
type OrderData {
items: [Product!]!
""" ... other fields"""
} product schema""" ... other lines """
type Product @key(fields: "id") @key(fields: "country_id store_id sku") {
id: String!
country_id: String!
store_id: String!
sku: String!
name: String! @shareable
description: String! @shareable
""" ... """
} Both schemas used by Apollo router and Hive gateway at the same time as the same from the different Hive targets. And Hive CDN returns the following supergraph: """ ... other lines """
enum join__Graph {
ORDERS @join__graph(
name: "orders"
url: "http://localhost:5000/query"
)
PRODUCTS @join__graph(
name: "products"
url: "http://localhost:2223/query"
)
}
type Query @join__type(graph: ORDERS) @join__type(graph: PRODUCTS) {
getOrderData(input: GetOrderDataRequest!) : OrderData @join__field(graph: ORDERS)
}
type OrderData @join__type(graph: ORDERS) {
store_id: String!
items: [Product!]!
""" ... other fields """
}
type Product @join__type(graph: ORDERS, key: "id", resolvable: false) @join__type(graph: PRODUCTS, key: "id") @join__type(graph: PRODUCTS, key: "country_id store_id sku") @join__type(graph: PRODUCTS, key: "country_id store_id remote_id") {
id: String!
country_id: String! @join__field(graph: PRODUCTS)
store_id: String! @join__field(graph: PRODUCTS)
sku: String! @join__field(graph: PRODUCTS)
remote_id: String! @join__field(graph: PRODUCTS)
description: String! @join__field(graph: PRODUCTS)
name: String! @join__field(graph: PRODUCTS)
""" ... other fields """
}
""" ... other lines """ And we are running this supergraph by the following Hive gateway config and at the same time same schemas and subgraphs used by the Apollo router for different use cases (as I mentioned above). import { defineConfig } from '@graphql-hive/gateway'
export const gatewayConfig = defineConfig({
supergraph: './supergraph.graphql',
})
# DEBUG=1 npx hive-gateway supergraph And we're querying like below: query GetOrderData($input: GetOrderDataRequest!) {
getOrderData(input: $input) {
__typename
... on OrderData {
__typename
store_id
items {
__typename
...item
}
total
subtotal
delivery_fee
}
}
}
fragment item on OrderItem {
__typename
product {
id
sku
name
}
price
absolute_discount
total
subtotal
} According to the query shared above, we observe the following execution differences: First, the subgraph fetches order data from the curl --location 'http://localhost:2223/query' \
--header 'accept: application/graphql-response+json, application/json, multipart/mixed' \
--header 'content-type: application/json' \
--data '{
"query": "query GetOrderData($_v0_representations:[_Any!]!){__typename _entities(representations:$_v0_representations){__typename ...on Product{country_id store_id sku remote_id sku name}}}",
"variables": {
"_v0_representations": [
{
"__typename": "Product",
"id": "feed7ce6-80cf-4303-8689-d264e8059b43"
},
{
"__typename": "Product",
"id": "fef61418-fe6a-4c2e-8e9f-00bdd1f60796"
},
{
"__typename": "Product",
"id": "ff806a7d-5e78-4ce8-ba4e-ee342e3b146e"
},
{
"__typename": "Product",
"id": "ce1a19c3-8adb-4b93-877d-e579e13cd6e5"
}
]
},
"operationName": "GetOrderData"
}' Then, it fetches IDs again while it has already returned by curl --location 'http://localhost:2223/query' \
--header 'accept: application/graphql-response+json, application/json, multipart/mixed' \
--header 'content-type: application/json' \
--data '{
"query": "query GetOrderData($_v0_representations:[_Any!]!){__typename _entities(representations:$_v0_representations){__typename ...on Product{id}}}",
"variables": {
"_v0_representations": [
{
"__typename": "Product",
"country_id": "12345",
"store_id": "123456",
"sku": "skucode1"
},
{
"__typename": "Product",
"country_id": "12345",
"store_id": "123456",
"sku": "skucode2"
},
{
"__typename": "Product",
"country_id": "12345",
"store_id": "123456",
"sku": "skucode3"
},
{
"__typename": "Product",
"country_id": "12345",
"store_id": "123456",
"sku": "skucode4"
}
]
},
"operationName": "GetOrderData"
}' The problem is here, it adds an extra latency, and since we have different resolver logics by requested fields this causes errors for some products. The same query works without error on the Apollo router, because the Apollo router also fetches the curl --location 'http://localhost:2223/query' \
--header 'accept: application/graphql-response+json, application/json, multipart/mixed' \
--header 'content-type: application/json' \
--data '{
"query": "query GetOrderData($_v0_representations:[_Any!]!){__typename _entities(representations:$_v0_representations){__typename ...on Product{country_id store_id sku id}}}",
"variables": {
"_v0_representations": [
{
"__typename": "Product",
"id": "feed7ce6-80cf-4303-8689-d264e8059b43"
},
{
"__typename": "Product",
"id": "fef61418-fe6a-4c2e-8e9f-00bdd1f60796"
},
{
"__typename": "Product",
"id": "ff806a7d-5e78-4ce8-ba4e-ee342e3b146e"
},
{
"__typename": "Product",
"id": "ce1a19c3-8adb-4b93-877d-e579e13cd6e5"
}
]
},
"operationName": "GetOrderData"
}' Please click to see execution logs:
Second execution logs to fetch
We thought that can we improve this flow with additionalResolvers, but could not find how to do it with the hive gateway (we just migrated) Can you please brainstorm with us on this problem? How we can solve it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I tried to reproduce the behavior here; Could you help us to reproduce it so we can help you better? Thanks for creating the issue! |
Beta Was this translation helpful? Give feedback.
Hello @ardatan, thank you for your great effort in this ecosystem. I appreciate your quick response and apologize for the late reply. I attempted to reproduce the issue as like you, and I found that it is working as expected (same as Apollo Router) with
@graphql-hive/[email protected]
I upgraded from 1.0.8.