You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm just starting out with GraphQL and want to implement a basic example of two federated services. For that I defined a the following data structure:
a Tenant has an id and a name
a Tenant has many Users (the ones with the tenant's id in user.tenant_id)
a User has an id, first_name, last_name and a tenant_id
a User belongs to a Tenant (the tenant with an id of user.tenant_id)
I only got one direction of the relation to work (User belongs to a Tenant) and I don't know how to implement the other direction. My code looks like this
As far as I understand GraphQL, for a query like this query Example { users { tenant { ... } } } all users are fetched first and then the tenant related to every user is fetched by calling the function find_tenant_by_id of the users-service.
For the other direction of this relation there must be a way of fetching all users by their tenant_id but I couldn't find documentation/example covering this case nor do I really understand what the SQL should look like for this relation.
I'm very grateful for any kind of help. Thank you very much in advance :)
The text was updated successfully, but these errors were encountered:
biwecka
changed the title
How to fetch both directions of one-to-many relation in federated graph
How to handle both directions of one-to-many relation in federated graph
Mar 4, 2024
Hi,
I'm just starting out with GraphQL and want to implement a basic example of two federated services. For that I defined a the following data structure:
Tenant
has anid
and aname
Tenant
has manyUsers
(the ones with the tenant'sid
inuser.tenant_id
)User
has anid
,first_name
,last_name
and atenant_id
User
belongs to aTenant
(the tenant with anid
ofuser.tenant_id
)I only got one direction of the relation to work (
User
belongs to aTenant
) and I don't know how to implement the other direction. My code looks like thisAs far as I understand GraphQL, for a query like this
query Example { users { tenant { ... } } }
all users are fetched first and then the tenant related to every user is fetched by calling the functionfind_tenant_by_id
of theusers-service
.For the other direction of this relation there must be a way of fetching all users by their
tenant_id
but I couldn't find documentation/example covering this case nor do I really understand what the SQL should look like for this relation.I'm very grateful for any kind of help. Thank you very much in advance :)
The text was updated successfully, but these errors were encountered: