Class: GraphQL::SchemaComparator::Changes::Criticality

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema_comparator/changes/criticality.rb

Overview

Defines the criticality of a Change object.

Constant Summary collapse

NON_BREAKING =

Non-breaking criticality usually defines changes that are always safe to make to a GraphQL Schema. They do not require any changes on the client side

1
DANGEROUS =

Dangerous criticality defines changes that are not breaking the schema, but may break runtime logic on clients if they did not code defensively enough to prevent these changes.

2
BREAKING =

Breaking criticality are changes that immediately impact clients usually causing queries not to be valid anymore.

3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level: NON_BREAKING, reason: nil) ⇒ Criticality

Creates a new Criticality object

Parameters:

  • level (Symbol) (defaults to: NON_BREAKING)

    The criticality level

  • reason (String) (defaults to: nil)

    The reason why this criticality is set on the change



59
60
61
62
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 59

def initialize(level: NON_BREAKING, reason: nil)
  @level = level
  @reason = reason
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



21
22
23
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 21

def level
  @level
end

#reasonObject (readonly)

Returns the value of attribute reason.



21
22
23
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 21

def reason
  @reason
end

Class Method Details

.breaking(reason: "This change is a breaking change") ⇒ GraphQL::SchemaComparator::Changes::Criticality

Returns a new Criticality object with a BREAKING level

Parameters:

  • reason (String) (defaults to: "This change is a breaking change")

    optional reason for this criticality

Returns:



27
28
29
30
31
32
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 27

def breaking(reason: "This change is a breaking change")
  new(
    level: BREAKING,
    reason: reason
  )
end

.dangerous(reason: "This change is dangerous") ⇒ GraphQL::SchemaComparator::Changes::Criticality

Returns a new Criticality object with a DANGEROUS level

Parameters:

  • reason (String) (defaults to: "This change is dangerous")

    optional reason for this criticality

Returns:



47
48
49
50
51
52
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 47

def dangerous(reason: "This change is dangerous")
  new(
    level: DANGEROUS,
    reason: reason
  )
end

.non_breaking(reason: "This change is safe") ⇒ GraphQL::SchemaComparator::Changes::Criticality

Returns a new Criticality object with a NON_BREAKING level

Parameters:

  • reason (String) (defaults to: "This change is safe")

    optional reason for this criticality

Returns:



37
38
39
40
41
42
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 37

def non_breaking(reason: "This change is safe")
  new(
    level: NON_BREAKING,
    reason: reason
  )
end

Instance Method Details

#<=>(other) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 64

def <=>(other)
  if level == other.level
    0
  elsif level < other.level
    -1
  else
    1
  end
end

#breaking?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 74

def breaking?
  @level == BREAKING
end

#dangerous?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 82

def dangerous?
  @level == DANGEROUS
end

#non_breaking?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/graphql/schema_comparator/changes/criticality.rb', line 78

def non_breaking?
  @level == NON_BREAKING
end