Skip to content

[GraphQl] Support for unions and interfaces for search functionality #2927

Open
@samzijlmans

Description

@samzijlmans

I am trying to create a general search functionality in my app that can return multiple types of objects. For each type of object I want to retrieve different fields.

In the graphQl specification this is supported using interfaces and unions. See this example below:

type Query {
    # Search across all content
    search(query: String!): [SearchResult]
}

union SearchResult = Conference | Festival | Concert | Venue
query {
  search(query: "Madison") {
    ... on Venue {
      id
      name
      address
    }

    ... on Festival {
      id
      name
      performers
    }

    ... on Concert {
      id
      name
      performingBand
    }

    ... on Conference {
      speakers
      workshops
    }
  }
}

See this guide for more details.

I tried making all my entities extend a 'base' entity and creating the search query on that entity, but that did not work.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions