-
Notifications
You must be signed in to change notification settings - Fork 11
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
Minify GraphQL query #1367
Open
peteranny
wants to merge
1
commit into
master
Choose a base branch
from
chore/minify-query
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Minify GraphQL query #1367
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
看起來大概是 20B,感覺差別不大
那這樣我可能會想,這幾段 regular expression 會不會有意外的 replace 狀況是我們沒想到的
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.
或者我們也可以用別人寫好的來做,只是怕會不會覺得不想要那麼多套件
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.
感覺他的套件要 server 端配合><" 不過看到他推薦的這個也蠻有趣的:https://www.apollographql.com/docs/apollo-server/performance/apq/
不只減少傳輸量,還允許 CDN 把結果 cache (這題再說XD)
想問
.replace(/\s?([{}()])\s?/g, '$1')
這段要怎麼理解?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.
我沒發現他這個還包含代換 token ORZ
那這裡有個應該是單純 minify 的:https://github.com/drwpow/gqlmin
只是把
query(name: $name) { name }
變成query(name: $name){name}
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.
我用了另一條路徑,https://github.com/goodjoblife/GoodJobShare/compare/gqlmin
如果 graphql 可以 minify --> 那是不是我們 bundle (compile) 的時候就可以 minify
嘗試了這樣:
.gql
的文件原理:
當 webpack 遇到
*.gql
(test: /\.(graphql|gql)$/,
) 的時候,用 './graphql-loader.js' 去處理,
i.e. 把
*.gql
的內容,透過 gqlmin 處理,並回傳成 js code基本上
會變成
所以 `import facebookLogin from './facebookLogin.gql',就會像是 import 一個純文字,後續操作都不變
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.
或者這裡有個現成的 minify-graphql-loader 看可不可以直接套用
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.
這個 package 我發現太久以前了,他宣稱
但現在的 graphql-tag/loader 在 apollo 會將
*.graphql
的文字解析成 AST但 minify-graphql-loader 還在假設 graphql-tag/loader 只是幫忙處理
#import
的關鍵字所以,這個 package 會產生不預期的 minify 結果
(我設定的結果:master...minify-graphql-loader)