Views Search API unions not resolved

Created on 29 August 2024, 3 months ago
Updated 15 September 2024, 2 months ago

Problem/Motivation

When creating a view that uses the Search API, if that index supports multiple bundles or entity types, the custom union for results is never defined.

Steps to reproduce

Create a Search API Index for nodes
Create 2 content types
Create a view, GraphQL view, search api, entity display

Proposed resolution

Modify `getGraphQlUnionTypes` and introduce `hasGraphQlUnionTypes` to check for a custom union.
Add a resolver for that union type.

Remaining tasks

Nil

User interface changes

Nil

API changes

`getGraphQlUnionTypes` will now only return types for a custom union. Eg MySearchResultRow, and not return a generic such as NodeUnion

Data model changes

Previous behaviour was to return the first union type if only one existed.
This is observed to cause issues with spilling incorrect __typename entities out of the search index, and assigning an incorrect entity type.

A Search API based view's results field will now always return a union, and throw an error if non-supported content types are in the result-set.

Upgrading?

If you had a previous Search API view that returned only one content type, eg result: [NodePage!]!, it'll now be within a union.

Example:

query MyQuery {
  mySearchApiView {
    results {
      ... on NodePage {
        id
        title
      }
    }
  }
🐛 Bug report
Status

Fixed

Version

2.2

Component

Code

Created by

🇦🇺Australia almunnings Melbourne, 🇦🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024