How to use the graphql-language-service-interface.getDiagnostics function in graphql-language-service-interface

To help you get started, we’ve selected a few graphql-language-service-interface 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 / packages / graphql-language-service / src / client.js View on Github external
function _getDiagnostics(
  filePath: string,
  queryText: string,
  schemaPath?: string,
): EXIT_CODE {
  try {
    // `schema` is not strictly requied as GraphQL diagnostics may still notify
    // whether the query text is syntactically valid.
    const schema = schemaPath ? generateSchema(schemaPath) : null;
    const resultArray = getDiagnostics(queryText, schema);
    const resultObject = resultArray.reduce((prev, cur, index) => {
      prev[index] = cur;
      return prev;
    }, {});
    process.stdout.write(JSON.stringify(resultObject, null, 2));
    return GRAPHQL_SUCCESS_CODE;
  } catch (error) {
    process.stderr.write(error);
    return GRAPHQL_FAILURE_CODE;
  }
}
github graphql / graphiql / packages / monaco-graphql / src / monaco-graphql-query.ts View on Github external
const diagnoseQueryValue = async (
  model: editor.ITextModel, // query or schema
  schema: GraphQLSchema,
): Promise<{
  valid: boolean;
  formattedDiagnostics: editor.IMarkerData[];
  diagnostics: any[];
}> => {
  let valid = false;
  const diagnostics = await getDiagnostics(model.getValue(), schema);
  const formattedDiagnostics: editor.IMarkerData[] = diagnostics.map(
    d => ({
      startLineNumber: d.range.start.line + 1,
      endLineNumber: d.range.end.line + 1,
      startColumn: d.range.start.character + 1,
      endColumn: d.range.end.character + 1,
      message: d.message,
      severity: MarkerSeverity.Error,
    }),
  );
  if (diagnostics.length < 1) {
    valid = true;
  }
  editor.setModelMarkers(model, 'linter', formattedDiagnostics);

  return {
github OneGraph / graphiql-explorer / src / App.js View on Github external
_queryError = (query: string) => {
    const {schema} = this.state;
    if (!schema) {
      return;
    }
    const errors = getDiagnostics(query, schema).filter(
      diag => diag.severity === 1,
    );
    console.log('errors', errors);
    if (errors.length) {
      return {
        errors: errors.map(error => ({
          message: error.message,
          locations: [
            {
              line: error.range.start.line + 1,
              column: error.range.start.character + 1,
            },
          ],
        })),
      };
    }
github imolorhe / altair / src / app / utils / codemirror / graphql-linter.ts View on Github external
CodeMirror.registerHelper('lint', 'graphql', (text: string, options: any) => {
  const schema = options.schema;
  try {
    const rawResults = getDiagnostics(text, schema);

    const results = rawResults.map(error => ({
      message: error.message,
      severity: SEVERITY[error.severity - 1],
      type: TYPE[error.source],
      from: CodeMirror.Pos(error.range.start.line, error.range.start.character),
      to: CodeMirror.Pos(error.range.end.line, error.range.end.character),
    }));

    return results;
  } catch (err) {
    debug.log(err);
    return [];
  }
});
github graphql / graphiql / packages / codemirror-graphql / src / lint.js View on Github external
CodeMirror.registerHelper('lint', 'graphql', (text, options) => {
  const schema = options.schema;
  const rawResults = getDiagnostics(text, schema);

  const results = rawResults.map(error => ({
    message: error.message,
    severity: SEVERITY[error.severity - 1],
    type: TYPE[error.source],
    from: CodeMirror.Pos(error.range.start.line, error.range.start.character),
    to: CodeMirror.Pos(error.range.end.line, error.range.end.character),
  }));

  return results;
});
github Quramy / ts-graphql-plugin / src / graphql-language-service-adapter.ts View on Github external
    const diagonosticsList = nodes.map(n => getDiagnostics(n.getText().slice(1, n.getWidth() - 1), this._schema));
    const result = [...errors];