In the lesson " GraphQL Relationships" there are (at least I suppose so) errors both in "Type definition" and GraphQL query.
Here the code that works for me: Type definition
type Movie {
title: String!
year: Int
plot: String
imdbRating: Float
countries: [String]
languages: [String]
poster: String
revenue: Int
budget: Int
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
genres: [Genre!]! @relationship(type: "IN_GENRE", direction: OUT)
}
type User {
userId: ID!
name: String!
}
type Actor {
name: String
actedInMovies: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
type Genre {
name: String!
movies: [Movie!]! @relationship(type: "IN_GENRE", direction: IN)
}
type ActedIn @relationshipProperties {
role: String
}
Query
query MyQuery {
movies (where: {title: "Matrix, The"}) {
title
actors {
name
}
actorsConnection {
edges {
properties {
role
}
}
}
genres {
name
}
}
}
After I change the "interface" to "type" as Andrea suggested, the error goes away,
but is it OK not to use interface here?
Can I understand that we do not have to use interface if we do not need to reuse the code (in this case "Rated"), as interface shines in the reusability?
Since it relates directly to the property of the relationship directive there should be no need for another type to implement it, which is why we changed it to a type.
As you say, interfaces should be used to structure implementing types. I recommend the interfaces and unions section on the GraphQL learn pages.