Skip to content

feat(search)!: resolve a reference across several targets - #848

Merged
ddeboer merged 8 commits into
mainfrom
worktree-issue-717-polymorphic-lookup
Oct 16, 2026
Merged

ddeboer merged 8 commits into
mainfrom
worktree-issue-717-polymorphic-lookup

Conversation

@ddeboer

@ddeboer ddeboer commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Fix #717

A lookup’s target (and an idOnly’s labelSource) may now name several Root Types, in order of precedence, so a field whose referent may be a Person or an Organization labels every value, types every value truthfully, and serves each kind’s own fields.

What changes

Declaration (@lde/search)

  • target: string | readonly string[], labelSource likewise; one plural reading (labelSourceNamesOf, labelTargetNamesOf, localLookupTargetsOf, referencedTargetsOf) replaces the single-target helpers, and inheritedFacetPolicies replaces inheritedFacetKeys.
  • searchSchema rejects an empty target list, a target named twice, joinable on several targets, and two targets declaring one field differently (kind, arity, Roles, or a reference’s strategy/referent). _target becomes a reserved field name.
  • Framing depth is the furthest any target reaches.

Index time (@lde/search, @lde/search-pipeline)

  • The extraction reads a multi-target referent’s rdf:type and emits every target’s expansion or key hop, each its own UNION branch inside one OPTIONAL, so multi-valued types and keys don’t multiply rows.
  • The projection matches it against each target’s class, in declaration order, and treats the referent as a document of that target: re-keyed through its key, admitted to a facet by its policy. A stored (local) referent records the match under _target, so an unidentified referent is still served as the kind it was stated to be. Single-target lookups store exactly what they stored before.

Query time (@lde/search-typesense)

  • Labels and projected lookups fetch from every target collection in the same round-trip; an IRI two collections hold belongs to the first declared. Each resolved nested document is marked with its target under a symbol key (NESTED_DOCUMENT_TYPE), never as a field.
  • The collection declares the union of the targets’ fields plus the discriminator.

Surface (@lde/search-api-graphql)

  • One interface per target set, PersonOrOrganizationReference, implemented by each ‹Target›Reference and carrying id plus every field the targets declare alike (nullable); __typename resolves per referent, and an inline fragment reaches per-type fields.
  • A referent no collection holds – dangling, or its lookup failed – is served as PersonOrOrganizationUnresolvedReference with only its id, rather than claimed for the first target.
  • The field’s filter is PersonOrOrganizationFilter { in: [IRI!] }; coarse discovery still finds it.

Not in scope

A join predicate on a polymorphic reference (“works whose creator died before 1900”) stays out of reach – an engine reference names one collection – and is tracked in #845.

Records

ADR 28 amends ADR 21, which had rejected both a target list and an output-side interface on convenience grounds; a __typename that is false for half the values is not a convenience problem. The search, search-api-graphql, search-typesense and search-pipeline reference pages describe the mechanism.

BREAKING for schema-level readers only: the renamed helpers above. A declaration naming one target is unchanged in storage and in emitted GraphQL.

A lookup’s target (and an idOnly’s labelSource) may name several Root
Types, in order of precedence. Each referent resolves against every
named collection and is read through the declaration of the one that
holds it – label, key and facet policy per value – and a stored
referent carries an rdf:type-derived discriminator so an unidentified
one is still served as the kind it was stated to be. A GraphQL surface
emits an interface named for the set, implemented by each target’s own
reference type, so __typename is truthful per referent; the field’s
filter is named for the set too. joinable is refused on such a lookup.

BREAKING CHANGE: labelSourceNameOf, labelTargetNameOf, localLookupTypeOf
and inheritedFacetKeys are replaced by labelSourceNamesOf,
labelTargetNamesOf, localLookupTargetsOf and inheritedFacetPolicies,
which return lists (or a map) rather than a single value; _target is a
reserved field name.
- Drop the GraphQL fixture that named one field at two referents: the
  schema now rejects that pairing, so the interface builder no longer
  re-checks it and the branch threshold is re-anchored.
- Cover a single-target lookup skipping an id-only selection, an empty
  stored referent field, a single-valued polymorphic nesting and a
  cut descent that still declares its discriminator.
…ocal lookup

The empty-endpoint case is read one level in, by the stored lookup,
not by the inline entry above it – so the test states an edge without
a creator rather than a work without edges.
Renumber the polymorphic-lookup ADR to 28, since main took 27 for the QLever sidecar.
- Rebuild an unanswered stored referent against its target’s levels, so its lookups nest
- Ask each target’s collection only for the lookup fields that target declares
- Reject an empty target or labelSource list with a new empty-target issue
- Refuse a type whose filter name collides with a multi-target lookup’s, output or not
- Read rdf:type and key hops as UNION branches of one OPTIONAL, so no row cross product
- Stop tracking a generated coverage summary and ignore coverage directories everywhere
- Drop a stale coverage-threshold comment and a duplicated GraphQL test
…eference

- Resolve a referent no collection holds to ‹Set›UnresolvedReference, not the first target
- Make every interface field nullable, since the unresolved type carries only its id
- Record the choice, and why dropping the referent was rejected, in ADR 28
…lymorphic-lookup

# Conflicts:
#	packages/search-api-graphql/vite.config.ts
#	packages/search-typesense/src/query-compiler.ts
#	packages/search/vite.config.ts
@ddeboer
ddeboer merged commit 20490df into main Oct 16, 2026
4 checks passed
@ddeboer
ddeboer deleted the worktree-issue-717-polymorphic-lookup branch October 16, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A labelOnly reference should be an interface, so a polymorphic range resolves labels and reports its type

1 participant