-
Notifications
You must be signed in to change notification settings - Fork 2k
canonicalize/normalize document utility #2342
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
Comments
@micimize Thanks for opening this issue 👍 query ($oneCondition: Boolean, $anotherCondition: Boolean) {
someField @include(if: $oneCondition)
someField @include(if: $anotherCondition)
} After merge you will get: query ($oneCondition: Boolean, $anotherCondition: Boolean) {
someField @include(if: $oneCondition) @include(if: $anotherCondition)
} Which is invalid since What is your use case for the |
hmm, true. We could just add directives that to the unique condition. My use case is data class generation, but there are other potential use-cases, like getting the correct cache hit on the client for As an aside, it feels a bit counter intuitive that {
name @include(if: false)
name @include(if: true)
} is valid, but not { name @include(if: false) @include(if: true) } |
@micimize There is
So without inlining fragments, we can only remove fields at the same level that don't have directives applied to them. {
foo
bar
foo
} Can you think of any other normalization step that doesn't affect the query execution? |
@IvanGoncharov I was more talking about developer-facing formatting like prettierjs (though this would only be for ASTs). I guess this makes more sense as a collection of smaller utilities:
This way implementors/users can decide for themselves if things like field order, distinct fragment definition, etc. are part of "query identity", eschewing the issue of whether or not the utilities are fully spec compliant. To distill my position:
I think the real validation of this idea is if it would be desirable for persisted query implementors to offer some subset of |
A user of GraphQL-core had a similar request. In his case, he wanted to normalize the order of arguments in particular by sorting them. So we are also thinking about something similar to |
@Cito Thanks for excellent example with an order of args. |
Feature requests
Would a
canonicalize(node)
ornormalize(node)
utility be a desirable feature? I started working on one to simplify some aspects of ast-based code generation, though all it does right now is merge duplicate fieldsI don't think it should inline fragments or anything like that (though maybe conditionally). Maybe we'd need to spec out exactly what a canonical document form would actually look like though
The text was updated successfully, but these errors were encountered: