lighthouse-graphql 0.7.2 → 0.7.3

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: 30f0e741c78c61751024d75f1b7599e5e8e1e3b2bc426a48f7b6a89c86eacf19
4
- data.tar.gz: 45e1282efbb6115e4cf4931fd51a05b85cc8d096d204aba819d90228766da3a7
3
+ metadata.gz: cf8e8162adf7eff6d40299e3e8ecc947b8958f032323d97b78596578030f3bfa
4
+ data.tar.gz: 3b4fcda74e4e0b4eeed1baf5853fb72a753cd7ff401a25a25cf234efabdb581f
5
5
  SHA512:
6
- metadata.gz: a13e0fad7027bf2201b63f1543b95808fd63bc7f0ff0f71b9361c42e72f808b4e6475ac9f82298257884c28ecb878924d2ba7a0b1aa4c2186c049a626962c416
7
- data.tar.gz: 5f84257bfde8cf780b224f39615b4c8a0cff520479b97e7e106859084e390db0f9fe5a24fff0e2573609e46129c2b43d210a8fa36c3f972da67c1b7f2b3268cd
6
+ metadata.gz: 06c2d9e4a484d3bd54556ef758bccb41759f28f8ac39aaf2b857f5107a364f74b4a701e3cc426ec8a72ad12b5aa96a4406c139bd273542dc746725db71489e59
7
+ data.tar.gz: d9eddb09ca7fc8acacbaeca60fa646d9a655a9a96a83a3be25aeeba418cd902cd64b9a2f9b0dd4c1108a258208a4a300b759837c8dca1300d8a39af1e74ae249
data/CHANGELOG.md CHANGED
@@ -6,6 +6,36 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.7.3] - 2026-10-29
10
+
11
+ ### Changed
12
+
13
+ - **Filters on input fields apply without `@nest`, as in PHP Lighthouse.** The filter
14
+ directives (`@eq`, `@where`, `@like`, ...) on an input object's fields apply whenever the
15
+ client sends it: at any depth, for every input of a list (together), and through `@spread`,
16
+ as PHP Lighthouse's `applyArgBuilderDirectives` goes through nested inputs. They used to
17
+ apply only under an argument marked `@nest`, which is still accepted and changes nothing.
18
+ `posts(filter: PostFilter): [Post!]! @all` filters by the `@eq` inside `PostFilter`.
19
+
20
+ ### Fixed
21
+
22
+ - **A definition of a built-in directive in the SDL no longer disables it.** graphql-ruby
23
+ replaced its `@oneOf`, `@skip`, `@include`, `@deprecated` and `@specifiedBy` with a plain
24
+ directive of the same name when the SDL declared one (`directive @oneOf on INPUT_OBJECT`),
25
+ so a `@oneOf` input accepted any number of fields while introspection still reported
26
+ `isOneOf: true`, and `@skip` skipped nothing. Lighthouse now drops those definitions and
27
+ keeps graphql-ruby's directives.
28
+ - A relation field (`@hasMany`, ...) filtered only through an input object's fields took the
29
+ batched load and ignored the filters, and `@delete`, `@forceDelete` and `@restore` refused
30
+ such an argument as no filter ("Would modify all models"). Both now see nested filters.
31
+
32
+ ### Added
33
+
34
+ - `@oneOf` input objects are documented and specced
35
+ ([Filtering & Ordering](docs/filtering-and-ordering.md#one-filter-of-several-oneof)):
36
+ `user(by: UserBy!): User @find` finds by whichever one field the client gives, and
37
+ graphql-ruby rejects a query giving none or more than one.
38
+
9
39
  ## [0.7.2] - 2026-10-29
10
40
 
11
41
  ### Added
@@ -26,6 +56,11 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
26
56
  - The `_` placeholder exists only for the IDE: a `scalar _` in your SDL is dropped once the
27
57
  schema builds, so the executable schema (and its introspection) has no `_` type.
28
58
 
59
+ ### Fixed
60
+
61
+ - Builds on graphql-ruby 2.6.14, whose changed internals made the root types
62
+ (`Types::QueryType`, ...) lose the app's code-first base.
63
+
29
64
  ## [0.7.1] - 2026-10-18
30
65
 
31
66
  ### Added
@@ -701,7 +736,8 @@ had been running inside a private monorepo as a path gem before being extracted.
701
736
  - Config-driven extension seams: `Lighthouse.configure`, `resolver_namespaces`,
702
737
  `on_error`, and `DirectiveRegistry.register` for app-defined directives.
703
738
 
704
- [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.2...HEAD
739
+ [Unreleased]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.3...HEAD
740
+ [0.7.3]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.2...v0.7.3
705
741
  [0.7.2]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.1...v0.7.2
706
742
  [0.7.1]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.7.0...v0.7.1
707
743
  [0.7.0]: https://github.com/Vaz-Innovation/lighthouse-graphql/compare/v0.6.0...v0.7.0
data/docs/directives.md CHANGED
@@ -545,7 +545,7 @@ type Query {
545
545
  createdAt: DateRange @whereBetween(key: "created_at")
546
546
  tagged: [String!] @whereJsonContains(key: "tags")
547
547
  trending: Boolean @scope
548
- filter: PostFilter @nest
548
+ filter: PostFilter
549
549
  limit: Int @limit
550
550
  ): [Post!]! @all
551
551
  }
@@ -554,11 +554,14 @@ input DateRange { from: DateTime! to: DateTime! }
554
554
  input PostFilter { title: String @like, authorId: ID @eq(key: "author_id") }
555
555
  ```
556
556
 
557
+ The filters on an input object's fields (`filter: PostFilter` above) apply when
558
+ the client sends it, at any depth and for each input of a list, as PHP
559
+ Lighthouse applies them. Those of a list's inputs all apply together.
560
+
557
561
  ### `@nest`
558
562
 
559
- On an argument whose type is an input object, applies the filters of the input's
560
- fields (at any depth, for those that carry `@nest` too), as if they were the
561
- field's own arguments.
563
+ Accepted as PHP Lighthouse's SDL writes it, on an argument or input field of an
564
+ input object type. Filters on nested input fields apply without it.
562
565
 
563
566
  ### `@limit`
564
567
 
@@ -54,6 +54,58 @@ type Query {
54
54
  }
55
55
  ```
56
56
 
57
+ ### Filters inside input objects
58
+
59
+ Filter directives also go on the fields of an input object. Its fields' filters
60
+ apply when the client sends it, at any depth, as in PHP Lighthouse:
61
+
62
+ ```graphql
63
+ input PostFilter {
64
+ title: String @like
65
+ author: AuthorFilter
66
+ }
67
+
68
+ input AuthorFilter { id: ID @eq(key: "author_id") }
69
+
70
+ type Query {
71
+ posts(filter: PostFilter): [Post!]! @all
72
+ }
73
+ ```
74
+
75
+ `posts(filter: { author: { id: 1 } })` keeps the posts of author 1. In a list of
76
+ inputs (`filters: [PostFilter!]`), every input's filters apply, together. An
77
+ argument with `@spread` filters the same way.
78
+
79
+ ### One filter of several: `@oneOf`
80
+
81
+ An input object marked [`@oneOf`](https://spec.graphql.org/draft/#sec-OneOf-Input-Objects)
82
+ takes exactly one of its fields: to find a user by id **or** by email, but not
83
+ both. Its fields' filters apply to the query:
84
+
85
+ ```graphql
86
+ input UserBy @oneOf {
87
+ id: ID @eq
88
+ email: String @eq
89
+ }
90
+
91
+ type Query {
92
+ user(by: UserBy!): User @find
93
+ }
94
+ ```
95
+
96
+ ```graphql
97
+ { user(by: { email: "ada@example.com" }) { id } }
98
+ ```
99
+
100
+ graphql-ruby validates it: a query giving two fields, none, or a `null` is rejected
101
+ before anything resolves, and introspection reports the type's `isOneOf`. Every
102
+ field of a `@oneOf` input is nullable and has no default value; the schema fails to
103
+ build otherwise.
104
+
105
+ `@oneOf` is built in, so the SDL needn't declare it. A `directive @oneOf on
106
+ INPUT_OBJECT` copied from elsewhere is ignored, like a definition of `@skip`,
107
+ `@include`, `@deprecated` or `@specifiedBy`: graphql-ruby's own directive stays.
108
+
57
109
  ## Ordering
58
110
 
59
111
  `@orderBy` works as in PHP Lighthouse. On an argument, the client picks the
@@ -4,15 +4,17 @@
4
4
  # stitched schema:
5
5
  #
6
6
  # 1. DocumentAST.from_source: every type defined once.
7
- # 2. Type extensions merged into the types they extend. An extension of a
7
+ # 2. The SDL's definitions of graphql-ruby's built-in directives (@skip,
8
+ # @include, @deprecated, @oneOf, @specifiedBy) dropped: see BUILT_IN_DIRECTIVES.
9
+ # 3. Type extensions merged into the types they extend. An extension of a
8
10
  # root type that has no definition (`extend type Query` alone) defines it.
9
- # 3. The type and field manipulators: @hide/@show, @model, @paginate (and the
11
+ # 4. The type and field manipulators: @hide/@show, @model, @paginate (and the
10
12
  # relation directives' `type:`), @softDeletes, @node.
11
- # 4. The argument manipulators: each argument directive whose class includes
13
+ # 5. The argument manipulators: each argument directive whose class includes
12
14
  # Contracts::ArgManipulator rewrites its argument (@whereConditions,
13
15
  # @whereHasConditions, @orderBy turn `_` into the input types they generate).
14
- # 5. `scalar _`, if the SDL declares it for the IDE, dropped: nothing is left of the placeholder.
15
- # 6. The definitions of directives the generated types use (`@enum`).
16
+ # 6. `scalar _`, if the SDL declares it for the IDE, dropped: nothing is left of the placeholder.
17
+ # 7. The definitions of directives the generated types use (`@enum`).
16
18
  #
17
19
  # Returns the manipulated SDL; ManipulateAST listeners then see its document.
18
20
  module Lighthouse::GraphQL::ASTBuilder
@@ -41,10 +43,17 @@ module Lighthouse::GraphQL::ASTBuilder
41
43
 
42
44
  OBJECT_LIKE = [Nodes::ObjectTypeDefinition, Nodes::InterfaceTypeDefinition].freeze
43
45
 
46
+ # graphql-ruby's classes for these do the work: @skip skips, @oneOf makes the
47
+ # input object accept exactly one field. A definition in the SDL (copied from
48
+ # a printed schema, or from a graphql-js project, where it is harmless) would
49
+ # replace the class with a plain directive of the same name, which does nothing.
50
+ BUILT_IN_DIRECTIVES = ::GraphQL::Schema.default_directives.keys.freeze
51
+
44
52
  module_function
45
53
 
46
54
  def build(sdl, registry: Lighthouse::DirectiveRegistry.default)
47
55
  document_ast = Lighthouse::GraphQL::DocumentAST.from_source(sdl)
56
+ BUILT_IN_DIRECTIVES.each { |name| document_ast.remove_directive(name) }
48
57
  extend_types(document_ast)
49
58
 
50
59
  document_ast = Lighthouse::GraphQL::DocumentAST.from_source(registry.manipulate_sdl(document_ast.to_sdl))
@@ -74,18 +74,16 @@ module Lighthouse::GraphQL::DirectiveResolvers
74
74
  directive_arg('scopes') || Lighthouse::GraphQL::DirectiveResolvers::BuilderApplier.any?(@field_def.ast_node) || filtered?(args)
75
75
  end
76
76
 
77
+ # A supplied argument, or input field at any depth, with a filter directive
78
+ # (@eq, @where, ...), or a supplied where-conditions argument.
77
79
  def filtered?(args)
78
- registry = Lighthouse::DirectiveRegistry.default
80
+ return true if filtering?(args)
81
+
79
82
  (@field_def.ast_node&.arguments || []).any? do |argument|
80
- args.key?(argument.name.underscore.to_sym) && argument.directives.any? { |d| filter_directive?(registry, d) }
83
+ args.key?(argument.name.underscore.to_sym) && argument.directives.any? { |d| CONDITION_DIRECTIVES.include?(d.name) }
81
84
  end
82
85
  end
83
86
 
84
- # An argument builder (@eq, @where, ...) or a where-conditions filter.
85
- def filter_directive?(registry, directive)
86
- registry.arg_builder_class(directive.name) || CONDITION_DIRECTIVES.include?(directive.name)
87
- end
88
-
89
87
  def constrained(relation, args, ctx)
90
88
  relation = apply_where_filters(scoped(relation), args, ctx)
91
89
  self.class.collection? ? relation : relation.first
@@ -47,13 +47,13 @@ class Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver
47
47
  # Compose argument-builder directives (@eq, @neq, @in, @notIn, @like,
48
48
  # @where, @orderBy, @whereConditions, @whereHasConditions) onto the relation, in SDL argument order, for each
49
49
  # field argument that carries one and that the client supplied a value
50
- # for — and for the input fields of an argument carrying @nest.
50
+ # for — and for the fields of the input objects the client sent, at any depth.
51
51
  def apply_arg_builders(relation, args_h, ctx = nil)
52
52
  return relation unless relation.respond_to?(:where)
53
53
  return relation unless @field_def.ast_node
54
54
 
55
- arg_builders.each do |path, arg_node, dnode, builder_class|
56
- relation = apply_arg_builder(relation, args_h, ctx, [path, arg_node, dnode, builder_class])
55
+ arg_builders(args_h).each do |values, node, dnode, builder_class|
56
+ relation = apply_arg_builder(relation, values, ctx, [[node.name], node, dnode, builder_class])
57
57
  end
58
58
 
59
59
  relation
@@ -141,35 +141,39 @@ class Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver
141
141
  hash.is_a?(Hash) && Lighthouse::Support::Naming.candidate_keys(path.last).any? { |key| hash.key?(key) }
142
142
  end
143
143
 
144
- # [path, node, directive, builder class] for every argument-builder
145
- # directive, in SDL order. An argument carrying @nest adds its input type's
146
- # fields', at any depth, with their path into the value.
147
- def arg_builders
148
- (@field_def.ast_node.arguments || []).flat_map do |arg_node|
149
- builders_of(arg_node, [arg_node.name], @field_def.arguments[arg_node.name])
150
- end
144
+ # Did the client send an argument or input field, at any depth, that
145
+ # carries an argument-builder directive? As PHP Lighthouse's wouldEnhanceBuilder.
146
+ def filtering?(args_h)
147
+ arg_builders(args_h).any? { |values, node, _dnode, _builder_class| arg_present?(values, [node.name]) }
148
+ end
149
+
150
+ # [values, node, directive, builder class] for every argument-builder
151
+ # directive on the field's arguments, in SDL order, then on the fields of the
152
+ # input objects the client sent for them (each of a list), at any depth,
153
+ # as PHP Lighthouse's applyArgBuilderDirectives goes through them. `values`
154
+ # holds the node's value: the arguments, or the input object it is a field of.
155
+ def arg_builders(args_h)
156
+ builders_in(@field_def.ast_node.arguments || [], @field_def.arguments, args_h)
151
157
  end
152
158
 
153
- def builders_of(node, path, argument)
159
+ def builders_in(nodes, arguments, values)
154
160
  registry = Lighthouse::DirectiveRegistry.default
155
- own = (node.directives || []).filter_map do |dnode|
156
- builder_class = dnode.name == 'builder' ? :builder : registry.arg_builder_class(dnode.name)
157
- [path, node, dnode, builder_class] if builder_class
161
+ nodes.flat_map do |node|
162
+ own = (node.directives || []).filter_map do |dnode|
163
+ builder_class = dnode.name == 'builder' ? :builder : registry.arg_builder_class(dnode.name)
164
+ [values, node, dnode, builder_class] if builder_class
165
+ end
166
+ own + nested_builders(arguments[node.name], dig_arg(values, [node.name]))
158
167
  end
159
- own + (argument && nest?(node) ? nested_builders(argument, path) : [])
160
168
  end
161
169
 
162
- def nest?(node)
163
- (node.directives || []).any? { |d| d.name == 'nest' }
164
- end
170
+ def nested_builders(argument, value)
171
+ return [] if argument.nil? || value.nil?
165
172
 
166
- def nested_builders(argument, path)
167
173
  type = argument.type.unwrap
168
174
  return [] unless type.kind.input_object?
169
175
 
170
- type.arguments.each_value.flat_map do |field|
171
- field.ast_node ? builders_of(field.ast_node, path + [field.ast_node.name], field) : []
172
- end
176
+ [value].flatten.compact.flat_map { |input| builders_in(type.arguments.values.filter_map(&:ast_node), type.arguments, input) }
173
177
  end
174
178
 
175
179
  # The client's value at `path` (an argument, then input fields), or nil.
@@ -254,7 +254,7 @@ module Lighthouse::GraphQL::DirectiveResolvers
254
254
  # to the data, as PHP Lighthouse does; the others are still modified.
255
255
  def mutate(model, _obj, args, ctx)
256
256
  args = Lighthouse::Support::Arguments.shallow(args)
257
- raise ::GraphQL::ExecutionError, WOULD_MODIFY_ALL unless filtered?(args)
257
+ raise ::GraphQL::ExecutionError, WOULD_MODIFY_ALL unless filtering?(args)
258
258
 
259
259
  records = apply_where_filters(records_of(model), args, ctx).to_a
260
260
  records.each do |record|
@@ -272,13 +272,6 @@ module Lighthouse::GraphQL::DirectiveResolvers
272
272
  def modify(_record)
273
273
  raise NotImplementedError
274
274
  end
275
-
276
- def filtered?(args)
277
- registry = Lighthouse::DirectiveRegistry.default
278
- (@field_def.ast_node.arguments || []).any? do |argument|
279
- args.key?(argument.name.underscore.to_sym) && argument.directives.any? { |d| registry.arg_builder_class(d.name) }
280
- end
281
- end
282
275
  end
283
276
 
284
277
  # @delete — destroy the models the field's argument filters select
@@ -10,8 +10,8 @@ module Lighthouse::GraphQL::Directives::Definitions
10
10
  PASSIVE = {
11
11
  'nest' => <<~GRAPHQL.chomp,
12
12
  """
13
- On an argument of an input object type, apply the filters of the input's fields
14
- (@eq, @where, ...; at any depth, for those that carry @nest too) as if they were the field's own arguments.
13
+ Accepted on an argument or input field of an input object type, as PHP Lighthouse's SDL
14
+ writes it. The filters of input fields (@eq, @where, ...) apply at any depth without it.
15
15
  """
16
16
  directive @nest on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
17
17
  GRAPHQL
@@ -73,6 +73,12 @@ class Lighthouse::GraphQL::DocumentAST
73
73
  self
74
74
  end
75
75
 
76
+ # Drops the directive definition of that name, if any.
77
+ def remove_directive(name)
78
+ @directives.delete(name)
79
+ self
80
+ end
81
+
76
82
  # Adds the type parsed from `sdl`, unless the document has a type of that name.
77
83
  def define_type(name, sdl = nil)
78
84
  return @types[name] if @types.key?(name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lighthouse
4
4
  module GraphQL
5
- VERSION = '0.7.2'
5
+ VERSION = '0.7.3'
6
6
  end
7
7
  end
@@ -51,6 +51,7 @@ module Lighthouse
51
51
  # Adds a type, or replaces the one of the same name.
52
52
  def put_type: (untyped definition) -> self
53
53
  def remove_type: (String name) -> self
54
+ def remove_directive: (String name) -> self
54
55
  # Adds the type parsed from the SDL (or the block's), unless one of the name exists.
55
56
  def define_type: (String name, ?String? sdl) ?{ () -> String } -> untyped
56
57
  def type?: (String name) -> bool
@@ -62,6 +63,8 @@ module Lighthouse
62
63
  # The manipulation phase: extensions merged, then the type, field and argument manipulators.
63
64
  module ASTBuilder
64
65
  ROOT_TYPES: Array[String]
66
+ # graphql-ruby's own directives, whose definitions the SDL may repeat.
67
+ BUILT_IN_DIRECTIVES: Array[String]
65
68
 
66
69
  def self?.build: (String sdl, ?registry: DirectiveRegistry) -> String
67
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lighthouse-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaz Innovation