How to use the @graphql-inspector/core.coverage 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 / coverage / src / index.ts View on Github external
.action(async (options: {
                silent: boolean;
                write: string;
                deprecated: boolean;
            }) => {
                try {
                    const config = await loadProjectConfig({
                        extensions: [CoverageExtension]
                    });
                    const [schema, documents] = await Promise.all([
                        config.getSchema(),
                        config.getDocuments(),
                    ])
                    const results = coverage(schema, documents.map(doc => new Source(print(doc.document), doc.location)));
                    if (!options.silent) {
                        for (const typeName in results.types) {
                            const result = results.types[typeName];
                            console.info(`type ` + chalk.bold.underline(result.type.name.toString()) + ` x ${result.hits} {`)
                            for (const childName in result.children) {
                                const childResult = result.children[childName];
                                console.info(`  ` + chalk.bold(childName) + ` x ${childResult.hits}`)
                            }
                            console.info(`}`)
                        }
                    }
                    if (options.write) {
                        writeFileSync(join(process.cwd(), options.write), JSON.stringify(results, null, 2));
                    }
                } catch (e) {
                    reportError(e);
github kamilkisiela / graphql-inspector / packages / cli / src / commands / coverage.ts View on Github external
silent?: boolean;
    renderer?: Renderer;
    headers?: Record;
  },
) {
  const renderer = options.renderer || new ConsoleRenderer();
  const silent = options.silent === true;
  const writePath = options.write;
  const shouldWrite = typeof writePath !== 'undefined';

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

    if (!silent) {
      renderer.coverage(coverage);
    }

    if (shouldWrite) {
      if (typeof writePath !== 'string' || !isValidPath(writePath)) {
        throw new Error(`--write is not valid file path: ${writePath}`);
      }

      const absPath = ensureAbsolute(writePath);
      const ext = extname(absPath)
        .replace('.', '')
        .toLocaleLowerCase();

      let output: string | undefined = undefined;