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 +4 -4
- data/CHANGELOG.md +37 -1
- data/docs/directives.md +7 -4
- data/docs/filtering-and-ordering.md +52 -0
- data/lib/lighthouse/ast_builder.rb +14 -5
- data/lib/lighthouse/directive_resolvers/association_resolvers.rb +5 -7
- data/lib/lighthouse/directive_resolvers/base.rb +26 -22
- data/lib/lighthouse/directive_resolvers/model_mutation_resolver.rb +1 -8
- data/lib/lighthouse/directives/definitions.rb +2 -2
- data/lib/lighthouse/document_ast.rb +6 -0
- data/lib/lighthouse/graphql/version.rb +1 -1
- data/sig/lighthouse/graphql.rbs +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf8e8162adf7eff6d40299e3e8ecc947b8958f032323d97b78596578030f3bfa
|
|
4
|
+
data.tar.gz: 3b4fcda74e4e0b4eeed1baf5853fb72a753cd7ff401a25a25cf234efabdb581f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
|
|
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
|
-
|
|
560
|
-
|
|
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.
|
|
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
|
-
#
|
|
11
|
+
# 4. The type and field manipulators: @hide/@show, @model, @paginate (and the
|
|
10
12
|
# relation directives' `type:`), @softDeletes, @node.
|
|
11
|
-
#
|
|
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
|
-
#
|
|
15
|
-
#
|
|
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
|
-
|
|
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|
|
|
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
|
|
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 |
|
|
56
|
-
relation = apply_arg_builder(relation,
|
|
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
|
-
#
|
|
145
|
-
#
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
159
|
+
def builders_in(nodes, arguments, values)
|
|
154
160
|
registry = Lighthouse::DirectiveRegistry.default
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
163
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
14
|
-
(@eq, @where,
|
|
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)
|
data/sig/lighthouse/graphql.rbs
CHANGED
|
@@ -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
|