-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Extend relay relationships to support pivot meta on edge #871
Extend relay relationships to support pivot meta on edge #871
Conversation
I like to solution, I think it makes a ton of sense to do it this way as it also gives the possibility for directives on the pivot fields. I don't think the interface is a good idea as it adds limitations. I think good exception messages are better here. You could consider adding two directives called something like |
@olivernybroe Thanks for chiming in with your vote of confidence! Respectfully, I disagree with the idea of using directives to identify the node and cursor fields for a few reasons:
If anything, I'd be willing to omit an interface, but I'm not sure why. Lighthouse already has a Node interface, so it seems to make sense to add an Edge one as well to fit this scenario. |
I figured out where the models were so I was able to added a passing test. |
One thing I'm debating here is whether the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change overall, i am fine with the design of this.
Can you add a test to cover a missing edgeType?
I wouldn't mind the extra magic, the |
@spawnia Thanks for the feedback and adjustments! Going the "magic type" method sounds good to me. We'll just have to make sure it's documented. Should I add that to this PR? That negates the need to check for an invalid type, but I'm still thinking we should make sure it has the expected base structure. What are your thoughts on adding an Edge interface? interface Edge {
node: Node
cursor: String!
}
type TeamEdge implements Edge {
node: Team
cursor: String!
role: String!
} We could then make sure that the edge type implements that interface. If not, the way it's built now it wouldn't break anything if they simply omitted the cursor or node, but then it's not proper relay schema anymore. I'm inclined to be more strict since this section of schema is determined by Relay, not Lighthouse. |
Also, with regards to the magic edge type, should we continue to support the |
Let's allow both. I can see a need for having different edges pointing towards the same type, e.g. |
Let's enforce that. Can you add docs and link to the relevant part of the Relay spec? |
tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php
Outdated
Show resolved
Hide resolved
@spawnia Lots of work done here. Here's what's done:
There is one test that's failing, presently, and that's because in the |
tests/Integration/Schema/Directives/BelongsToManyDirectiveTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid tests and implementation, needs only a little polish (and docs)
Co-Authored-By: Benedikt Franke <benedikt@franke.tech>
Thanks for the review, @spawnia! Did you happen to see my question regarding loading the Node interface dynamically? #871 (comment) |
…dams/lighthouse into feature/add-edge-pivot-support
Sorry that I have to keep formatting. I think I've finally tweaked PhpStorm to match what StyleCI is looking for. |
I don't get what you want to change there, it worked previously? |
No worries, i am going to squash the commits anyway. |
The So we have a couple options:
Make sense? |
Makes complete sense, thanks for the breakdown. I agree that we might improve upon the point you mentioned in 1. For this PR, fixing 2. seems appropriate. Nice catch. |
Roger that! I went ahead and made an issue to keep track of this. We can discuss a better solution there and make a new PR for that. 👍 |
I think we should actually remove the Unfortunately, there is no way in the SDL to require a field named The bug relating to not finding the |
Ah, I see what you mean, the That said, if the |
... i have not thought of that. Brilliant! That validation could be run when enabling a config option such as |
@spawnia I removed the I like the direction you're going in #878. Let's make another PR that adds the configuration and validation. I really like the idea of having a "Relay mode" in Lighthouse so I'd be happy to help build that out. If you're cool with that let's merge this PR and then create the next PR that moves on from this code. |
Nicely done, thanks @JasonTheAdams |
Tasks remaining
Related Issue/Intent
Resolves #869
Changes
This extends the relate directives — specifically
@belongsToMany
— to include anedgeType
argument. This allows for supplying a custom edge (as opposed to only the generated one). For example:Then, when the edge is being resolved the node and cursor fields are handled as they are now, but any additional field is retrieved as pivot data.
This takes advantage of the relay edge type which is intended to reflect the relationship meta between entities. In the world of Laravel this is exactly what pivot data is. Going this route also allows for supporting further control of the edge with directives and such.
Breaking changes
This should not break anything and be fully backwards compatible.
Further Thoughts
I'm considering adding an
Edge
interface so custom edges can implement it. It could even be that the interface is explicitly required.