contrib icon indicating copy to clipboard operation
contrib copied to clipboard

entgql: prefer edge schema over normal edge rel

Open tankbusta opened this issue 3 years ago • 7 comments

Edge Schema's are awesome and allow you to store metadata about a relationship (like when 2 user's first became friends) but the gql generator places both edges (friends and friendship) inside the node. However, the friendship edge looses the ability to filter. I noticed it creates the WhereInput fields inside the Go model but not GraphQL

https://github.com/ent/contrib/blob/7ed77ac9d07696176d7dfd80fd4cb3e8a1334582/entgql/internal/todo/ent/gql_where_input.go#L683-L689

This PR adds support for including the missing WhereInput fields in the schema and dropping the redundant edge on the nodes that have an edge schema. I would consider this a breaking change as it removes an edge that exists today but I struggled wondering how we could support backwards compatibility so I'm open to suggestions.

I will probably need to run the Code Generator on all the examples after we've discussed this a bit more in-depth.

tankbusta avatar Dec 31 '22 02:12 tankbusta

@a8m @giautm Are we able to get some 👀 on this? Looks like the CI failure is a GitHub rate limit issue

tankbusta avatar Jan 14 '23 02:01 tankbusta

@tankbusta would you mind if I push to your branch? Look like it contains a lot of unrelated changes from the master.

giautm avatar Feb 20 '23 23:02 giautm

Yes please go ahead! I tried to rebase with master but I apparently messed up 😟

tankbusta avatar Feb 22 '23 01:02 tankbusta

@tankbusta: Can you help me fix broken test cases?

Ps: To avoid conflicts when you pull the code, please delete the local branch and fresh pull.

giautm avatar Feb 22 '23 21:02 giautm

I'll take a look. Interestingly, these tests didn't fail when I submitted

tankbusta avatar Feb 23 '23 04:02 tankbusta

Alright, should be fixed! Sorry about that - the issue was I didn't run the code generator when I originally submitted it because I wanted it to be easier for y'all to review. When you ran the code generator, it broke the test due to change this PR makes.

The test is a perfect example of what this PR changes; allowing fields that are added on an edge schema to be queryable (and filtered on) via GraphQL

tankbusta avatar Feb 23 '23 05:02 tankbusta

Anything I can do @giautm to help move this along?

tankbusta avatar Mar 27 '23 23:03 tankbusta