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

Populated Field aka pseudo Relationship and reverse Relationship #2905

Closed
gautamsi opened this issue May 5, 2020 · 4 comments
Closed

Populated Field aka pseudo Relationship and reverse Relationship #2905

gautamsi opened this issue May 5, 2020 · 4 comments

Comments

@gautamsi
Copy link
Member

gautamsi commented May 5, 2020

Feature request

I see that we have used relationship based on Id only. This may not be suitable in all situations probably due to not wanting to populate the database with id everywhere.

If you use Relationship field you can have the relationship configured 1 sided or both sided, in 1 sided there is no way to query them in GraphQL, for example you have author field on Post but there is no Relationship on User side where author is. There is no way currently access Post for user as a field on User.

I was thinking about a Populate Field which would work similar to mongoose populate option. We create a field and provide ref to populate the field over graphql.

Advantage:

  • this will not generate another database field
  • only visible in GraphQL which would be invisible if read access is denied.
  • it would help in creating less number of queries when working on background jobs which has unrestricted access.
  • this will also be helpful in loading data from reverse Relationship

Describe the solution you'd like

Create a Populate field which would auto fill the data when requested in graphql query

postListFields = {
  reviewId: { type: text } // this may be flagged by some internal/external process based on some criteria but I don't want to save is as relationship
};

ReviewQueueListFields = {
// ... more field for review list
  spamCheckId: { type: text },
  post: { type: Populate, ref: 'Post', refField: 'reviewId', matchField: 'spamCheckId',  many: true | false }
}

this post field is not saved in database but accessible over graphql internally. similar to virtual field it will not be searchable or orderable etc..

I think we can not do mongoose like populate which would replace the field with content from source due to dynamic schema being involved with GraphQL but this Populate field may work.

this will be more powerful to gather data based on nested populate fields reducing the backend overhead of multiple queries.

Reverse Relationship was possible in v4 where you could populate field from 1 sided Relationship

User.relationship({ path: 'posts', ref: 'Post', refPath: 'author' });

in above example actual Relationship was configured in Post list with author field containing id of User.

Describe alternatives you've considered

Relationship field is out of question, you need to do multiple queries in back end process when needing these values.

@MadeByMike
Copy link
Contributor

I'm really struggling to understand this. Do you think you could phrase this in terms of a use-case with a real example of how it should work and what benefit it offers?

@gautamsi
Copy link
Member Author

gautamsi commented Jul 7, 2020

I can try make it simple with Blog demo example.

For example I want to add a featuredPost field for User. here I have Post.slug as unique field, I want to store slug value in featuredPost field rather than the id of the post.

this will also help in Relationship GraphQL queries where I can use conenct: { slug: 'post-slug' } } rather than first fetch the id and then connect that id.

@stale
Copy link

stale bot commented Nov 5, 2020

It looks like there hasn't been any activity here in over 6 months. Sorry about that! We've flagged this issue for special attention. It wil be manually reviewed by maintainers, not automatically closed. If you have any additional information please leave us a comment. It really helps! Thank you for you contribution. :)

@stale stale bot added the needs-review label Nov 5, 2020
@bladey
Copy link
Contributor

bladey commented Apr 8, 2021

Keystone 5 has officially moved into active maintenance mode as we push towards the next major new version Keystone Next, you can find out more information about this transition here.

In an effort to sustain the project going forward, we're cleaning up and closing old issues such as this one. If you feel this issue is still relevant for Keystone Next, please let us know.

@bladey bladey closed this as completed Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants