This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Extend @oneToOne
to allow querying from both sides
#930
Labels
Comments
6 tasks
I think the approach taken in #964
will actually work. The main issue with it was specifying a `virtual: true`
annotation on the non-owning side of the 1:1 is a confusing concept not
really seen as a common pattern anywhere else.
It would make more sense to put an `owner: true` annotation on the owner
side of the relationship instead.
…On Wed, 18 Mar 2020 at 09:16, Enda ***@***.***> wrote:
Problem
This creates a user.details_id column in the database, and enables
relation data fetching when querying the User model.
@ModelType User {
id: ID!
"""
@OnetoOne key: 'details_id'
"""
details: UserDetails
}
Currently it is not possible to fetch the User relation when querying
UserDetails. This is because the oneToOne annotation is only applied to
one side. It should be possible to query from both sides making it a
bidirectional relationship (at the GraphQL level).
Proposal
Have a @OnetoOne field annotation which maps between the two types. This
field should be optional.
@ModelType User {
id: ID!
"""
@OnetoOne key: 'details_id', field: 'user'
"""
details: UserDetails
}
The oneToOne annotation in the opposite type should NOT have a key
attribute as this associates the field with a column in the table for this
type.
@ModelType UserDetails {
id: ID!
"""
@OnetoOne field: 'details'
"""
user: User
}
Challenges
- Validation might be tricky
- Following our existing patterns, fields should be generated.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#930>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZTDZNON3NF4MDXNZ6O2YTRICGNHANCNFSM4LOMHA5Q>
.
--
Enda Phelan
Software Engineer
Red Hat <https://www.redhat.com>
Communications House
Cork Road, Waterford, Ireland, X91 NY33
ephelan@redhat.com
<https://www.redhat.com>
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Problem
This creates a
user.details_id
column in the database, and enables relation data fetching when querying the User model.Currently it is not possible to fetch the User relation when querying
UserDetails
. This is because the oneToOne annotation is only applied to one side. It should be possible to query from both sides making it a bidirectional relationship (at the GraphQL level).Proposal
Have a
@oneToOne
field annotation which maps between the two types. This field should be optional.The oneToOne annotation in the opposite type should NOT have a
key
attribute as this associates the field with a column in the table for this type.Challenges
The text was updated successfully, but these errors were encountered: