graphql-armory 0.1.0.pre14 → 0.1.0.pre15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60c5c0dcce6269bada949c9a3bcfcd5de843bef80c81c721fc577eb95aa6793f
4
- data.tar.gz: b4f86066c3d298a14e7762467d1302cdd8f42b695f8218cff0e75bfaee053501
3
+ metadata.gz: fb7c61a0d3d30bbe553aa4f56387032b0e00cd6f4525e79095b59039310ce9f6
4
+ data.tar.gz: aa56813e0f996e68af068be958838eab40c6c6aa259eaae5d413d064ae63a11b
5
5
  SHA512:
6
- metadata.gz: 86ddf1c6c14fda0da7a1508462cf1aad860ace99eab0f80e75ef6b9533f0156de762e5f207c92bda4390745b945dcbfe86f3d71e2829e117f13276ddce5b6833
7
- data.tar.gz: 4b28de723a5013ab17fd7183dbdf2e1e97418b5080478dab7903d13e09a787b53f200a8d3a531515c6359501d22139941de9c7819674ff9880f448b59dba976d
6
+ metadata.gz: 81b161b7bf3faf154d23e0be31753937e50c8a503b4c44ca152b000e53430541f14c8a0816687ea544f373752d213b58c94a5653ca181a302ea5dad43068fe00
7
+ data.tar.gz: 7f1e85ec3cecd5f215a15a1dcc273008be52c31fd10ef44fc1753a6d649974ee0e97071759c48b299c794846b474006cdbcd0078b1ec6e07f4aae2ccaebe414e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0.pre15 (2026-11-05)
4
+
5
+ A fix for [API versioning](docs/versioning.md): a schema whose field, argument, enum value or membership class included `Versioning::Base` after members were defined with it now fails with a `ConfigurationError` that names those members, instead of a `NoMethodError` on every query and in the audit. Anyone adopting versioning in an existing schema should upgrade.
6
+
7
+ ### Fixed
8
+
9
+ - Versioning refuses a schema whose field, argument, enum value or membership was built before its class included `Versioning::Base`, with a `ConfigurationError` naming those members, on the first query, `Versioning.types`, `Schema::Visibility`'s preload of named profiles and in the audit. Before, every query that reached such a member and the audit failed with a `NoMethodError` (#80).
10
+
3
11
  ## 0.1.0.pre14 (2026-11-05)
4
12
 
5
13
  This release adds [response caching](docs/response-caching.md) and [subscriptions over hosted pub/sub](docs/subscriptions.md). The cache answers a repeated persisted operation from a store, and stores an answer only when nothing it could not see took part in it, with an audit that finds unsafe declarations before production. Subscriptions run graphql-ruby subscriptions over Pusher, Ably or any transport of the same shape, with each update delivered as its own subscriber, never broadcast, and ended when the subscriber loses access. Upgrade if you need either; nothing existing changes for a schema that does not install them, except that rate limiting no longer charges subscription deliveries.
data/README.md CHANGED
@@ -6,12 +6,12 @@
6
6
 
7
7
  Open-source extensions for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), built on its public extension points: no fork, no monkey patching. One gem, one module at a time; each module has its own page in [`docs/`](docs) with the problem it solves, how to use it, and its limits.
8
8
 
9
- > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre14`). The API may change before 1.0.
9
+ > **Status: early development.** Prereleases on RubyGems (`0.1.0.pre15`). The API may change before 1.0.
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```ruby
14
- gem "graphql-armory", "~> 0.1.0.pre14" # a prerelease: `gem install graphql-armory --pre`
14
+ gem "graphql-armory", "~> 0.1.0.pre15" # a prerelease: `gem install graphql-armory --pre`
15
15
  gem "pundit" # or "cancancan", for the authorization module
16
16
  ```
17
17
 
data/docs/versioning.md CHANGED
@@ -527,6 +527,7 @@ Errors: `Versioning::ConfigurationError` (a server-side setup mistake), `Unknown
527
527
  - **An enum with every value hidden in V** raises graphql-ruby's `MissingValuesError` on any query that reaches it in V, introspection included. Give the enum the lifecycle instead.
528
528
  - **Named `Schema::Visibility` profiles** work only as the plugin's own, with `profiles: true` (graphql 2.4.10 or later; earlier versions build a named profile from the first query's context and keep it for every query, so `use` raises `ArgumentError` there). They hold the version and nothing else: Authorization's `visible_when:` raises under them, and your own `visible?` is asked once per version, so it must not read the user (the audit's `:profiles`). Without `profiles: true`, a query under a named profile raises `ConfigurationError`. Dynamic profiles (`dynamic: true`, or no profiles) work either way.
529
529
  - **`Schema::AlwaysVisible`** never asks `visible?`, so nothing would be versioned: the first query and `Versioning.types` raise `ConfigurationError` instead, even when it was added after `use`.
530
+ - **`Base` included after members were defined.** A field, argument, enum value or membership built with a class before that class included `Base` has no lifecycle. The first query, `Versioning.types`, `Schema::Visibility`'s preload and the audit refuse the schema with a `ConfigurationError` naming those members (a field with the file and line of its class): include `Base` in your base classes before defining anything with them. Under `profiles: true`, a member a profile already served before `Base` was included keeps being served in every version, as it was without `Base`.
530
531
  - **Your own `visible?`** on a base class, or the schema's `self.visible?`, must call `super`, or the plugin is skipped for those members. The audit cannot read whether it does: it reports each one (`:own_check`) until you declare it in `own_checks:`.
531
532
  - **Two refusing plugins.** With persisted queries, a request both refuse gets the persisted query's code. Either way nothing runs.
532
533
  - **Signals.** `to_definition`, `Schema.validate` and subscription triggers go through `query_class` too, so each records one signal.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Armory
5
- VERSION = "0.1.0.pre14"
5
+ VERSION = "0.1.0.pre15"
6
6
  end
7
7
  end
@@ -98,7 +98,7 @@ module GraphQL
98
98
 
99
99
  refused = schema_refusals(schema, findings)
100
100
  definitions = Integration.definitions(schema)
101
- members = definitions.flat_map { |type| members_of(type) }.uniq
101
+ members = definitions.flat_map { |type| Integration.members_of(type) }.uniq
102
102
  members.concat(schema.directives.values.flat_map(&:all_argument_definitions))
103
103
  undeclared(schema, members, findings)
104
104
  guarded(findings, "Schema") { OwnChecks.(schema, definitions, members, findings) }
@@ -142,14 +142,6 @@ module GraphQL
142
142
  end.positive?
143
143
  end
144
144
 
145
- def members_of(type)
146
- members = [type, *Armory::Definitions.fields_at_every_level(type), *Integration.arguments_in(type)]
147
- members.concat(type.all_enum_value_definitions) if type.kind.enum?
148
- members.concat(type.type_memberships) if type.kind.union?
149
- members.concat(type.interface_type_memberships.select { |membership| membership.respond_to?(:visible?) }) if type.respond_to?(:interface_type_memberships)
150
- members
151
- end
152
-
153
145
  # A label no version has fails the member's check whenever it is asked: reported even for a member no query asks.
154
146
  def undeclared(schema, members, findings)
155
147
  labels = schema.armory_versioning.versions.map(&:label)
@@ -127,6 +127,7 @@ module GraphQL
127
127
  end
128
128
 
129
129
  def visible?(context)
130
+ Integration.refuse_late_member(self) unless defined?(@armory_lifecycle)
130
131
  Integration.refuse_twin_overlap(self, armory_twins, context, field: true)
131
132
  return false unless super
132
133
 
@@ -152,6 +153,7 @@ module GraphQL
152
153
  EXECUTABLE = %i[QUERY MUTATION SUBSCRIPTION FIELD FRAGMENT_DEFINITION FRAGMENT_SPREAD INLINE_FRAGMENT VARIABLE_DEFINITION].freeze
153
154
 
154
155
  def visible?(context)
156
+ Integration.refuse_late_member(self) unless defined?(@armory_lifecycle)
155
157
  Integration.refuse_twin_overlap(self, armory_twins, context)
156
158
  return false unless super
157
159
 
@@ -229,6 +231,7 @@ module GraphQL
229
231
  include Member
230
232
 
231
233
  def visible?(context)
234
+ Integration.refuse_late_member(self) unless defined?(@armory_lifecycle)
232
235
  Integration.refuse_twin_overlap(self, armory_twins, context)
233
236
  return false unless super
234
237
  return true unless armory_versioned?
@@ -319,6 +322,7 @@ module GraphQL
319
322
  attr_reader :armory_lifecycle
320
323
 
321
324
  def visible?(context)
325
+ Integration.refuse_late_member(self) unless defined?(@armory_lifecycle)
322
326
  return false unless super
