Can we please tree shake away graphql
from final bundle?
#1905
-
I'm using the amazing codeden's It works amazingly! Specifically, using the configuration below I can also generate But I see that urql anyway inserts the Can we create an option to take it off? What is it for? My query is compiled at compile time. Can we do tree shaking of that heavy library? I have only a few queries and the final bundle is big already for other reasons and the device it has to run on is a low-low-low end one. Configschema: ./schema.graphql
generates:
./types.ts:
documents: ./**/*.graphql
plugins:
- typescript-urql
config:
documentMode: documentNode Generated codeimport { DocumentNode } from "graphql";
// ...
export const MyDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "query",
// ...
},
],
} as unknown as DocumentNode; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
It's simply not possible, no, and we've talked about this before in several issues; This basically comes down to leftover dependencies, in other words, we have several files that cannot be removed entirely, namely:
Now, given that, what's the actual impact;
Careful here! 😃 This is simply not an accurate statement, since an absolute number on its own isn't representative of the impact of code. If you're measuring unminified code especially, you'll see numbers that don't tell you anything about what's being delivered to the user. So, strictly speaking we always measure in minzipped (minified + gzipped) as this is a consistent number that gives us an idea of "relative impact". So, in other words, what's the impact of Well, luckily, I've got an isolated build of just that. Our imports of interest here are: export { valueFromASTUntyped } from "graphql/utilities/valueFromASTUntyped.mjs";
export { GraphQLError } from "graphql/error/GraphQLError.mjs";
export { Kind } from "graphql/language/kinds.mjs";
export { parse } from "graphql/language/parser.mjs";
export { print } from "graphql/language/printer.mjs";
export { visit } from "graphql/language/visitor.mjs"; The minzipped size of this is Now, the real question here apart from the technical requirements and details above though is probably "But what do we want to do about this?" And the answer is simple, we don't want to require users to precompile queries and we don't want To that end what I'm currently working on is a "graphql lite" package, which will continue to function normally and as expected in front-end applications when it's swapped into the build process or codebase. This is codenamed "graphql-web-lite" and would bring the Now, the closing advice here for now is, if you're precompiling, you can already alias
Well, I'd really doubt that 3.2/3.5% (albeit, measured with the above problems, I've mentioned) is the big driving factor here, unless all the other dependencies and modules are <3% each. But yea, if you really need to squeeze some size out here, do the aliasing trick, and in the future we'll have a package that we'd like to recommend people to alias in their frontend build process to reduce the impact of the |
Beta Was this translation helpful? Give feedback.
It's simply not possible, no, and we've talked about this before in several issues; This basically comes down to leftover dependencies, in other words, we have several files that cannot be removed entirely, namely:
graphql/language/parser
) cannot be removed. As@urql/core
supports both raw strings and precompiled query documents, it must always have the parser available.graphql/language/printer
) cannot be removed, since it must be used (no matter whether we have raw strings or precompiled queries) to stringify the query document that is sent to the API. This cannot be skipped as we must parse the query, since it's a guarantee to have it available in unstring…