graphql-armory 0.1.0.pre11 → 0.1.0.pre13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +4 -4
  4. data/docs/authorization.md +7 -7
  5. data/docs/rate-limiting.md +1 -1
  6. data/docs/versioning.md +540 -0
  7. data/lib/graphql/armory/authorization/adapters/pundit.rb +26 -1
  8. data/lib/graphql/armory/authorization/audit/findings.rb +6 -1
  9. data/lib/graphql/armory/authorization/audit/overrides.rb +8 -2
  10. data/lib/graphql/armory/authorization/audit/payload_reuse.rb +9 -8
  11. data/lib/graphql/armory/authorization/definitions.rb +8 -92
  12. data/lib/graphql/armory/authorization/integration/object.rb +2 -2
  13. data/lib/graphql/armory/authorization/integration.rb +29 -2
  14. data/lib/graphql/armory/authorization/rule.rb +3 -3
  15. data/lib/graphql/armory/authorization.rb +3 -1
  16. data/lib/graphql/armory/definitions.rb +111 -0
  17. data/lib/graphql/armory/location.rb +101 -0
  18. data/lib/graphql/armory/rate_limits/analysis_guard.rb +9 -2
  19. data/lib/graphql/armory/version.rb +1 -1
  20. data/lib/graphql/armory/versioning/audit/command.rb +43 -0
  21. data/lib/graphql/armory/versioning/audit/own_checks.rb +139 -0
  22. data/lib/graphql/armory/versioning/audit/profiles.rb +123 -0
  23. data/lib/graphql/armory/versioning/audit/subscription_triggers.rb +98 -0
  24. data/lib/graphql/armory/versioning/audit.rb +559 -0
  25. data/lib/graphql/armory/versioning/controls.rb +403 -0
  26. data/lib/graphql/armory/versioning/decision.rb +89 -0
  27. data/lib/graphql/armory/versioning/deprecation.rb +95 -0
  28. data/lib/graphql/armory/versioning/diff/command.rb +49 -0
  29. data/lib/graphql/armory/versioning/diff.rb +349 -0
  30. data/lib/graphql/armory/versioning/dump/command.rb +46 -0
  31. data/lib/graphql/armory/versioning/dump.rb +107 -0
  32. data/lib/graphql/armory/versioning/gate.rb +140 -0
  33. data/lib/graphql/armory/versioning/integration.rb +903 -0
  34. data/lib/graphql/armory/versioning/lifecycle.rb +61 -0
  35. data/lib/graphql/armory/versioning/profiles.rb +122 -0
  36. data/lib/graphql/armory/versioning/rspec.rb +38 -0
  37. data/lib/graphql/armory/versioning/versions.rb +111 -0
  38. data/lib/graphql/armory/versioning/view.rb +61 -0
  39. data/lib/graphql/armory/versioning.rb +132 -0
  40. data/lib/graphql/armory.rb +1 -0
  41. data/lib/tasks/graphql_armory.rake +20 -0
  42. metadata +24 -2
  43. data/lib/graphql/armory/authorization/location.rb +0 -79
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Armory
5
+ module Versioning
6
+ # When a member lives: from `added` (the first version when absent) up to, not including, `removed` (still here when
7
+ # absent). Building it checks only the shape of the labels, because members load before `use` declares the list. Their
8
+ # order is checked against the query's list every time it is asked, with nothing remembered on the member: a type may
9
+ # be shared by two schemas with different lists. The audit is the place to catch an undeclared label before a request.
10
+ class Lifecycle
11
+ # The lifecycle of a member that declares none: every version, at no cost.
12
+ class Everywhere
13
+ def covers?(_version) = true
14
+ def to_h = {}
15
+ end
16
+
17
+ EVERYWHERE = Everywhere.new.freeze
18
+
19
+ def self.build(added: nil, removed: nil)
20
+ added.nil? && removed.nil? ? EVERYWHERE : new(added: added, removed: removed)
21
+ end
22
+
23
+ attr_reader :added, :removed
24
+
25
+ def initialize(added: nil, removed: nil)
26
+ { added: added, removed: removed }.each do |name, label|
27
+ next if label.nil? || (label.is_a?(String) && !label.empty?)
28
+
29
+ raise ConfigurationError, "#{name}: must be a non-empty String naming a version, got #{label.inspect}"
30
+ end
31
+ raise ConfigurationError, "removed: must be a later version than added:, both are #{added.inspect}" if !added.nil? && added == removed
32
+
33
+ @added = added&.dup&.freeze
34
+ @removed = removed&.dup&.freeze
35
+ freeze
36
+ end
37
+
38
+ def covers?(version)
39
+ return @removed.nil? if Version::LATEST.equal?(version)
40
+
41
+ versions = version.versions
42
+ from = @added ? position(versions, :added, @added) : 0
43
+ to = @removed ? position(versions, :removed, @removed) : versions.size
44
+ raise ConfigurationError, "removed: #{@removed.inspect} comes before added: #{@added.inspect} in versions:" if to <= from
45
+
46
+ from <= version.index && version.index < to
47
+ end
48
+
49
+ def to_h
50
+ { added: @added, removed: @removed }.compact
51
+ end
52
+
53
+ private
54
+
55
+ def position(versions, name, label)
56
+ versions.index(label) || raise(ConfigurationError, "#{name}: #{label.inspect} is not in versions: #{versions.map(&:label).inspect}")
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Armory
5
+ module Versioning
6
+ # One named `Schema::Visibility` profile per served version (`use ..., profiles: true`): graphql-ruby computes each
7
+ # version's visibility once, for the life of the schema, instead of once per query.
8
+ #
9
+ # class AppSchema < GraphQL::Schema
10
+ # use GraphQL::Armory::Versioning, versions: %w[2024-06-01 2025-01-01], default: :latest, profiles: true
11
+ # use GraphQL::Schema::Visibility, profiles: GraphQL::Armory::Versioning.profiles(self), preload: true
12
+ # end
13
+ #
14
+ # Each profile's Hash holds the version's label and the gate's own `Versions`, and nothing else: a check that needs the
15
+ # query's user (Authorization's `visible_when:`, an app's `visible?`) cannot run under it. A query runs only under its
16
+ # own version's profile: `Lookup` names it before graphql-ruby builds the query, and refuses a query that ends up
17
+ # under any other.
18
+ class Profiles
19
+ # Before 2.4.10, graphql-ruby built a named profile with the first query's context and kept it for every query.
20
+ MINIMUM_GRAPHQL = Gem::Version.new("2.4.10")
21
+
22
+ # Validates `use`'s `profiles:` and wires the gate's list; `use` goes through here.
23
+ def self.build(versions, enabled:, graphql_version: GraphQL::VERSION)
24
+ raise ConfigurationError, "profiles: must be true or false, got #{enabled.inspect}" unless [true, false].include?(enabled)
25
+ return Off.new unless enabled
26
+
27
+ if Gem::Version.new(graphql_version) < MINIMUM_GRAPHQL
28
+ raise ArgumentError, "profiles: true needs graphql #{MINIMUM_GRAPHQL} or later, this is graphql #{graphql_version}: " \
29
+ "earlier versions build a named profile from the first query's context and keep it for every query"
30
+ end
31
+
32
+ new(versions)
33
+ end
34
+
35
+ # `new` is inert: it knows no version, so it names no profile and refuses every query that asks for one.
36
+ def initialize(versions = Versions::Null.new)
37
+ @versions = versions
38
+ end
39
+
40
+ def enabled? = true
41
+
42
+ # The profile name of a served version.
43
+ def name(version) = :"armory_v_#{version.label}"
44
+
45
+ # The Hash for `use GraphQL::Schema::Visibility, profiles:`, new each time: graphql-ruby adds the name to each
46
+ # Hash it is given and freezes it.
47
+ def to_h
48
+ @versions.each_served.to_h { |version| [name(version), { armory_version: version.label, armory_versions: @versions }] }
49
+ end
50
+
51
+ # What a query built for tooling (`Versioning.types`) passes to run under its version's profile.
52
+ def query_options(version) = { visibility_profile: name(version) }
53
+
54
+ # Before graphql-ruby builds the query: name the profile of the version its context asks for. A refused version
55
+ # gets none and runs under the Warden, whose `visible?` raises the refusal, so `to_definition` still raises it.
56
+ def options(gate, options)
57
+ values = options[:context]
58
+ decision = gate.resolve(values.respond_to?(:[]) ? values[:armory_version] : nil)
59
+ expected = decision.refused? ? nil : name(decision.version)
60
+ [options[:visibility_profile], values.respond_to?(:[]) ? values[:visibility_profile] : nil].each do |named|
61
+ raise ConfigurationError, foreign(named, expected) unless named.nil? || named == expected
62
+ end
63
+ return options.merge(use_visibility_profile: false) if decision.refused?
64
+
65
+ options.merge(visibility_profile: expected)
66
+ end
67
+
68
+ # After the query is built and its version decided: it runs under that version's profile, or under the Warden.
69
+ def check(query, decision)
70
+ expected = decision.refused? ? nil : name(decision.version)
71
+ named = query.context[:visibility_profile]
72
+ raise ConfigurationError, foreign(named, expected) unless named.nil? || named == expected
73
+
74
+ profile = query.visibility_profile
75
+ if profile
76
+ return if !expected.nil? && profile.name == expected
77
+
78
+ raise ConfigurationError, "the query runs under #{profile.name ? "the visibility profile #{profile.name.inspect}" : 'a dynamic visibility profile'}, " \
79
+ "not #{expected.inspect}: under profiles: true, pass `profiles: GraphQL::Armory::Versioning.profiles(#{query.schema})` " \
80
+ "to `use GraphQL::Schema::Visibility`"
81
+ end
82
+ return if decision.refused? || query.schema.use_visibility_profile?
83
+
84
+ raise ConfigurationError, "profiles: true needs `use GraphQL::Schema::Visibility, profiles: GraphQL::Armory::Versioning.profiles(#{query.schema})`: " \
85
+ "the schema does not use Schema::Visibility"
86
+ end
87
+
88
+ private
89
+
90
+ def foreign(named, expected)
91
+ "the query names the visibility profile #{named.inspect}, " \
92
+ "#{expected ? "not its version's #{expected.inspect}" : 'and its version is refused'}: under profiles: true a query runs " \
93
+ "only under its version's profile, which the plugin names. Do not set visibility_profile"
94
+ end
95
+
96
+ # `profiles: false`, the default: no profile of its own, and no named profile at all, since one keeps the
97
+ # visibility of every query that names it.
98
+ class Off
99
+ def enabled? = false
100
+
101
+ def to_h
102
+ raise ConfigurationError, "Versioning.profiles needs `use GraphQL::Armory::Versioning, ..., profiles: true`, " \
103
+ "before `use GraphQL::Schema::Visibility, profiles: GraphQL::Armory::Versioning.profiles(self)`"
104
+ end
105
+
106
+ def query_options(_version) = {}
107
+
108
+ def options(_gate, options) = options
109
+
110
+ def check(query, _decision)
111
+ name = query.visibility_profile.respond_to?(:name) ? query.visibility_profile.name : nil
112
+ return if name.nil?
113
+
114
+ raise ConfigurationError, "the query runs under the visibility profile #{name.inspect}: named Schema::Visibility profiles keep " \
115
+ "one visibility for every query that names them, so they cannot follow each query's version. Use " \
116
+ "`use GraphQL::Armory::Versioning, ..., profiles: true` with `GraphQL::Armory::Versioning.profiles`, or dynamic: true"
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/expectations"
4
+
5
+ # `require "graphql/armory/versioning/rspec"` in your spec helper, then:
6
+ #
7
+ # expect(AppSchema).to have_consistent_versions
8
+ # expect(AppSchema).to have_no_breaking_changes(from: "2024-06-01", to: "2025-01-01")
9
+ RSpec::Matchers.define :have_consistent_versions do
10
+ match do |schema|
11
+ (@report = GraphQL::Armory::Versioning::Audit.(schema)).ok?
12
+ end
13
+
14
+ failure_message do |schema|
15
+ "expected #{schema} to have consistent versions, but the audit found:\n#{@report}"
16
+ end
17
+
18
+ failure_message_when_negated do |schema|
19
+ "expected #{schema} not to have consistent versions, but the audit found no problems"
20
+ end
21
+ end
22
+
23
+ # For a version line that should only grow:
24
+ #
25
+ # expect(AppSchema).to have_no_breaking_changes(from: "2024-06-01", to: "2025-01-01")
26
+ RSpec::Matchers.define :have_no_breaking_changes do |versions|
27
+ match do |schema|
28
+ !(@result = GraphQL::Armory::Versioning::Diff.(schema, from: versions.fetch(:from), to: versions.fetch(:to))).breaking?
29
+ end
30
+
31
+ failure_message do |schema|
32
+ "expected #{schema} to have no breaking changes from #{versions[:from]} to #{versions[:to]}, but found:\n#{@result}"
33
+ end
34
+
35
+ failure_message_when_negated do |schema|
36
+ "expected #{schema} to have breaking changes from #{versions[:from]} to #{versions[:to]}, but found none"
37
+ end
38
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Armory
5
+ module Versioning
6
+ # One version of the schema: its label, its position in the list, and whether it is retired. Comparable with another
7
+ # Version of the same list or with one of its labels (`version < "2025-01-01"`); a label the list does not hold raises.
8
+ class Version
9
+ include Comparable
10
+
11
+ attr_reader :label, :index, :versions
12
+
13
+ def initialize(label, index, retired, versions)
14
+ @label = label
15
+ @index = index
16
+ @retired = retired
17
+ @versions = versions
18
+ freeze
19
+ end
20
+
21
+ def retired?
22
+ @retired
23
+ end
24
+
25
+ def <=>(other)
26
+ case other
27
+ when Version then index <=> other.index
28
+ when String then index <=> @versions.fetch(other).index
29
+ end
30
+ end
31
+
32
+ def to_s
33
+ label
34
+ end
35
+
36
+ def inspect
37
+ "#<#{self.class.name} #{label}>"
38
+ end
39
+
40
+ # What `visible?` sees when graphql-ruby asks it with no query (`NullContext`): the latest version, with no list at
41
+ # hand. A removed member never comes back, so "latest" is "nothing removed it".
42
+ LATEST = Object.new.tap { |latest| def latest.inspect = "#<GraphQL::Armory::Versioning::Version LATEST>" }.freeze
43
+ end
44
+
45
+ # The schema's versions, oldest first. Labels are opaque: their order is their position. Validated by `Gate.build`.
46
+ class Versions
47
+ include Enumerable
48
+
49
+ def initialize(labels, retired: [])
50
+ @all = labels.each_with_index.map { |label, index| Version.new(label.dup.freeze, index, retired.include?(label), self) }.freeze
51
+ @by_label = @all.to_h { |version| [version.label, version] }.freeze
52
+ @served = @all.reject(&:retired?).freeze
53
+ freeze
54
+ end
55
+
56
+ def index(label)
57
+ @by_label[label]&.index
58
+ end
59
+
60
+ def fetch(label)
61
+ @by_label.fetch(label) { raise UnknownVersionError, "#{label.inspect} is not in versions: #{@all.map(&:label).inspect}" }
62
+ end
63
+
64
+ def latest
65
+ @all.last
66
+ end
67
+
68
+ def served?(label)
69
+ version = @by_label[label]
70
+ version ? !version.retired? : false
71
+ end
72
+
73
+ def retired?(label)
74
+ @by_label[label]&.retired? || false
75
+ end
76
+
77
+ def each_served(&block)
78
+ @served.each(&block)
79
+ end
80
+
81
+ def each(&block)
82
+ @all.each(&block)
83
+ end
84
+
85
+ def size
86
+ @all.size
87
+ end
88
+
89
+ # The list of a gate nobody wired: it knows no version, so every label is unknown.
90
+ class Null
91
+ include Enumerable
92
+
93
+ def index(_label) = nil
94
+ def served?(_label) = false
95
+ def retired?(_label) = false
96
+ def size = 0
97
+ def each_served(&block) = [].each(&block)
98
+ def each(&block) = [].each(&block)
99
+
100
+ def fetch(label)
101
+ raise UnknownVersionError, "#{label.inspect} is not a version: no versions are declared (use GraphQL::Armory::Versioning, versions: [...])"
102
+ end
103
+
104
+ def latest
105
+ raise UnknownVersionError, "there is no latest version: no versions are declared (use GraphQL::Armory::Versioning, versions: [...])"
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Armory
5
+ module Versioning
6
+ # One version's schema, for tooling: what a query of that version sees. Built by `Versioning.types(schema, label)`.
7
+ #
8
+ # v = GraphQL::Armory::Versioning.types(AppSchema, "2024-06-01")
9
+ # v.type("Contract") # nil: not in that version
10
+ # v.fields(Types::Invoice).map(&:graphql_name)
11
+ #
12
+ # Everything goes through graphql-ruby's own visibility for that version (`query.types`), plus the checks graphql-ruby
13
+ # leaves out: a type answers only when it is listed in that version, and a member only when its owner is. Objects it
14
+ # answers are graphql-ruby's own: calling their methods (`type.fields`) without a context sees every version.
15
+ # `View.new` with nothing answers nothing.
16
+ class View
17
+ def initialize(types = nil)
18
+ @types = types
19
+ end
20
+
21
+ # The type of that name in this version, or nil.
22
+ def type(name)
23
+ return unless @types && @types.reachable_type?(name)
24
+
25
+ @types.type(name)
26
+ end
27
+
28
+ def all_types = @types ? @types.all_types : []
29
+
30
+ def fields(owner) = visible?(owner) ? @types.fields(owner) : []
31
+
32
+ def field(owner, name) = visible?(owner) ? @types.field(owner, name) : nil
33
+
34
+ # Of a field, an input object or a directive.
35
+ def arguments(owner) = owner_visible?(owner) ? @types.arguments(owner) : []
36
+
37
+ def possible_types(type) = visible?(type) ? @types.possible_types(type) : []
38
+
39
+ def interfaces(type) = visible?(type) ? @types.interfaces(type) : []
40
+
41
+ def enum_values(type) = visible?(type) ? @types.enum_values(type) : []
42
+
43
+ # Whether this version lists the type.
44
+ def visible?(type)
45
+ !type.nil? && type.respond_to?(:graphql_name) && type(type.graphql_name).equal?(type)
46
+ end
47
+
48
+ private
49
+
50
+ def owner_visible?(owner)
51
+ case owner
52
+ when GraphQL::Schema::Field then visible?(owner.owner) && field(owner.owner, owner.graphql_name).equal?(owner)
53
+ when Class
54
+ owner < GraphQL::Schema::Directive ? !@types.nil? && @types.directives.include?(owner) : visible?(owner)
55
+ else false
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphQL
4
+ module Armory
5
+ # API versioning: a client names the version of the schema it was built against, and gets exactly that version's
6
+ # schema, or a refusal. Members say when they arrived and when they left.
7
+ #
8
+ # class AppSchema < GraphQL::Schema
9
+ # use GraphQL::Schema::Visibility
10
+ # use GraphQL::Armory::Versioning, versions: %w[2024-01-15 2024-06-01 2025-01-01], retired: %w[2024-01-15], default: :latest
11
+ # end
12
+ #
13
+ # class Types::BaseField < GraphQL::Schema::Field
14
+ # include GraphQL::Armory::Versioning::Base
15
+ # end
16
+ #
17
+ # field :total, Integer, null: false, added: "2024-06-01"
18
+ # field :amount, Integer, null: false, removed: "2025-01-01"
19
+ #
20
+ # AppSchema.execute(params[:query], context: { armory_version: request.headers["X-API-Version"] })
21
+ #
22
+ # Hooks only `Schema.query_class` (to decide the version once per query) and `visible?` on the classes that include
23
+ # `Base`, so every lookup graphql-ruby makes for the query (validation, both engines, introspection, SDL) sees one version.
24
+ module Versioning
25
+ class Error < Armory::Error; end
26
+
27
+ # The schema or a member was not set up the way versioning needs. Server-side, never a client's doing.
28
+ class ConfigurationError < Error; end
29
+
30
+ # A label the version list does not hold.
31
+ class UnknownVersionError < ConfigurationError; end
32
+
33
+ # A versioned member was asked about in a query whose version is refused: only callers that skip validation reach it,
34
+ # such as `to_definition`, `Schema.validate` or a query the app built itself. The message never quotes the client's value.
35
+ class RefusedVersionError < Error
36
+ attr_reader :code
37
+
38
+ def initialize(message, code)
39
+ @code = code
40
+ super(message)
41
+ end
42
+ end
43
+
44
+ # The request named no version and the schema says `default: :refuse`.
45
+ class MissingVersionError < RefusedVersionError; end
46
+
47
+ # Answers the Version a query sees, from a resolver, `resolve_type` or anything else that holds its context, so data
48
+ # can be mapped to the schema that client sees. Raises for anything that is not a query's context.
49
+ def self.version(context)
50
+ if context.is_a?(GraphQL::Query::NullContext) || !context.respond_to?(:namespace)
51
+ raise ConfigurationError, "Versioning.version needs a query's context (a resolver's, resolve_type's or a trigger's), not a #{context.class}"
52
+ end
53
+
54
+ Integration.version(context)
55
+ end
56
+
57
+ # One version's schema for tooling (a `View`): what a query naming `label` sees, decided the way a request is, with
58
+ # `context:` merged in (a user, for `visible_when:`). Records no signal. Raises the refusal for a version that is not
59
+ # served, and `ConfigurationError` for a schema versioning cannot serve.
60
+ def self.types(schema, label, context: {})
61
+ decision = Integration.gate(schema).resolve(label)
62
+ raise decision.error if decision.refused?
63
+
64
+ Integration.refuse_always_visible(schema)
65
+ Integration.check_schema(schema)
66
+ # Under `profiles: true`, the version's own profile: what its requests see.
67
+ profile = schema.armory_versioning_profiles.query_options(decision.version)
68
+ query = GraphQL::Query.new(schema, "{ __typename }", validate: false, context: context.merge(armory_version: label), **profile)
69
+ View.new(query.types)
70
+ end
71
+
72
+ # Whether no served version of `schema` sees more than one of `definitions` (twins of one name), for Authorization's
73
+ # audit. False for a schema without versioning.
74
+ def self.disjoint?(schema, definitions)
75
+ return false unless schema.respond_to?(:armory_versioning)
76
+
77
+ schema.armory_versioning.versions.each_served.all? do |version|
78
+ definitions.count { |definition| Integration.covers?(definition, version) } <= 1
79
+ end
80
+ end
81
+
82
+ # The Hash for `use GraphQL::Schema::Visibility, profiles:` on a schema that says `use ..., profiles: true`: one named
83
+ # profile per served version, built from the gate's own list, so the two cannot drift.
84
+ #
85
+ # use GraphQL::Armory::Versioning, versions: [...], default: :latest, profiles: true
86
+ # use GraphQL::Schema::Visibility, profiles: GraphQL::Armory::Versioning.profiles(self), preload: true
87
+ def self.profiles(schema)
88
+ Integration.gate(schema)
89
+ schema.armory_versioning_profiles.to_h
90
+ end
91
+
92
+ # `versions:` the labels, oldest first; `retired:` the oldest ones, no longer served; `default:` what a request with no
93
+ # version gets: `:latest`, a served label or `:refuse`. `sinks:` and `on_sink_error:` as in Telemetry. `own_checks:` names
94
+ # the app's own `visible?` methods the audit does not report, each with the reason it is kept. `profiles: true` runs each
95
+ # query under its version's named `Schema::Visibility` profile (graphql >= 2.4.10; see `profiles`).
96
+ def self.use(schema, versions:, default: Gate::UNSET, retired: [], sinks: [], on_sink_error: nil, own_checks: {}, profiles: false)
97
+ gate = Gate.build(versions: versions, default: default, retired: retired, sinks: sinks, on_sink_error: on_sink_error, own_checks: own_checks)
98
+ named_profiles = Profiles.build(gate.versions, enabled: profiles)
99
+
100
+ if schema.singleton_class.include?(Integration::Guard)
101
+ raise ConfigurationError, "#{schema} already uses Versioning (here or in a parent schema): use it once"
102
+ end
103
+
104
+ schema.instance_variable_set(:@armory_versioning, gate)
105
+ schema.instance_variable_set(:@armory_versioning_profiles, named_profiles)
106
+ schema.singleton_class.prepend(Integration::Guard)
107
+ schema.query_class(schema.query_class)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ require "graphql/armory/definitions"
114
+ require "graphql/armory/location"
115
+ require "graphql/armory/versioning/versions"
116
+ require "graphql/armory/versioning/lifecycle"
117
+ require "graphql/armory/versioning/decision"
118
+ require "graphql/armory/versioning/gate"
119
+ require "graphql/armory/versioning/deprecation"
120
+ require "graphql/armory/versioning/profiles"
121
+ require "graphql/armory/versioning/integration"
122
+ require "graphql/armory/versioning/view"
123
+ require "graphql/armory/versioning/audit"
124
+ require "graphql/armory/versioning/audit/own_checks"
125
+ require "graphql/armory/versioning/audit/subscription_triggers"
126
+ require "graphql/armory/versioning/audit/command"
127
+ require "graphql/armory/versioning/audit/profiles"
128
+ require "graphql/armory/versioning/diff"
129
+ require "graphql/armory/versioning/diff/command"
130
+ require "graphql/armory/versioning/dump"
131
+ require "graphql/armory/versioning/dump/command"
132
+ require "graphql/armory/versioning/controls"
@@ -17,4 +17,5 @@ require "graphql/armory/ids"
17
17
  require "graphql/armory/persisted_queries"
