Last active
March 4, 2018 21:24
-
-
Save VitorLuizC/b2200cce7baca8a1f405325c177ba5e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const BLOCK = /\{[\w|\_|\s|\:|\!|\(|\)|\$]*\}/ | |
| /** | |
| * Get GraphQL block. | |
| * @param {string} [source] | |
| * @returns {string} | |
| */ | |
| const getBlocks = (source = '') => { | |
| const { '0': block, index } = BLOCK.exec(source) || {} | |
| if (!block) | |
| return [] | |
| const rest = source.substring(index + block.length) | |
| return [ block, ...getBlocks(rest) ] | |
| } |
This file contains hidden or 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
| query.substring(...[ query.indexOf('{'), query.indexOf('}') + 1 ]).replace(, '$1,').replace(/\s/g, '') | |
| function compressGraphQLBlocks (source) { | |
| const LINE_BREAK_STATEMENTS = /([^\{])[\r\n|\n|\r][^\}]/g | |
| const block = source.replace(LINE_BREAK_STATEMENTS, '$1,') | |
| } | |
| function getBlockIndex (source) { | |
| const open = source.indexOf('{') | |
| const close = | |
| } | |
| function getBlockIndexes (source, indexes) { | |
| const open = source.indexOf('{') | |
| const close = source.indexOf('}') | |
| const indexes = [ open, close ] | |
| return indexes | |
| } | |
This file contains hidden or 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
| type User { | |
| id: String | |
| name: String | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment