How to Query an Interface?


(Powers Rc) #1

I have developed an interface which several node types are implemented with using the same syntax found here. I can not however figure out how to query that defined interface, or if that is even possible.

Using the example found in the linked document above. How would I query the "Person" interface?
When I try and query my interface I get an empty list inside of my object.

Thanks


(William Lyon) #2

Could you share the query you have so far?

If you have an Actor type that implements the Person interface, then you'll want to use an Inline Fragment in the query. For example, from that sample schema getting actors for a movie would look something like:

{
  Movie {
    actors {
        ... on Actor {
          name
        }
    }
  }
}

(Powers Rc) #3

I was trying something like below.

{
  Person{
    name
    born
  }
}

I was thinking that the interface was the parent of the node type that implements it. So you have to access the specific node type before referring to the interface? Is it possible to just query all the node types of a specific interface, like the example above?

Could you also explain the difference between "Implements" & "Extends"? I tried to use "extends" in-place of "implements" but Neo4j reject the idl.


(Powers Rc) #4

Is there a way to query all nodes and relationships using graphQL?


(Btroop) #5

Having similar issues with using interfaces.

If I query an interface, I receive the following error when trying to query one of the types on that interface

"message": "Abstract type Entity must resolve to an Object type at runtime for field Query.entities with value { uuid: \"6b270c306e6a11e8bfe8b8e85647febc\" }, received \"undefined\". Either the Entity type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",

When I query a type that has a relationship to an in interface, I receive the following error:

"Resolve function for \"Organization.commonName\" returned undefined",

I've tried following all the GraphQL/Apollo documentation, like adding __resolveType and __typeOf resolvers and exposing the schema & fragment types to the client cache.

Apollo guidance - Unions & interfaces

Apollo guidance - Fragment matcher

Similar issue on github

I feel like I'm losing my mind because I can't figure this one out...any ideas?