module GraphQL::SchemaComparator

Constants

VERSION

Public Class Methods

compare(old_schema, new_schema) click to toggle source

Compares and returns changes for two versions of a schema

@param old_schema [GraphQL::Schema, String] @param new_schema [GraphQL::Schema, String] @return [GraphQL::SchemaComparator::Result] the result of the comparison

# File lib/graphql/schema_comparator.rb, line 27
def self.compare(old_schema, new_schema)
  parsed_old = parse_schema(old_schema)
  parsed_new = parse_schema(new_schema)

  changes = Diff::Schema.new(parsed_old, parsed_new).diff
  Result.new(changes)
end

Private Class Methods

parse_schema(schema) click to toggle source
# File lib/graphql/schema_comparator.rb, line 37
def self.parse_schema(schema)
  if schema.respond_to?(:ancestors) && schema.ancestors.include?(GraphQL::Schema)
    schema
  elsif schema.is_a?(String)
    GraphQL::Schema.from_definition(schema)
  else
    raise ArgumentError, "Invalid Schema #{schema}. Expected a valid IDL or GraphQL::Schema object."
  end
end