Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider if @column for specifying foreign key can be confusing #699

Open
ramnivas opened this issue Apr 6, 2023 · 0 comments
Open

Consider if @column for specifying foreign key can be confusing #699

ramnivas opened this issue Apr 6, 2023 · 0 comments
Labels
Milestone

Comments

@ramnivas
Copy link
Contributor

ramnivas commented Apr 6, 2023

Currently, we use @column to designate both: the column in the current table and the column in the foreign table (inferred based on the cardinality), but this can be confusing. For example, in the snippet below, one may think that the venueid is a column in Venue.

@postgres
service ConcertService {
  type Concert {
    ...
    @column("venue_id") venue: Venue
    @column("fallback_venue_id") fallback: Venue
  }

  type Venue {
    ...
    @column("venue_id") concerts: Set<Concert>?
    @column("fallback_venue_id") fallback_concerts: Set<Concert>?
  }
}

We could introduce @foreign_column to demarcate self columns from those in another table:

@postgres
service ConcertService {
  type Concert {
    ...
    @column("venue_id") venue: Venue
    @column("fallback_venue_id") fallback: Venue
  }

  type Venue {
    ...
    @foreign_column("venue_id") concerts: Set<Concert>?
    @foreign_column("fallback_venue_id") fallbackConcerts: Set<Concert>?
  }
}

Alternatively, we can introduce a @relation annotation to connect fields from two different types:

@postgres
service ConcertService {
  type Concert {
    ...
    @relation(Venue.concerts) venue: Venue
    @relation(Venue.fallbackConcerts) fallback: Venue
  }

  type Venue {
    ...
    @relation(Concert.venue) concerts: Set<Concert>?
    @relation(Concert.fallback) fallbackConcerts: Set<Concert>?
  }
}

Developers can still specify @column to specify the column, but only for columns that actually exist in the surrounding table:

@postgres
service ConcertService {
  type Concert {
    ...
    @relation(Venue.concerts) @column("v_id") venue: Venue // column name explicit
    @relation(Venue.fallbackConcerts) fallback: Venue // column name inferred here
  }

  type Venue {
    ...
    @relation(Concert.venue) concerts: Set<Concert>?
    @relation(Concert.fallback) fallbackConcerts: Set<Concert>?
  }
}
@ramnivas ramnivas added the P1 label May 18, 2023
@ramnivas ramnivas added this to the M2 milestone Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant