Replies: 1 comment 1 reply
-
Most of the AST code is in
Can you tell me more about why you want to know if fragments reference fragments? Whats the use case for knowing this and what would you do if you had that list? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Create an
AstHelper
class with well defined and tested methods to perform common operations on the abstract syntax tree.Methods
getRecursivelyReferencedFragments()
- Given a node in the AST, return all fragments referenced by the node.detectDeprecatedFields()
- Given a query and a reference to a graphql schema, detect if the query references any fields marked deprecated by the schema.Implementation
getRecursivelyReferencedFragments()
We don't want to traverse the whole tree here so we will use a modified depth first search. In pseudo code:
detectDeprecatedFields()
Detecting deprecated fields is more straightforwards. We can use the QueryTraverser visitor pattern. In (mostly) pseudo code:
Testing
We will write unit tests in Groovy to achieve 100% code coverage
AstHelper
class. I am unaware of any other testing requirements, please let me know if I am missing anything.Extension
We can evolve this class in the future to add more functionality. For example:
normalizeExecutableQuery()
- Given a query, return a normalized version. his represents the AST collapsed into its eventual "field" with schema types and so on all resolved.Open Questions
Where in the directory structure should this class live?
My initial thought is
src/main/java/graphql/AstHelper.java
Beta Was this translation helpful? Give feedback.
All reactions