Skip to content

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

Open
ddeboer wants to merge 3 commits into
mainfrom
worktree-issue-717-polymorphic-lookup
Open

feat(search)!: resolve a reference across several targets#848
ddeboer wants to merge 3 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 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 (one OPTIONAL triple) and emits every target’s expansion or key hop.
  • 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; __typename resolves per referent, and an inline fragment reaches per-type fields.
  • 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 27 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.
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