Allows defining custom directives to modify runtime query execution#1687
Closed
matthewowen wants to merge 2 commits intormosolgo:masterfrom
Closed
Allows defining custom directives to modify runtime query execution#1687matthewowen wants to merge 2 commits intormosolgo:masterfrom
matthewowen wants to merge 2 commits intormosolgo:masterfrom
Conversation
Owner
|
I love this idea! Thanks for sharing your sample code too. Personally, I've shifted my thoughts about execution to a complete rewrite, although I haven't actually hacked on it since my initial spike at #1394 . Custom directives is definitely a requirement for a new executor. I was hoping to have made more progress on that by now but, uh, ... other things ... took priority at work 😆 That's how it goes sometimes. I can't really pitch in on this one right now, but if you're able to get something working with minimal overhead, I'm definitely open to adding it. |
772141f to
6002d2f
Compare
8db255c to
cf1a267
Compare
cf1a267 to
c0e5e08
Compare
Owner
|
I'm not going to merge this branch in particular, but keep an eye on #1394 where we'll have custom directives of one sort or another, thanks again for your work here! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm opening this PR as an exploratory suggestion for custom directives: at Flexport we're using this library and have a bunch of use cases that custom directives could really help with.
This PR doesn't yet have specs or docs and certainly isn't complete, but I wanted to throw it out there as at least a strawman for a possible direction for this feature: from reading the associated issues, it seems that custom directives has stalled out a little?
The high level is that we allow a directive to define specific hooks, and at the appropriate points in parsing and executing a query we can then call into those hooks. In this PR, we allow directives to define a hook to be called at query execution time, such that when when resolving a field the directive is inserted and can return some other value, call into the original resolve proc, modify the arguments to the inner resolve proc, etc.
A minimal example of use would be as follows:
In this case, given a query like
we would receive
But with a query like
we would receive
I think an approach that allows defining hook points on directives would be a pretty powerful way to provide flexibility. I would imagine that the two key points one would want to hook in at would be during AST generation (as skip and include do) and during query execution (as I've implemented here). I think we'd also want to ensure that these hook points are appropriately implemented for fragments as well as fields.
I guess the high level question I have here: do you consider this to be a plausible approach, and would you be receptive to me pursuing it further? And if so, what are the areas you'd like to see focused on (setting aside obvious details here like documentation and testing)?