How to use the graphql-language-service-utils.validateWithCustomRules function in graphql-language-service-utils

To help you get started, we’ve selected a few graphql-language-service-utils 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-interface / src / getDiagnostics.ts View on Github external
export function validateQuery(
  ast: DocumentNode,
  schema: GraphQLSchema | null | undefined = null,
  customRules?: Array,
  isRelayCompatMode?: boolean,
): Array {
  // We cannot validate the query unless a schema is provided.
  if (!schema) {
    return [];
  }

  const validationErrorAnnotations = mapCat(
    validateWithCustomRules(schema, ast, customRules, isRelayCompatMode),
    error => annotations(error, SEVERITY.ERROR, 'Validation'),
  );

  // Note: findDeprecatedUsages was added in graphql@0.9.0, but we want to
  // support older versions of graphql-js.
  const deprecationWarningAnnotations = !findDeprecatedUsages
    ? []
    : mapCat(findDeprecatedUsages(schema, ast), error =>
        annotations(error, SEVERITY.WARNING, 'Deprecation'),
      );

  return validationErrorAnnotations.concat(deprecationWarningAnnotations);
}
github graphql / graphiql / src / interfaces / getDiagnostics.js View on Github external
} catch (error) {
    const range = getRange(
      error.locations[0],
      queryText,
    );

    return [{
      severity: SEVERITY.ERROR,
      message: error.message,
      source: 'GraphQL: Syntax',
      range,
    }];
  }

  const errors: Array = schema ?
    validateWithCustomRules(schema, ast, customRules) : [];
  return mapCat(errors, error => errorAnnotations(error));
}