How to use the @graphql-inspector/core.validate function in @graphql-inspector/core

To help you get started, we’ve selected a few @graphql-inspector/core 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 Urigo / graphql-cli / packages / commands / validate / src / index.ts View on Github external
strictDeprecated: boolean;
                noStrictFragments: boolean;
                apollo: boolean;
                maxDepth: number;
            }) => {
                try {

                    const config = await loadProjectConfig({
                        extensions: [ValidateExtension]
                    });
                    const [schema, documents] = await Promise.all([
                        config.getSchema(),
                        config.getDocuments(),
                    ]);
    
                    const results = validate(schema, documents.map(doc => new Source(print(doc.document), doc.location)), options);
                    for (const result of results) {
                        for (const error of result.errors) {
                            for (const location of error.locations) {
                                console.error(chalk.bold.underline(`${result.source.name}:${location.line}:${location.column};`));
                                console.error(` ` + chalk.red(`Error: ${error.message}`));
                            }
                        }
                        for (const error of result.deprecated) {
                            for (const location of error.locations) {
                                console.error(chalk.bold.underline(`${result.source.name}:${location.line}:${location.column};`));
                                console.error(` ` + chalk.red(`Error: ${error.message}`));
                            }
                        }
                    }
                    if (results.length === 0) {
                        console.info(`Documents are valid against the schema!`);
github kamilkisiela / graphql-inspector / packages / cli / src / commands / validate.ts View on Github external
apollo?: boolean;
    keepClientFields?: boolean;
    maxDepth?: number;
    renderer?: Renderer;
    headers?: Record;
  },
) {
  const renderer = options.renderer || new ConsoleRenderer();

  try {
    const schema = await loadSchema(schemaPointer, {
      headers: options.headers,
    });
    const documents = await loadDocuments(documentsPointer);

    const invalidDocuments = validateDocuments(schema, documents, {
      strictFragments: !options.noStrictFragments,
      maxDepth: options.maxDepth || undefined,
      apollo: options.apollo || false,
      keepClientFields: options.keepClientFields || false,
    });

    if (!invalidDocuments.length) {
      renderer.success('All documents are valid');
    } else {
      const errorsCount = countErrors(invalidDocuments);
      const deprecated = countDeprecated(invalidDocuments);

      if (errorsCount) {
        renderer.emit(
          `\nDetected ${errorsCount} invalid document${
            errorsCount > 1 ? 's' : ''