Prisma1: Prisma client - chaining API after array

Created on 18 Sep 2018  路  3Comments  路  Source: prisma/prisma1

Is your feature request related to a problem? Please describe.
Prisma client does not emit the chaining API when we run into an array. The reason for that is we can have multiple solutions and we want the community to choose the API.

Describe the solution you'd like
Currently, the client just stops when the chaining API reaches an array.

In the new API, client.users().friends() can return an array of friends or an array of users with friends.

Similarly, client.users().book() can return an array of books or an array of users with book.

We can add to this API in an additive fashion.

Describe alternatives you've considered
Current alternative is to use the direct GraphQL, SQL feature of client.

kinfeature kindiscussion rf0-needs-spec areclient

Most helpful comment

Im a fan of the Objection.js style of eager loading. That framework uses a simple relation expression string to describe how to eagerly load relationships and which ones should/should not be loaded.

For example:

// Returns an array of users with the friends (user model) array populated
client.users().eager('friends')

// Returns an array of users with the books array populated 
client.users().eager('books') 

// Each person has the `.books` property populated with Books objects. 
// The `.friends` property contains the User's friends. 
// Each friend also has the `books` and `friends` relations eagerly fetched.
client.users().eager('[books, friends.[books, friends]')

I believe its simple yet powerful enough to easily define very complex relationships with ease.

All 3 comments

What if we pass an argument which controls which should be the "root" type?
E.g. client.users().book() returns an array of books and client.users().friends({root: true}).book() returns an array of friends with book.

Im a fan of the Objection.js style of eager loading. That framework uses a simple relation expression string to describe how to eagerly load relationships and which ones should/should not be loaded.

For example:

// Returns an array of users with the friends (user model) array populated
client.users().eager('friends')

// Returns an array of users with the books array populated 
client.users().eager('books') 

// Each person has the `.books` property populated with Books objects. 
// The `.friends` property contains the User's friends. 
// Each friend also has the `books` and `friends` relations eagerly fetched.
client.users().eager('[books, friends.[books, friends]')

I believe its simple yet powerful enough to easily define very complex relationships with ease.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MitkoTschimev picture MitkoTschimev  路  3Comments

ragnorc picture ragnorc  路  3Comments

AlessandroAnnini picture AlessandroAnnini  路  3Comments

thomaswright picture thomaswright  路  3Comments

schickling picture schickling  路  3Comments