From 9c8f072d222132ce17537d6ca54c245fd22898ef Mon Sep 17 00:00:00 2001 From: Nathaniel Tucker Date: Sat, 4 Oct 2025 14:24:43 -0400 Subject: [PATCH] feat: Unions can query without discriminator --- packages/endpoint/src/schemas/Union.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/endpoint/src/schemas/Union.ts b/packages/endpoint/src/schemas/Union.ts index ec14ea508fa4..195eb8d1c7da 100644 --- a/packages/endpoint/src/schemas/Union.ts +++ b/packages/endpoint/src/schemas/Union.ts @@ -33,7 +33,17 @@ export default class UnionSchema extends PolymorphicSchema { const discriminatedSchema = this.schema[schema]; // Was unable to infer the entity's schema from params - if (discriminatedSchema === undefined) return; + if (discriminatedSchema === undefined) { + // In this case, we will try each schema until we find one that matches + for (const key in this.schema) { + const id = unvisit(this.schema[key], args); + if (id !== undefined) { + return { id, schema: key }; + } + } + return; + } + const id = unvisit(discriminatedSchema, args); if (id === undefined) return; return { id, schema };