GraphQL Issue using Interfaces on Relationship Types with Properties
![iuviene iuviene](https://community.neo4j.com/legacyfs/online/1X/bc14f9894a72bfde8caf169a8cdce32c54cb4f35.png)
10-17-2020 11:46 AM
Hi. I have been successfully defining schemas that use relationships with interfaces but I just tried to do this with a relationship type that has properties and then the schema won't validate.
Example:
Using the schema from the docs with: Person, User, and Actor, etc I want to include the friends relationship as part of the Person Interface but attach a since property to the friends relationship. My approach was this:
interface Person {
id: ID!
name: String
friends: [Friend]
}
type Friend @relation (name: "FRIEND_OF") {
from: Person
to: Person
since: Date
}
type User implements Person {
id: ID!
name: String
friends: [Friend]
screenName: String
reviews: [Review] @relation(name: "WROTE", direction: OUT)
}
type Actor implements Person {
id: ID!
name: String
friends: [Friend]
movies: [Movie] @relation(name: "ACTED_IN", direction: OUT)
}
type Movie {
movieId: ID!
title: String
}
type Review {
rating: Int
created: DateTime
movie: Movie @relation(name: "REVIEWS", direction: OUT)
}
When I run this the schema validator complains that the type User is implementing the Friend relationship but that Friend is defined as having the to and from types as Person. I assumed the validator would resolve the use of types implementing interfaces for these fields. Is there another way to handle this or am I missing something?
Thanks,
Nick
- Labels:
-
GraphQL-and-GRANDstack
![MuddyBootsCode MuddyBootsCode](https://community.neo4j.com/legacyfs/online/2X/7/7b1e57bcf619a1531fb53f6cc4e0cb83c5c27f06.jpeg)
10-19-2020 02:09 PM
You may have to define the relationship as a field on the interface like:
interface Person {
id: ID!
name: String
friends: [Friend] @relation(name: "FRIEND_OF", direction: OUT/IN)
}
Just like you have for your Review relationship. Not sure if that will work but it might.
![](/skins/images/DCEE200A061243D9CDD43EC39D921EED/responsive_peak/images/icon_anonymous_message.png)