Datamodelling: many to many with/without join table


#1

I noticed you can define many to many relationships in 2 ways:

1. indirect with a “join table” (user)-(favoriteMovie)-(movie)

type User {
id: ID!
favoriteMovies: [FavoriteMovie!]! @relation(name: "UserToFavoriteMovie")
}
type FavoriteMovie {
  id: ID!
  user: User! @relation(name: "UserToFavoriteMovie")
  movie: Movie! @relation(name: "MovieToFavoriteMovie")
}
type Movie {
  id: ID! 
  favoriteMovies: [FavoriteMovie!]! @relation(name: "MovieToFavoriteMovie")
}

2. directly (user)-(movie) with relation named "FavoriteMovies

type User {
    id: ID!
    moviesFavorite: [Movie!]! @relation(name: "FavoriteMovies")
}
type Movie {
    id: ID! 
    usersFavorite: [User!]! @relation(name: "FavoriteMovies")
}

In which cases would you choose direct or indirect?
My first thought would be:
Direct, if the nr of joins are going to be within reasonable bounds eg. (country flags)-(colors in flag)-(colors)
Indirect, if nr of joins can grow very large eg. (users)-(like)-(blockbusterMovie)

Any other criteria to keep in mind?


#2

Behind the scenes, Graphcool should be implicitly converting your “direct” relationships to join tables. I’d use an indirect relationship if the relationship itself needs data associated with it - for example, the case posted here: Defining relation-specific data