-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Compact GraphQL query text #3983
Conversation
0e15af7
to
79bd3d5
Compare
This seems reasonable to me! I'd love to see some fixture tests which validate this behavior. I think a set of fixture tests similar to the three sets we have here: https://github.com/facebook/relay/tree/main/compiler/crates/graphql-text-printer/tests. Ideally we could have tests that look like this (this would be the implementation of the
I think there's one issue here: Which is that we don't yet implement the location agnostic equality test for all IR node types. Maybe you could look into how difficult it would be to add the trait for the missing types? |
9916c24
to
4f49252
Compare
@@ -405,6 +409,16 @@ impl LocationAgnosticPartialEq for Argument { | |||
} | |||
} | |||
|
|||
impl LocationAgnosticPartialEq for Option<&Argument> { |
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 impl should be redundant from Option<T>
, but I couldn't work out the right ref incantation
} else { | ||
self.next_line(false) | ||
} | ||
} |
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.
These separator utils are the main change here, they have conditional behaviour in them which avoids the need for self.options.compact
checks everywhere
|
||
fn print_type(&mut self, type_: &TypeReference) -> FmtResult { | ||
write!(self.writer, "{}", self.schema.get_type_string(&type_)) | ||
} |
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.
I pulled out a few duplicated prints as I found them
query Test{aliasOfFoo:username(name:"val1")@customDirective(level:2){emailAddresses,firstName(if:false,unless:false)},...FX} | ||
|
||
fragment FX on Query{aliased:username(name:"argVal"){thin:emailAddresses}} |
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 test captures the same behaviour as GraphQLJava graphql-java/graphql-java#2872
compiler/Cargo.lock
Outdated
@@ -1144,9 +1145,9 @@ dependencies = [ | |||
|
|||
[[package]] | |||
name = "once_cell" | |||
version = "1.8.0" | |||
version = "1.12.0" |
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.
Stale from ee99ea4
176f4f8
to
4bf7eb9
Compare
@@ -8,6 +8,9 @@ | |||
"editor.defaultFormatter": "esbenp.prettier-vscode" | |||
}, | |||
"prettier.enable": true, | |||
"rust-analyzer.rustfmt.extraArgs": [ | |||
"+nightly" | |||
], |
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.
Additional to #3959, this helps contributors use the same setup as the github rust lint action
@@ -175,16 +175,16 @@ dependencies = [ | |||
|
|||
[[package]] | |||
name = "clap" | |||
version = "3.1.18" | |||
version = "3.2.8" | |||
source = "registry+https://github.com/rust-lang/crates.io-index" |
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.
@captbaritone I implemented those fixture tests. Does this look alright to you? |
0c59dfb
to
c06b0b5
Compare
Wires the pre-existing `compact` printing into a feature flag. Additionally disables indenting when printing in compact form
@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@tomgasson Sorry I lost track of this. I'll work on importing/rebasing now. |
Hey @tomgasson — this PR looks great! Thanks for taking it on. I'm in the process of reviewing it now. We'll fix it up internally and land it, thank you for doing this work!! And thank you for adding a bunch of fixtures, that makes it a lot easier to review. Some questions for you:
|
I think that is legal. Looks like an oversight
I think it probably is. The code to iterate through the conditions' selections should probably share more with the It will be hard to test this one, because I believe a And sometimes combined via a transform, but I can't work out how to trigger that behavior |
Okay, cool. I guess a future person can figure out what's going on with that condition code, and clean it up. I'll remove the space internally, no need to change the PR. Thanks! |
We noticed that some of our query text contains a significant amount of unnecessary whitespace. Unlike server->client requests, client->server requests generally aren't compressed and would require a js compression library to do so.
This PR adds a feature flag to compact the query text. I saw the pre-existing
compact
mode wasn't wired up to anything, so I've co-opted it.As an example of the benefit, we have one query which this shrinks from
84kb
to31kb
We're slowly making our way to persisted queries, but this is an immediate improvement and I imagine we're not the only ones who will benefit from smaller network payloads
Happy to make this a config rather than a feature flag, if you don't think this should be the default output