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

0 Likes

(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
        }
    }
  }
}
0 Likes

(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.

0 Likes

(Powers Rc) #4

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

0 Likes

(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?

0 Likes

(Smkhalsa) #6

I'm getting the same error as @btroop. Has anyone figured out how to use inline fragments on interface types with neo4j-graphql-js?

0 Likes

(William Lyon) #7

Hey @smkhalsa can you share your typedefs and the query? We use a couple of interface types in the tests for neo4j-graphql-js, for example here in the typedefs

andan example query that we run in the tests looks like this:

 {
    Movie(title: "River Runs Through It, A") {
      title
      ratings {
        rating
        User {
          ... on User {
            name
            userId
          }
        }
      }
    }
  }

Could be we aren't properly handling more complex uses of inline fragments?

0 Likes

(Smkhalsa) #8

Hey @William_Lyon, I created a gist with a minimal reproduction of the issue:

For the interface query, it seems to fail regardless of whether or not inline fragments are used. For some reason, the value of the __resolveType resolver is not getting passed back in the response.

For example, the query:

query {
  PlaylistInterface {
    id
    name
  }
}

results in the following error:

Abstract type Playlist must resolve to an Object type at runtime for field Query.PlaylistInterface with value { name: \"My Favorite Songs\", id: \"0ae75bb2-d7cd-4914-81ea-2d57594cbdfb\" }, received \"undefined\". Either the Playlist type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.

Also, the following union query...

query {
	PlaylistUnion {
    ... on PublicPlaylist {
      id
    }
    ... on UserPlaylist {
      id
    }
  }
}

... fails with this error:

schemaType.getFields is not a function
0 Likes

(Smkhalsa) #9

@William_Lyon have you had a chance to look at this? Interfaces and Unions are currently blockers for me. Let me know if there is anything I can do to help.

0 Likes