dotansimha / dotansimha/graphql-code-generator
Allow to have collapse whitespaces in query strings when documentMode: string is set
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
There might be a reason why this isn't already implemented, and if there is tell me, but:
It seems that it would be better if the whitespaces inside the generated strings that contain operations and fragments were collapsed and normalized.
For example, currently:
Given a .graphql file that contains the following query:
```graphql
query getCurrentUserInfo {
currentUser {
fullName
cartItemsCount
purchasedCoursesCount
specialRole
}
}
```
This would be the string version that gets generated by GraphQL Code Generator:
```javascript
export const GetCurrentUserInfoDocument = gql`
query getCurrentUserInfo {
currentUser {
fullName
cartItemsCount
purchasedCoursesCount
specialRole
}
}
`;
```
However, notice that all those double whitespaces, tabs, and of course line breaks are basically redundant.
It could instead generate:
```javascript
export const GetCurrentUserInfoDocument = gql`query getCurrentUserInfo { currentUser { fullName cartItemsCount purchasedCoursesCount specialRole } }`;
```
The 2 queries above have absolutely no functional difference, but if the line breaks, tabs, and double whitespaces are preserved, that adds to the bundle size of the app (if you're building a client-side web app) completely unnecessarily.
Not only that, but it's also just extra unnecessary bits sent over the network to the server every time when you use these strings to send requests to your intended GraphQL endpoint.
So, why not simply do a `.replace(/\s+/g, ' ').trim()` on these strings to get rid of all the unnecessary whitespace characters?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.