Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Extend @oneToOne to allow querying from both sides #930

Open
craicoverflow opened this issue Mar 18, 2020 · 1 comment
Open

Extend @oneToOne to allow querying from both sides #930

craicoverflow opened this issue Mar 18, 2020 · 1 comment
Labels

Comments

@craicoverflow
Copy link

Problem

This creates a user.details_id column in the database, and enables relation data fetching when querying the User model.

@model
type 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.

@model
type 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.

@model
type UserDetails {
  id: ID!
  """
  @oneToOne field: 'details'
  """
  user: User
}

Challenges

  • Validation might be tricky
  • Following our existing patterns, fields should be generated.
@craicoverflow
Copy link
Author

craicoverflow commented Jun 29, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant