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
Kaqqao parsed directive arguments #1289
Kaqqao parsed directive arguments #1289
Conversation
…vailable to the data fetcher and more tests
@@ -21,7 +21,7 @@ | |||
/** | |||
* Prevents execution if the query complexity is greater than the specified maxComplexity. | |||
* | |||
* Use the {@link Function<QueryComplexityInfo, Boolean>} parameter to supply a function to perform a custom action when the max complexity | |||
* Use the `Function<QueryComplexityInfo Boolean>` parameter to supply a function to perform a custom action when the max complexity | |||
* is exceeded. If the function returns {@code true} a {@link AbortExecutionException} is thrown. | |||
*/ |
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.
This was stopping the command line version from building ebacuse of JavaDoc errors. Clearly our builds dont run the same profile of JavaDoc as I do. Not sure why
@@ -10,6 +11,7 @@ | |||
import static graphql.language.NodeUtil.directivesByName; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…ective-arguments # Conflicts: # src/main/java/graphql/VisibleForTesting.java # src/main/java/graphql/execution/ConditionalNodes.java
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.
Looks good overall. See my comments.
Also: I think a small end to end test with getting the directives from the DFE would be useful.
public Map<String, GraphQLDirective> getFieldDirectives(Field field, GraphQLSchema schema, Map<String, Object> variables) { | ||
GraphqlFieldVisibility fieldVisibility = schema.getFieldVisibility(); | ||
|
||
Map<String, GraphQLDirective> directiveMap = new HashMap<>(); |
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.
LinkedHasMap
|
||
@Override | ||
public Map<String, GraphQLDirective> getDirectives() { | ||
return new HashMap<>(directives); |
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.
LinkedHashMap
Gave this a bit more thought, and I think there should be a method that returns a map of parsed directives for any directive container. This is because one might need to get directives from a different field than the first (if I can do it if you agree on the approach. |
@andimarek - there is an integration test inside |
@kaqqao - what shape do you see for this? as in what is the key? The Field node? Should be not just combine them?? Do you need the AST nodes per set of directives?
|
@bbakerman The way I have it right now is that I return a new object (called I.e. it is a map of directives by name by location. The reason there's a Similarly to how only the current fields' directives are available, so are only the current fragments' directives (where a current fragment is a fragment to which a current field belongs). E.g. for a complex query such as: fragment Details on Book @timeout(afterMillis: 25) {
title
review @timeout(afterMillis: 5)" +
}
query Books @timeout(afterMillis: 30) {
books(searchString: "monkey") {
id
...Details @timeout(afterMillis: 20)
...on Book @timeout(afterMillis: 15) {
review @timeout(afterMillis: 10)
}
}
} The resulting map for the {
"FIELD": {
"timeout": [ {"afterMillis": 5}, {"afterMillis": 10} ]
},
"MUTATION": {},
"INLINE_FRAGMENT": {
"timeout": [ {"afterMillis": 15} ]
},
"FRAGMENT_DEFINITION": {
"timeout": [ {"afterMillis": 25} ]
},
"FRAGMENT_SPREAD": {
"timeout": [ {"afterMillis": 20} ]
},
"QUERY": {
"timeout": [ {"afterMillis": 30} ]
}
} For the Not sure if that's the way it should be, that's just the way I have it now... I then have some convenience methods on this new I don't really have a formed opinion yet on what should be in the library and how it should look... but I'm guessing in the background a structure keyed by the AST node will be necessary, while in the client-visible part it could be for the current context only, similar to the thing laid out above. This is of course if such a feature is desired in the first place, as it's rather complicated 😟 |
I added a comprehensive example and more rationale to the previous message, so if you're reading this from an email, please make sure to see the updated version of it. |
@kaqqao - yes I think you are right. We do need this and not what I have here. If you are happy to then can you please make a PR, unwind the directives support we have there (directives of the top level field) and put in your idea. The name My suggestion would be something like I would then see the DataFetchingEnvironemnt have a Wew would also need to capture these into ExecutionStepIngo so one can look up as the parent directives. |
please keep the DirectivesResolver code but change it to cater for the new collection of directives. Also please add tests for this new scenario |
I might back this change out since its 1/2 complete as is - not invaluable but not what we want as API know that I think more on it. |
This reverts commit 40027fc
This is related to #1229 - I could not work out how to push to @kaqqao original branch - so I made my own
The original issue is #1228
This takes his ideas and uses GraphqlDirective as the runtime object for directives and arguments rather than
Map<String,Map<String,Object>
representation.So now given
a data fetcher can do this