18
18
  require "graphql/armory/rate_limits"
19
19
  require "graphql/armory/keyset"
20
+ require "graphql/armory/versioning"
20
21
  require "graphql/armory/railtie" if defined?(::Rails::Railtie)
@@ -15,4 +15,24 @@ namespace :graphql_armory do
15
15
  desc "Writes the audit's problems to a baseline file, or removes from it what is gone; it never adds to a file that exists"
16
16
  task :audit_baseline, [:schema, :baseline], &baseline_action
17
17
  end
18
+
19
+ namespace :versions do
20
+ versions_action = GraphQL::Armory::Versioning::Audit::Command::RAKE_ACTION
21
+ unless Rake::Task.task_defined?("graphql_armory:versions:audit") && Rake::Task["graphql_armory:versions:audit"].actions.include?(versions_action)
22
+ desc "Lists what a query of each served version would have refused, and members a version serves outside their lifecycle (exit 1 if any)"
23
+ task :audit, [:schema], &versions_action
24
+ end
25
+
26
+ dump_action = GraphQL::Armory::Versioning::Dump::Command::RAKE_ACTION
27
+ unless Rake::Task.task_defined?("graphql_armory:versions:dump") && Rake::Task["graphql_armory:versions:dump"].actions.include?(dump_action)
28
+ desc "Writes each served version's SDL to <dir>/<label>.graphql, plus <dir>/latest.graphql (dir defaults to schema)"
29
+ task :dump, [:schema, :dir], &dump_action
30
+ end
31
+
32
+ diff_action = GraphQL::Armory::Versioning::Diff::Command::RAKE_ACTION
33
+ unless Rake::Task.task_defined?("graphql_armory:versions:diff") && Rake::Task["graphql_armory:versions:diff"].actions.include?(diff_action)
34
+ desc "Lists what changes between two served versions: breaking, dangerous and safe (exit 1 if anything breaks)"
35
+ task :diff, [:schema, :from, :to], &diff_action
36
+ end
37
+ end
18
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-armory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre11
4
+ version: 0.1.0.pre13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Israel
@@ -48,6 +48,7 @@ files:
48
48
  - docs/persisted-queries.md