323
327
  return true if Lifecycle::EVERYWHERE.equal?(@armory_lifecycle)
324
328
 
@@ -608,6 +612,7 @@ module GraphQL
608
612
  types = nil
609
613
  walked = -> { types ||= definitions(schema) }
610
614
  checks = []
615
+ checks << -> { refuse_late_base(walked.(), schema.directives.values) }
611
616
  checks << -> { refuse_abstract_loads(walked.()) } if abstract_loads
612
617
  checks << -> { refuse_late_bound_twins(walked.(), schema.directives.values) } if late_bound_count.positive?
613
618
  checks << -> { refuse_subscription_twins(schema) }
@@ -756,10 +761,62 @@ module GraphQL
756
761
  directive.subclasses.reduce(directive.locations) { |locations, subclass| locations | directive_locations(subclass) }
757
762
  end
758
763
 
764
+ # A member built before its class included `Base` has none (`refuse_late_base` refuses the schema); the audit reads it
765
+ # as living everywhere, which is what it could declare, so it reports that refusal instead of failing.
759
766
  def self.lifecycle_of(member)
760
- member.respond_to?(:armory_lifecycle) ? member.armory_lifecycle : Lifecycle::EVERYWHERE
767
+ (member.armory_lifecycle if member.respond_to?(:armory_lifecycle)) || Lifecycle::EVERYWHERE
761
768
  end
762
769
 
770
+ # A type and everything versioned under it: its fields at every level, their arguments (or an input object's),
771
+ # an enum's values and its type memberships.
772
+ def self.members_of(type)
773
+ members = [type, *Armory::Definitions.fields_at_every_level(type), *arguments_in(type)]
774
+ members.concat(type.all_enum_value_definitions) if type.kind.enum?
775
+ members.concat(type.type_memberships) if type.kind.union?
776
+ members.concat(type.interface_type_memberships.select { |membership| membership.respond_to?(:visible?) }) if type.respond_to?(:interface_type_memberships)
777
+ members
778
+ end
779
+
780
+ LATE_BASE_LISTED = 5
781
+
782
+ # A field, argument, enum value or membership built before its class included `Base` has no lifecycle: its
783
+ # `visible?` would fail on every query. Refused with the members and what to do.
784
+ def self.refuse_late_base(types, directives)
785
+ members = types.flat_map { |type| members_of(type) } + directives.flat_map(&:all_argument_definitions)
786
+ late = members.uniq.select do |member|
787
+ (member.is_a?(Member) || member.is_a?(Membership)) && !member.instance_variable_defined?(:@armory_lifecycle)
788
+ end
789
+ return if late.empty?
790
+
791
+ names = late.first(LATE_BASE_LISTED).map { |member| late_base_name(member) }
792
+ names << "and #{late.size - LATE_BASE_LISTED} more" if late.size > LATE_BASE_LISTED
793
+ raise ConfigurationError, "#{names.join(", ")}: #{late_base_message(late_base_name(late.first, located: false))}"
794
+ end
795
+
796
+ # The same refusal from the member itself, for the paths that never run the schema checks: `Schema::Visibility`'s
797
+ # preload of named profiles, and a member built after the schema already ran a query (the checks are remembered).
798
+ def self.refuse_late_member(member)
799
+ raise ConfigurationError, late_base_message(late_base_name(member, located: false))
800
+ end
801
+
802
+ def self.late_base_message(name)
803
+ "the class of #{name} included GraphQL::Armory::Versioning::Base after #{name} was defined, so it has no lifecycle " \
804
+ "and every query would fail. include Base in the class before defining any field, argument or enum value with it " \
805
+ "(your base field, argument and enum value classes)"
806
+ end
807
+ private_class_method :late_base_message
808
+
809
+ def self.late_base_name(member, located: true)
810
+ name = if member.is_a?(Membership)
811
+ "#{member.abstract_type.graphql_name} membership of #{member.object_type.graphql_name}"
812
+ else
813
+ member.path
814
+ end
815
+ location = located && Location.of(member)
816
+ location ? "#{name} (#{location})" : name
817
+ end
818
+ private_class_method :late_base_name
819
+
763
820
  def self.versioned_type?(type) = !Lifecycle::EVERYWHERE.equal?(lifecycle_of(type))
764
821
 
765
822
  # A member is versioned by its own lifecycle, or, for an argument or input field, by its type's.
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.pre14
4
+ version: 0.1.0.pre15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Israel