Search over multiple name predicates

The docs mention how to search over a single predicate, but how about searching over more than one?

For instance with this schema:

  type Book {
    Book.name
    relationships
  }

  type Movie {
    Movie.name
    relationships
  }

  type Podcast {
    Podcast.name
    relationships
  }

I’d like to be able to search name across all Books, Movies, and Podcasts…

You need to create an interface.

interface Namer {
  name: String! @search
}

type Book implements Namer {...}
type Movie implements Namer{...}
type Podcast implements Namer{...}

Then you can query something with somehting like that

query foo ($name:String!){
     queryNamer(filter: {name:$name}) {
         name
         __typename
         ... on Book {
              #book's field names here
         }
         ... on Podcast {

        }
    }
}
1 Like

Would it be the same idea for returning search results unrelated predicates (from two schemas that don’t share any fields)?

qq, is that a GraphQL question or DQL? if GraphQL, please move to Users/GraphQL.

Fixed

Can you explain what you mean by unrelated predicates?

@MichelDiz: originally meant it for DQL, but afaik interfaces are GQL only, right?

@amaster507: I mean searching two fields, like name for Books, Podcasts, and Movies and only the description field for Movies - for example.

Interfaces are graphQL only, but the handling of the logic can be done in DQL without interfaces.

I believe with an interface in GraphQL you can only filter with the interfaces predicates. GraphQL unions may also help your use case when they get released.

DQL query blocks would make this pretty easy. I can try to write up a quick example sometime later.

1 Like