49
49
  - docs/rate-limiting.md
50
50
  - docs/telemetry.md
51
+ - docs/versioning.md
51
52
  - exe/graphql-armory-publish
52
53
  - lib/graphql-armory.rb
53
54
  - lib/graphql/armory.rb
@@ -94,11 +95,11 @@ files:
94
95
  - lib/graphql/armory/authorization/integration/resolver.rb
95
96
  - lib/graphql/armory/authorization/integration/root_check.rb
96
97
  - lib/graphql/armory/authorization/integration/schema.rb
97
- - lib/graphql/armory/authorization/location.rb
98
98
  - lib/graphql/armory/authorization/memo.rb
99
99
  - lib/graphql/armory/authorization/rspec.rb
100
100
  - lib/graphql/armory/authorization/rule.rb
101
101
  - lib/graphql/armory/authorization/scope.rb
102
+ - lib/graphql/armory/definitions.rb
102
103
  - lib/graphql/armory/encoder.rb
103
104
  - lib/graphql/armory/encoder/default.rb
104
105
  - lib/graphql/armory/encoder/legacy.rb
@@ -110,6 +111,7 @@ files:
110
111
  - lib/graphql/armory/keyset.rb
111
112
  - lib/graphql/armory/keyset/controls.rb
112
113
  - lib/graphql/armory/keyset/encoder_check.rb
