Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active March 4, 2018 21:24
Show Gist options
  • Select an option

  • Save VitorLuizC/b2200cce7baca8a1f405325c177ba5e4 to your computer and use it in GitHub Desktop.

Select an option

Save VitorLuizC/b2200cce7baca8a1f405325c177ba5e4 to your computer and use it in GitHub Desktop.
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) ]
}
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
}
type User {
id: String
name: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment