Add mergeAST utility for merging multiple AST documents#4582
Open
veeceey wants to merge 1 commit intographql:16.x.xfrom
Open
Add mergeAST utility for merging multiple AST documents#4582veeceey wants to merge 1 commit intographql:16.x.xfrom
veeceey wants to merge 1 commit intographql:16.x.xfrom
Conversation
|
Someone is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel. A member of the Team first needs to authorize it. |
|
|
Contributor
Implements a `mergeAST` function that merges multiple DocumentNodes by combining selection sets of operations with matching names and types, recursively deduplicating fields with the same response name and arguments, and deduplicating fragment definitions. This addresses the long-standing need (issue graphql#1428) for a way to dynamically merge GraphQL queries, such as when resolvers need to ensure additional fields are present in requests to backend services. Closes graphql#1428
1697428 to
a29673b
Compare
Author
|
Thanks for the pointer @yaacovCR. I went through benjie's feedback on #4359 -- the DOS concern with mergeAST on unvalidated input is a fair point. I'll look into adding depth/complexity guards so it's safer to use on arbitrary documents. If the preference is still to keep this as a separate package first, I'm open to that too. Let me know how you'd like to proceed. |
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.
Summary
mergeASTutility function that merges multipleDocumentNodes into a single document by combining their selection setsCloses #1428
Motivation
As discussed in #1428, there are many use cases where dynamically merging GraphQL AST trees is needed, particularly:
The implementation follows the suggestion from @benjie to migrate/adapt the approach from GraphiQL's
merge-astutility, while providing a simpler, focused API that fits naturally alongside the existingconcatASTutility.API
Test plan
concatASTtests still pass🤖 Generated with Claude Code