How to use the graphql-language-service-parser.onlineParser function in graphql-language-service-parser

To help you get started, we’ve selected a few graphql-language-service-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql / graphiql / src / interfaces / getAutocompleteSuggestions.js View on Github external
function runOnlineParser(
  queryText: string,
  callback: callbackFnType,
): ContextToken {
  const lines = queryText.split('\n');
  const parser = onlineParser();
  let state = parser.startState();
  let style = '';

  let stream: CharacterStream = new CharacterStream('');

  for (let i = 0; i < lines.length; i++) {
    stream = new CharacterStream(lines[i]);
    // Stop the parsing when the stream arrives at the current cursor position
    while (!stream.eol()) {
      style = parser.token(stream, state);
      const code = callback(stream, state, style, i);
      if (code === 'BREAK') {
        break;
      }
    }
github graphql / graphiql / packages / graphql-language-service-interface / src / getAutocompleteSuggestions.ts View on Github external
function runOnlineParser(
  queryText: string,
  callback: callbackFnType,
): ContextToken {
  const lines = queryText.split('\n');
  const parser = onlineParser();
  let state = parser.startState();
  let style = '';

  let stream: CharacterStream = new CharacterStream('');

  for (let i = 0; i < lines.length; i++) {
    stream = new CharacterStream(lines[i]);
    while (!stream.eol()) {
      style = parser.token(stream, state);
      const code = callback(stream, state, style, i);
      if (code === 'BREAK') {
        break;
      }
    }

    // Above while loop won't run if there is an empty line.
github graphql / graphiql / packages / codemirror-graphql / src / utils / runParser.js View on Github external
export default function runParser(sourceText, parserOptions, callbackFn) {
  const parser = onlineParser(parserOptions);
  const state = parser.startState();
  const lines = sourceText.split('\n');

  lines.forEach(line => {
    const stream = new CharacterStream(line);
    while (!stream.eol()) {
      const style = parser.token(stream, state);
      callbackFn(stream, state, style);
    }
  });
}
github graphql / graphiql / packages / codemirror-graphql / src / mode.js View on Github external
CodeMirror.defineMode('graphql', config => {
  const parser = onlineParser({
    eatWhitespace: stream => stream.eatWhile(isIgnored),
    lexRules: LexRules,
    parseRules: ParseRules,
    editorConfig: { tabSize: config.tabSize },
  });

  return {
    config,
    startState: parser.startState,
    token: parser.token,
    indent,
    electricInput: /^\s*[})\]]/,
    fold: 'brace',
    lineComment: '#',
    closeBrackets: {
      pairs: '()[]{}""',
github graphql / graphiql / packages / codemirror-graphql / src / variables / mode.js View on Github external
CodeMirror.defineMode('graphql-variables', config => {
  const parser = onlineParser({
    eatWhitespace: stream => stream.eatSpace(),
    lexRules: LexRules,
    parseRules: ParseRules,
    editorConfig: { tabSize: config.tabSize },
  });

  return {
    config,
    startState: parser.startState,
    token: parser.token,
    indent,
    electricInput: /^\s*[}\]]/,
    fold: 'brace',
    closeBrackets: {
      pairs: '[]{}""',
      explode: '[]{}',
github Mayank1791989 / gql / src / schema / _shared / SchemaParser.js View on Github external
constructor() {
    this._parser = onlineParser({
      eatWhitespace: (stream) => stream.eatWhile(isIgnored),
      lexRules: LexRules,
      parseRules: ParseRules,
    });
  }