GraphQL: Use Common Interface for Classes

Hi,

I’ve just started exploring Weaviate’s GraphQL interface and it works great!

I have used GraphQL in another context and built my own schema. Our model is based on schema(dot)org and I made schema:Thing an interface that is implemented by all other classes like schema:ScholarlyArticle etc.

Is it possible to add a GraphQL interface when creating a class? And if so, would this allow for a way of querying multiple vector spaces when using Get?

So if I create a class ScholarlyArticle that implements Thing and another class Book that also implements Thing, would it be possible to query also for Thing and thereby query the combined vector spaces for ScholarlyArticle and Book? Of course, one could only query for the properties of Thing.

Thanks for your feedback,

Tobias

Hi @Tobias_Schweizer ! Welcome to our community :hugs:

Happy to know that you are experimenting and liking Weaviate!

AFAIK, there isn’t a way to implement such an Interface.

While you can use cross reference to create relationships between those classes, you will need to query each class with it’s properties separately.

There is a way to do multiple queries at the same request payload by leveraging GraphQL alias, like so:

 {
   Get {
     Q1: MyClass(tenant: "rep-1") {
       name
     }
     Q2: MyClass(tenant: "rep-2") {
       name
     }
   }
 }

but those queries, while in the same request, are isolated from each other.

Also, a caveat: this is not supported in our clients, so you will need to use raw() method, or call it directly.

Let me know if this helps!

Thanks!

Hi @DudaNogueira,

Thanks for your response.

Would the results for those queries be returned as different lists/sets of results like shown here, each with their own pagination of results?

Do you think it would make sense to create a feature request for the support of interfaces in GraphQL? If so, I’d gladly add one.

In our own GraphQL endpoint, interfaces allow for more compact queries (and consistency) as fragments can be used:

# fragment definition for interface Thing
fragment baseFields on Thing {
  iri
  name
  description
  identifier
  sameAs
}

# fields to be returned for a query
... on Dataset {
          ...baseFields
          keywords
        }

Kind regards,

Tobias

Is there a comprehensive tutorial on Weaviates GraphQL? Some videos? I don’t think I really know what it is and what I can do with it. Currently I’m using Weaviate to import objects and do vector searches on it (i.e. - nearText() calls).

hi Robert!

Unfortunately not much, as new versions are moving away from GraphQL (they will still be there) and moving towards GRPC, that is way more performant than REST apis.