#7883·tyk

GraphQL 联合: 对具有不同可为空联合字段的异构数组进行实体解析失败

作者: dennissetiawan创建于 2026年3月12日更新于 2026年8月13日
标签bugexternal

Related Issue This is a distinct reproduction of the same []null / empty URL symptom seen in #7653, but with a different trigger: truly heterogeneous arrays where items are different subtypes and carry different nullable federated fields — rather than a single entity type with multiple @key variants. — — — Description When Tyk Gateway resolves federated entities via _entities queries for a field on a type that appears in an array, the federation planner uses array index 0 as the anchor to determine the subgraph URL for the entire entity resolution batch. If item[0] has null for the federated field being resolved (because item[0] is of a different subtype and that field does not apply to it), Tyk generates an empty URL and the fetch fails with: Get "": unsupported protocol scheme "" This manifests specifically with heterogeneous arrays — arrays where items have different subtypes, and only some items carry a particular federated field (others have null for that field). — — — How This Differs from #7653 Issue #7653 involves a single entity type (Product) extended via two different @key fields (id vs sku) in two separate subgraphs. All array items are the same type. This issue involves an array of items where each item can be one of two completely different entity types (e.g. TypeAlpha or TypeBeta), and only items of the matching type carry a non-null value for a given federated field. The planner still exhibits the same index-0 URL anchor behavior, but it is triggered by a structurally different schema pattern. — — — Steps to Reproduce ### Schema Setup Subgraph A ("catalog") — owns the Item array; extends two entity types from Subgraph B: graphql extend type TypeAlpha @key(fields: "id") { id: String @external } extend type TypeBeta @key(fields: "id") { id: String @external } type Item { itemType: ItemType! # enum: ALPHA | BETA id: String! alphaDetail: TypeAlpha # non-null only when itemType == ALPHA betaDetail: TypeBeta # non-null only when itemType == BETA } enum ItemType { ALPHA BETA } type Query { listItems: [Item!]! } Subgraph B ("details") — owns both entity types: graphql type TypeAlpha @key(fields: "id") { id: String name: String } type TypeBeta @key(fields: "id") { id: String name: String } ### Query graphql query { listItems { itemType id alphaDetail { name } betaDetail { name } } } ### Data That Triggers the Bug Subgraph A returns a mixed array where the first element is type ALPHA (so betaDetail is null at index 0): json [ { "id": "alpha-001", "itemType": "ALPHA", "alphaDetail": { "id": "alpha-001" }, "betaDetail": null }, { "id": "alpha-002", "itemType": "ALPHA", "alphaDetail": { "id": "alpha-002" }, "betaDetail": null }, { "id": "beta-001", "itemType": "BETA", "alphaDetail": null, "betaDetail": { "id": "beta-001" } } ]

内容来源: TykTechnologies/tyk