114
+ - lib/graphql/armory/location.rb
113
115
  - lib/graphql/armory/persisted_queries.rb
114
116
  - lib/graphql/armory/persisted_queries/controls.rb
115
117
  - lib/graphql/armory/persisted_queries/manifest.rb
@@ -131,6 +133,26 @@ files:
131
133
  - lib/graphql/armory/rate_limits/time.rb
132
134
  - lib/graphql/armory/telemetry.rb
133
135
  - lib/graphql/armory/version.rb
136
+ - lib/graphql/armory/versioning.rb
137
+ - lib/graphql/armory/versioning/audit.rb
138
+ - lib/graphql/armory/versioning/audit/command.rb
139
+ - lib/graphql/armory/versioning/audit/own_checks.rb
140
+ - lib/graphql/armory/versioning/audit/profiles.rb
141
+ - lib/graphql/armory/versioning/audit/subscription_triggers.rb
142
+ - lib/graphql/armory/versioning/controls.rb
143
+ - lib/graphql/armory/versioning/decision.rb
144
+ - lib/graphql/armory/versioning/deprecation.rb
145
+ - lib/graphql/armory/versioning/diff.rb
146
+ - lib/graphql/armory/versioning/diff/command.rb
147
+ - lib/graphql/armory/versioning/dump.rb
148
+ - lib/graphql/armory/versioning/dump/command.rb
149
+ - lib/graphql/armory/versioning/gate.rb
150
+ - lib/graphql/armory/versioning/integration.rb
151
+ - lib/graphql/armory/versioning/lifecycle.rb
152
+ - lib/graphql/armory/versioning/profiles.rb
153
+ - lib/graphql/armory/versioning/rspec.rb
154
+ - lib/graphql/armory/versioning/versions.rb
155
+ - lib/graphql/armory/versioning/view.rb
134
156
  - lib/tasks/graphql_armory.rake
135
157
  homepage: https://github.com/israelb/graphql-armory
136
158
  licenses: