How to use the @graphql-inspector/core.diff 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 kamilkisiela / graphql-inspector / packages / cli / src / commands / diff.ts View on Github external
? options.rule
          .map(
            (name): Rule => {
              const rule = resolveRule(name);

              if (!rule) {
                renderer.error(`\Rule '${name}' does not exist!\n`);
                return process.exit(1);
              }

              return rule;
            },
          )
          .filter(f => f)
      : [];
    const changes = diffSchema(oldSchema, newSchema, rules);

    if (!changes.length) {
      renderer.success('No changes detected');
    } else {
      renderer.emit(
        `\nDetected the following changes (${changes.length}) between schemas:\n`,
      );

      changes.forEach(change => {
        renderer.emit(...renderChange(change));
      });

      if (hasBreaking(changes)) {
        const breakingCount = changes.filter(
          c => c.criticality.level === CriticalityLevel.Breaking,
        ).length;
github Urigo / graphql-cli / packages / commands / diff / src / index.ts View on Github external
.action(async (baseSchemaPtr: string) => {
        try {

          const config = await loadProjectConfig({
            extensions: [DiffExtension]
          })
          if (!baseSchemaPtr) {
            const diffConfig = await config.extension('diff');
            baseSchemaPtr = diffConfig.baseSchema || 'git:origin/master:schema.graphql';
          }
          const [baseSchema, currentSchema] = await Promise.all([
            config.loadSchema(baseSchemaPtr),
            config.getSchema(),
          ]);
          const changes = diff(baseSchema, currentSchema);
  
          if (!changes.length) {
            console.log(logSymbols.success, 'No changes detected');
          } else {
            console.warn(logSymbols.warning, `Detected the following changes (${changes.length}) between schemas:\n`);
  
            changes.forEach(change => {
              console.log(...renderChange(change));
            });
  
            if (hasBreaking(changes)) {
              const breakingCount = changes.filter(c => c.criticality.level === CriticalityLevel.Breaking).length;
              throw `Detected ${breakingCount} breaking change${breakingCount > 1 ? 's' : ''}\n`;
            } else {
              console.log(logSymbols.success, 'No breaking changes detected\n');
            }
github kamilkisiela / graphql-inspector / website / live / src / diff / Diff.js View on Github external
useEffect(() => {
    try {
      setChanges(diff(oldSchema, buildSchema(code)));
    } catch (e) {
      console.error(e);
    }
  }, [code]);
github artsy / metaphysics / peril / schemaValidatorUtils.ts View on Github external
export const getBreakingChanges = async (
  localSchemaSDL: string,
  upstreamSchemaSDL: string
): Promise => {
  const allChanges = diff(
    buildSchema(localSchemaSDL),
    buildSchema(upstreamSchemaSDL)
  )
  const breakings = allChanges.filter(c => c.criticality.level === "BREAKING")
  const messages = breakings.map(c => c.message)
  return messages
}
github kamilkisiela / graphql-inspector / packages / github / src / diff.ts View on Github external
export async function diff({
  path,
  schemas,
}: {
  path: string;
  schemas: {
    old: GraphQLSchema;
    new: GraphQLSchema;
  };
}): Promise {
  const changes = diffSchemas(schemas.old, schemas.new);

  if (!changes || !changes.length) {
    return {
      conclusion: CheckConclusion.Success,
    };
  }

  const annotations = await Promise.all(
    changes.map(change => annotate({path, change, schemas})),
  );
  let conclusion: CheckConclusion = CheckConclusion.Success;

  if (
    changes.some(
      change => change.criticality.level === CriticalityLevel.Breaking,
    )
github aerogear / graphback / packages / graphql-migrations / src / production / migrations / GraphQLMigrationCreator.ts View on Github external
let oldSchema: GraphQLSchema;
    if (migrations.length) {
      const last = migrations[migrations.length - 1];

      oldSchema = buildSchema(last.model);
    }

    const newMigration: SchemaMigration = {
      id: new Date().getTime(),
      model: printSchema(this.schema)
    };

    let changes: ModelChange[] = [];
    if (oldSchema) {
      const inspectorChanges = diff(oldSchema, this.schema);
      changes = mapModelChanges(inspectorChanges);
    } else {
      changes = this.getContext().map((model: InputModelTypeContext) => {
        return {
          type: ModelChangeType.TYPE_ADDED,
          path: {
            type: model.name
          }
        }
      });
    }

    if (!changes.length) {
      return undefined;
    }
github aerogear / graphback / packages / graphback-db-manage / src / database / migrations / schema / GraphQLSchemaManager.ts View on Github external
public getChanges(): Change[] {
    let changes: Change[] = [];

    if (!this.previousSchemaText || !this.previousSchemaText.length) {
      return changes;
    }

    const oldSchema = buildSchema(this.previousSchemaText);
    const newSchema = buildSchema(this.currentSchemaText);

    if (oldSchema && newSchema) {
      changes = diff(oldSchema, newSchema);
    }

    return this.getValidChangeTypes(changes);
  }