Closed shlomi84 closed 2 years ago
The simplest way to achieve this would be to add properties to the SQLAlchemy Movie
model:
@property
def genre_name(self):
return self.genre.genre
This property will become available in your schema.
If your Genre
entity only consists of a single field genre
, it would make sense to remove the genre Type and Model from your schema and implement the entity by adding the genre
field to all models having a relationship with the Genre
entity. However, this is a question of schema design & normalization.
Regarding your other question about the filtering library, you will need to implement custom filtering to be able to filter over relationships. Consider the is_admin_filter
from the library's readme as an example.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.
I'm working on a simple CRUD REST API to learn GraphQL & SqlAlchemy. I have a Movie table
that has its own properties (movie, budget, rating) but also 4 foreign keys (genre, studio, director, actors). my GraphQL types are simple
however, now when I query data, for the relationship tables, I have to replicate key, value pairs to get simple data
i.e. can I avoid using genre {genre}, studio {studio}, etc. and just retrieve genre directly inside the movie?
bonus question: adding filters to these relationships doesn't work I have a movie filter
that I can use like so
to have filtering available for my
movie
table. However, the filters only work for the fields defined in themovie
table itself, i.e.movie name
,rating
,budget
. Does anyone know how I can usegraphene-sqlalchemy-filter
to filter for all fields (director/actor/genre/studio)? It seems to me that GraphQL doesn't handle relationships all that well.