lighthouse-graphql 0.7.1 → 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 +58 -1
- data/docs/directives.md +7 -4
- data/docs/filtering-and-ordering.md +52 -0
- data/docs/getting-started.md +44 -11
- data/lib/lighthouse/ast_builder.rb +16 -4
- data/lib/lighthouse/cache_control.rb +14 -2
- data/lib/lighthouse/complexity.rb +11 -1
- data/lib/lighthouse/directive_resolvers/aggregate_resolver.rb +17 -1
- data/lib/lighthouse/directive_resolvers/all_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/association_resolvers.rb +70 -16
- data/lib/lighthouse/directive_resolvers/auth_resolver.rb +10 -1
- data/lib/lighthouse/directive_resolvers/base.rb +44 -22
- data/lib/lighthouse/directive_resolvers/broadcast_resolver.rb +12 -1
- data/lib/lighthouse/directive_resolvers/cache_resolvers.rb +28 -3
- data/lib/lighthouse/directive_resolvers/can_resolvers.rb +62 -9
- data/lib/lighthouse/directive_resolvers/count_resolver.rb +16 -1
- data/lib/lighthouse/directive_resolvers/event_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/field_resolver.rb +6 -1
- data/lib/lighthouse/directive_resolvers/find_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/first_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/guard_resolver.rb +10 -1
- data/lib/lighthouse/directive_resolvers/method_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/model_mutation_resolver.rb +75 -16
- data/lib/lighthouse/directive_resolvers/paginate_resolver.rb +17 -2
- data/lib/lighthouse/directive_resolvers/rename_resolver.rb +14 -1
- data/lib/lighthouse/directive_resolvers/subscription_resolver.rb +13 -1
- data/lib/lighthouse/directive_resolvers/validator_resolver.rb +13 -1
- data/lib/lighthouse/directives/arguments/base.rb +18 -0
- data/lib/lighthouse/directives/arguments/filters.rb +16 -7
- data/lib/lighthouse/directives/definitions.rb +43 -6
- data/lib/lighthouse/document_ast.rb +12 -0
- data/lib/lighthouse/enum_directive.rb +6 -1
- data/lib/lighthouse/feature_directive.rb +13 -1
- data/lib/lighthouse/graphql/version.rb +1 -1
- data/lib/lighthouse/graphql_ruby_patches.rb +26 -2
- data/lib/lighthouse/ide_helper.rb +7 -6
- data/lib/lighthouse/scalar_coercion.rb +4 -1
- data/lib/lighthouse/tasks/lighthouse.rake +8 -0
- data/lib/lighthouse/type_resolution.rb +8 -2
- data/sig/lighthouse/graphql.rbs +4 -0
- metadata +1 -1
|
@@ -25,7 +25,19 @@ require_relative 'base'
|
|
|
25
25
|
# across arguments, arguments of a query, or input that never reaches a model.
|
|
26
26
|
class Lighthouse::GraphQL::DirectiveResolvers::ValidatorDirectiveResolver < Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver
|
|
27
27
|
def self.directive_name = 'validator'
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
def self.definition
|
|
30
|
+
<<~GRAPHQL.chomp
|
|
31
|
+
"""
|
|
32
|
+
Validate the arguments of a field, or the values of an input type, with a contract class
|
|
33
|
+
before the field resolves. Failures are reported keyed by argument path.
|
|
34
|
+
"""
|
|
35
|
+
directive @validator(
|
|
36
|
+
"The contract class, looked up in Config.namespaces[:validators]. Defaults to Validators::<ParentType>::<FieldName>Validator on a field, and to Validators::<InputType>Validator on an input type."
|
|
37
|
+
class: String
|
|
38
|
+
) on FIELD_DEFINITION | INPUT_OBJECT
|
|
39
|
+
GRAPHQL
|
|
40
|
+
end
|
|
29
41
|
|
|
30
42
|
# A default name, e.g. Mutation::SignUpValidator: always looked up under
|
|
31
43
|
# the validators namespaces, although it contains `::`.
|
|
@@ -7,6 +7,24 @@
|
|
|
7
7
|
class Lighthouse::GraphQL::Directives::Arguments::Base
|
|
8
8
|
include Lighthouse::Contracts::ArgBuilder
|
|
9
9
|
|
|
10
|
+
# The `key` argument's SDL, which most of them take.
|
|
11
|
+
KEY_ARGUMENT = Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver.argument_sdl(
|
|
12
|
+
'key: String', "The column to filter on. Defaults to the argument's name in snake_case."
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def self.argument_sdl(...) = Lighthouse::GraphQL::DirectiveResolvers::BaseDirectiveResolver.argument_sdl(...)
|
|
16
|
+
|
|
17
|
+
# The SDL of a filter directive: `description`, then its arguments (`key` by default).
|
|
18
|
+
def self.sdl(name, description, arguments = KEY_ARGUMENT)
|
|
19
|
+
parentheses = "(\n#{arguments}\n)" if arguments
|
|
20
|
+
<<~GRAPHQL.chomp
|
|
21
|
+
"""
|
|
22
|
+
#{description}
|
|
23
|
+
"""
|
|
24
|
+
directive @#{name}#{parentheses} on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
|
|
25
|
+
GRAPHQL
|
|
26
|
+
end
|
|
27
|
+
|
|
10
28
|
def initialize(arg_node, directive_node)
|
|
11
29
|
@arg_node = arg_node
|
|
12
30
|
@directive_node = directive_node
|
|
@@ -6,7 +6,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
6
6
|
# @eq — equality filter (the default). `field(status: String @eq)`
|
|
7
7
|
class Eq < Base
|
|
8
8
|
def self.directive_name = 'eq'
|
|
9
|
-
def self.definition = '
|
|
9
|
+
def self.definition = sdl('eq', 'Add an equality filter to the query: the column equals the value.')
|
|
10
10
|
|
|
11
11
|
def handle_builder(relation, value)
|
|
12
12
|
return relation if value.nil?
|
|
@@ -19,7 +19,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
19
19
|
# named; a list matches any of its values. `deletePosts(ids: [ID!]! @whereKey)`
|
|
20
20
|
class WhereKey < Base
|
|
21
21
|
def self.directive_name = 'whereKey'
|
|
22
|
-
def self.definition = '
|
|
22
|
+
def self.definition = sdl('whereKey', "Filter by the model's primary key, whatever its column is named. A list matches any of its values.", nil)
|
|
23
23
|
|
|
24
24
|
def handle_builder(relation, value)
|
|
25
25
|
return relation if value.nil?
|
|
@@ -31,7 +31,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
31
31
|
# @neq — inequality filter.
|
|
32
32
|
class Neq < Base
|
|
33
33
|
def self.directive_name = 'neq'
|
|
34
|
-
def self.definition = '
|
|
34
|
+
def self.definition = sdl('neq', 'Add an inequality filter to the query: the column differs from the value.')
|
|
35
35
|
|
|
36
36
|
def handle_builder(relation, value)
|
|
37
37
|
return relation if value.nil?
|
|
@@ -43,7 +43,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
43
43
|
# @in — value is one of a list.
|
|
44
44
|
class In < Base
|
|
45
45
|
def self.directive_name = 'in'
|
|
46
|
-
def self.definition = '
|
|
46
|
+
def self.definition = sdl('in', 'Filter by a list of values: the column is one of them.')
|
|
47
47
|
|
|
48
48
|
def handle_builder(relation, value)
|
|
49
49
|
return relation if value.nil?
|
|
@@ -55,7 +55,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
55
55
|
# @notIn — value is none of a list.
|
|
56
56
|
class NotIn < Base
|
|
57
57
|
def self.directive_name = 'notIn'
|
|
58
|
-
def self.definition = '
|
|
58
|
+
def self.definition = sdl('notIn', 'Filter by a list of values: the column is none of them.')
|
|
59
59
|
|
|
60
60
|
def handle_builder(relation, value)
|
|
61
61
|
return relation if value.nil?
|
|
@@ -67,7 +67,7 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
67
67
|
# @like — SQL LIKE with the value wrapped in wildcards.
|
|
68
68
|
class Like < Base
|
|
69
69
|
def self.directive_name = 'like'
|
|
70
|
-
def self.definition = '
|
|
70
|
+
def self.definition = sdl('like', 'Filter with SQL LIKE: the column contains the value, which is wrapped in wildcards.')
|
|
71
71
|
|
|
72
72
|
def handle_builder(relation, value)
|
|
73
73
|
return relation if value.nil?
|
|
@@ -80,7 +80,16 @@ module Lighthouse::GraphQL::Directives::Arguments
|
|
|
80
80
|
# the @whereConditions extension. `field(age: Int @where(operator: "GT"))`
|
|
81
81
|
class Where < Base
|
|
82
82
|
def self.directive_name = 'where'
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
def self.definition
|
|
85
|
+
sdl('where', 'Add a where condition to the query: the column compares to the value with an operator.',
|
|
86
|
+
"#{KEY_ARGUMENT}\n#{OPERATOR_ARGUMENT}")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
OPERATOR_ARGUMENT = argument_sdl(
|
|
90
|
+
'operator: String',
|
|
91
|
+
'The comparison: EQ (default), NEQ, GT, GTE, LT, LTE, IN, NIN, CONTAINS, STARTS_WITH, ENDS_WITH, IS_NULL or IS_NOT_NULL.'
|
|
92
|
+
)
|
|
84
93
|
|
|
85
94
|
# LIKE pattern of each wildcard operator, built from the client value.
|
|
86
95
|
LIKE_PATTERNS = {
|
|
@@ -8,10 +8,38 @@
|
|
|
8
8
|
module Lighthouse::GraphQL::Directives::Definitions
|
|
9
9
|
# Directives that only mark the SDL for others to read.
|
|
10
10
|
PASSIVE = {
|
|
11
|
-
'nest' =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
'nest' => <<~GRAPHQL.chomp,
|
|
12
|
+
"""
|
|
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
|
+
"""
|
|
16
|
+
directive @nest on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
|
|
17
|
+
GRAPHQL
|
|
18
|
+
'spread' => <<~GRAPHQL.chomp,
|
|
19
|
+
"""
|
|
20
|
+
On an argument of an input object type, merge the input's fields into the arguments
|
|
21
|
+
the field's resolver or mutation receives, as if they were the field's own.
|
|
22
|
+
"""
|
|
23
|
+
directive @spread on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
|
|
24
|
+
GRAPHQL
|
|
25
|
+
'inject' => <<~GRAPHQL.chomp,
|
|
26
|
+
"""
|
|
27
|
+
Set an argument from the request's context, on the server, so clients cannot set it.
|
|
28
|
+
"""
|
|
29
|
+
directive @inject(
|
|
30
|
+
"A path in the context, with dots: \\"current_user.id\\"."
|
|
31
|
+
context: String!
|
|
32
|
+
"The name of the argument to set, with dots for a nested one: \\"input.author_id\\"."
|
|
33
|
+
name: String!
|
|
34
|
+
) repeatable on FIELD_DEFINITION
|
|
35
|
+
GRAPHQL
|
|
36
|
+
'cacheKey' => <<~GRAPHQL.chomp
|
|
37
|
+
"""
|
|
38
|
+
Mark the field whose value identifies its object in the keys of @cache and @clearCache.
|
|
39
|
+
Without one, the first field of type ID is used.
|
|
40
|
+
"""
|
|
41
|
+
directive @cacheKey on FIELD_DEFINITION
|
|
42
|
+
GRAPHQL
|
|
15
43
|
}.freeze
|
|
16
44
|
|
|
17
45
|
module_function
|
|
@@ -38,8 +66,17 @@ module Lighthouse::GraphQL::Directives::Definitions
|
|
|
38
66
|
# @hasManyThrough and @hasOneThrough: @hasMany's and @hasOne's definitions, renamed.
|
|
39
67
|
def through_aliases
|
|
40
68
|
resolvers = Lighthouse::GraphQL::DirectiveResolvers
|
|
41
|
-
{
|
|
42
|
-
|
|
69
|
+
{
|
|
70
|
+
'hasManyThrough' => [resolvers::HasManyDirectiveResolver, <<~TEXT.chomp],
|
|
71
|
+
Resolve a one-to-many association of the parent that goes through another (`has_many :through`)
|
|
72
|
+
as a list, batch-loaded so that listing it for many parents is not an N+1.
|
|
73
|
+
With `type`, the list is paginated.
|
|
74
|
+
TEXT
|
|
75
|
+
'hasOneThrough' => [resolvers::HasOneDirectiveResolver, <<~TEXT.chomp]
|
|
76
|
+
Resolve a one-to-one association of the parent that goes through another (`has_one :through`),
|
|
77
|
+
batch-loaded so that loading it for many parents is not an N+1.
|
|
78
|
+
TEXT
|
|
79
|
+
}.to_h { |name, (klass, description)| [name, klass.definition(name, description)] }
|
|
43
80
|
end
|
|
44
81
|
|
|
45
82
|
# { type name => its SDL }, for the types the directives above refer to.
|
|
@@ -67,6 +67,18 @@ class Lighthouse::GraphQL::DocumentAST
|
|
|
67
67
|
self
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
# Drops the type of that name, if any.
|
|
71
|
+
def remove_type(name)
|
|
72
|
+
@types.delete(name)
|
|
73
|
+
self
|
|
74
|
+
end
|
|
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
|
+
|
|
70
82
|
# Adds the type parsed from `sdl`, unless the document has a type of that name.
|
|
71
83
|
def define_type(name, sdl = nil)
|
|
72
84
|
return @types[name] if @types.key?(name)
|
|
@@ -24,7 +24,12 @@ module Lighthouse::GraphQL::EnumDirective
|
|
|
24
24
|
) on ENUM_VALUE
|
|
25
25
|
GRAPHQL
|
|
26
26
|
|
|
27
|
-
TYPE_DEFINITIONS = {
|
|
27
|
+
TYPE_DEFINITIONS = {
|
|
28
|
+
'Mixed' => <<~GRAPHQL.chomp
|
|
29
|
+
"Loose type that allows any value. Be careful when passing in large JSON objects, as it may result in poor performance."
|
|
30
|
+
scalar Mixed
|
|
31
|
+
GRAPHQL
|
|
32
|
+
}.freeze
|
|
28
33
|
|
|
29
34
|
module_function
|
|
30
35
|
|
|
@@ -22,7 +22,19 @@ module Lighthouse::GraphQL::FeatureDirective
|
|
|
22
22
|
# Arguments with a default are nullable, not `Type! = default` as in PHP: graphql-ruby
|
|
23
23
|
# 2.5 does not fill in a directive argument's default, so a non-null one would be
|
|
24
24
|
# refused wherever it is left out. Left out or null, it takes its default.
|
|
25
|
-
DEFINITION =
|
|
25
|
+
DEFINITION = <<~GRAPHQL.chomp
|
|
26
|
+
"""
|
|
27
|
+
Include a field or an object type in the schema only while a feature flag is in a given state,
|
|
28
|
+
for the actor of the request (Flipper by default, see Config.feature_checker).
|
|
29
|
+
Otherwise, it is hidden from introspection and a query selecting it is invalid.
|
|
30
|
+
"""
|
|
31
|
+
directive @feature(
|
|
32
|
+
"The name of the feature flag."
|
|
33
|
+
name: String!
|
|
34
|
+
"The state the feature must be in for the element to be visible."
|
|
35
|
+
when: FeatureState = ACTIVE
|
|
36
|
+
) on FIELD_DEFINITION | OBJECT
|
|
37
|
+
GRAPHQL
|
|
26
38
|
|
|
27
39
|
TYPE_DEFINITIONS = {
|
|
28
40
|
'FeatureState' => <<~GRAPHQL.chomp
|
|
@@ -6,7 +6,8 @@ module Lighthouse::GraphQL
|
|
|
6
6
|
# of nil, and building the schema then fails to coerce it. Its own
|
|
7
7
|
# build_default_value already maps NullValue to nil; do the same here.
|
|
8
8
|
module NullDirectiveArguments
|
|
9
|
-
|
|
9
|
+
# graphql 2.6.14 added a third parameter (the type resolver): pass on whatever it takes.
|
|
10
|
+
def args_to_kwargs(arg_owner, node, *rest)
|
|
10
11
|
node.is_a?(::GraphQL::Language::Nodes::NullValue) ? nil : super
|
|
11
12
|
end
|
|
12
13
|
end
|
|
@@ -29,7 +30,28 @@ module Lighthouse::GraphQL
|
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def build_interface_type(definition, type_resolver, base_type)
|
|
32
|
-
Lighthouse::GraphQL::RootTypes.base_for(definition.name)
|
|
33
|
+
root = Lighthouse::GraphQL::RootTypes.base_for(definition.name)
|
|
34
|
+
return super unless root
|
|
35
|
+
|
|
36
|
+
type_resolver.register(root) if type_resolver.respond_to?(:register)
|
|
37
|
+
root
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# graphql 2.6.14 makes the class of every type before any is built, on
|
|
42
|
+
# base_types, and builds into it, whatever base build_object_type is given:
|
|
43
|
+
# seed the root types' with the app's (`Types::QueryType`, `Types::NodeType`).
|
|
44
|
+
module RootTypeClasses
|
|
45
|
+
def initialize(lookup_hash, directives, queued_directives, type_classes, &block)
|
|
46
|
+
super
|
|
47
|
+
# `keys`: the values change while it goes over them.
|
|
48
|
+
type_classes.keys.each do |name|
|
|
49
|
+
root = Lighthouse::GraphQL::RootTypes.base_for(name)
|
|
50
|
+
current = type_classes[name]
|
|
51
|
+
next if root.nil? || (current.is_a?(Class) ? current < root : current.equal?(root))
|
|
52
|
+
|
|
53
|
+
type_classes[name] = root.is_a?(Class) ? Class.new(root) { graphql_name(name) } : root
|
|
54
|
+
end
|
|
33
55
|
end
|
|
34
56
|
end
|
|
35
57
|
|
|
@@ -37,6 +59,8 @@ module Lighthouse::GraphQL
|
|
|
37
59
|
# root types are then built on base_types[:object], as before.
|
|
38
60
|
if builder && %i[build_object_type build_interface_type].all? { |name| builder.method_defined?(name) || builder.private_method_defined?(name) }
|
|
39
61
|
builder.prepend(RootTypeBuilder)
|
|
62
|
+
resolver = builder.const_get(:TypeResolver) if builder.const_defined?(:TypeResolver)
|
|
63
|
+
resolver.prepend(RootTypeClasses) if resolver&.method_defined?(:interface_module)
|
|
40
64
|
end
|
|
41
65
|
|
|
42
66
|
# The app's schema class inherits Lighthouse's (`class AppSchema <
|
|
@@ -78,9 +78,8 @@ module Lighthouse::IdeHelper
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def placeholder_only(sdl)
|
|
81
|
-
declared = sdl.to_s.match?(/^\s*scalar\s+_\b/) ? Set['_'] : Set.new
|
|
82
81
|
render('The schema does not build: only the `_` placeholder is declared until it does.',
|
|
83
|
-
|
|
82
|
+
placeholder_declared?(sdl) ? [] : [PLACEHOLDER_SCALAR])
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
# Config.ide_helper's refresh: the files in the Rails app's root, when the
|
|
@@ -110,7 +109,7 @@ module Lighthouse::IdeHelper
|
|
|
110
109
|
def programmatic_types_sdl(sdl, registry: Lighthouse::DirectiveRegistry.default, directives: directives_sdl(sdl, registry: registry))
|
|
111
110
|
declared = type_names(sdl) | type_names(directives)
|
|
112
111
|
generated_sdl = generated_types(sdl, declared, registry).sort_by(&:name).map(&:to_query_string)
|
|
113
|
-
generated_sdl.unshift(PLACEHOLDER_SCALAR) if
|
|
112
|
+
generated_sdl.unshift(PLACEHOLDER_SCALAR) if declared.exclude?('_')
|
|
114
113
|
|
|
115
114
|
render(
|
|
116
115
|
'Types the manipulation phase generates (Connection/Paginator types, whereConditions inputs, ...).',
|
|
@@ -128,9 +127,11 @@ module Lighthouse::IdeHelper
|
|
|
128
127
|
|
|
129
128
|
# The manipulation phase replaces the `_` placeholder (`where: _ @whereConditions`,
|
|
130
129
|
# `orderBy: _ @orderBy`), but the IDE reads the SDL as written, so it needs
|
|
131
|
-
# the placeholder declared.
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
# the placeholder declared. It is always declared, whether or not the SDL
|
|
131
|
+
# uses it yet, so the first `_` an author writes is not an error; only an SDL
|
|
132
|
+
# that declares it itself is left alone.
|
|
133
|
+
def placeholder_declared?(sdl)
|
|
134
|
+
sdl.to_s.match?(/^\s*scalar\s+_\b/)
|
|
134
135
|
end
|
|
135
136
|
|
|
136
137
|
def type_names(sdl)
|
|
@@ -21,7 +21,10 @@ module Lighthouse::GraphQL::ScalarCoercion
|
|
|
21
21
|
The class that reads and writes this scalar's values: coerce_input(value, context) and
|
|
22
22
|
coerce_result(value, context), as a GraphQL::Schema::Scalar.
|
|
23
23
|
"""
|
|
24
|
-
directive @scalar(
|
|
24
|
+
directive @scalar(
|
|
25
|
+
"The scalar class, looked up in Config.namespaces[:types]. A fully-qualified name is used as-is."
|
|
26
|
+
class: String!
|
|
27
|
+
) on SCALAR
|
|
25
28
|
GRAPHQL
|
|
26
29
|
|
|
27
30
|
module_function
|
|
@@ -7,6 +7,14 @@ namespace :lighthouse do
|
|
|
7
7
|
Lighthouse::IdeHelper.write(output_dir: output_dir).each { |path| puts "Wrote #{path}" }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
desc 'Print the final schema (SDL) to stdout, as clients see it (SCHEMA=AppSchema)'
|
|
11
|
+
task print_schema: :environment do
|
|
12
|
+
schema = Object.const_get(ENV.fetch('SCHEMA', 'AppSchema'))
|
|
13
|
+
puts schema.to_definition
|
|
14
|
+
rescue StandardError => e
|
|
15
|
+
abort("#{schema || 'Schema'} can not be printed: #{e.message}")
|
|
16
|
+
end
|
|
17
|
+
|
|
10
18
|
desc 'Build the schema cache in tmp/cache (for config.schema_cache; e.g. during a Docker build)'
|
|
11
19
|
task cache: :environment do
|
|
12
20
|
puts "Wrote #{Lighthouse::GraphQL::SchemaCache.warm!}"
|
|
@@ -26,14 +26,20 @@ module Lighthouse::GraphQL::TypeResolution
|
|
|
26
26
|
The class that picks the object type of this union's values: `resolve_type(object, context)`
|
|
27
27
|
or `call(object, context)`, returning a type name or a type class.
|
|
28
28
|
"""
|
|
29
|
-
directive @union(
|
|
29
|
+
directive @union(
|
|
30
|
+
"The class to call, looked up in Config.namespaces[:types]. A fully-qualified name is used as-is."
|
|
31
|
+
resolveType: String!
|
|
32
|
+
) on UNION
|
|
30
33
|
GRAPHQL
|
|
31
34
|
'interface' => <<~GRAPHQL.chomp
|
|
32
35
|
"""
|
|
33
36
|
The class that picks the object type of this interface's values: `resolve_type(object, context)`
|
|
34
37
|
or `call(object, context)`, returning a type name or a type class.
|
|
35
38
|
"""
|
|
36
|
-
directive @interface(
|
|
39
|
+
directive @interface(
|
|
40
|
+
"The class to call, looked up in Config.namespaces[:types]. A fully-qualified name is used as-is."
|
|
41
|
+
resolveType: String!
|
|
42
|
+
) on INTERFACE
|
|
37
43
|
GRAPHQL
|
|
38
44
|
}.freeze
|
|
39
45
|
|
data/sig/lighthouse/graphql.rbs
CHANGED
|
@@ -50,6 +50,8 @@ module Lighthouse
|
|
|
50
50
|
def add: (untyped definition) -> untyped
|
|
51
51
|
# Adds a type, or replaces the one of the same name.
|
|
52
52
|
def put_type: (untyped definition) -> self
|
|
53
|
+
def remove_type: (String name) -> self
|
|
54
|
+
def remove_directive: (String name) -> self
|
|
53
55
|
# Adds the type parsed from the SDL (or the block's), unless one of the name exists.
|
|
54
56
|
def define_type: (String name, ?String? sdl) ?{ () -> String } -> untyped
|
|
55
57
|
def type?: (String name) -> bool
|
|
@@ -61,6 +63,8 @@ module Lighthouse
|
|
|
61
63
|
# The manipulation phase: extensions merged, then the type, field and argument manipulators.
|
|
62
64
|
module ASTBuilder
|
|
63
65
|
ROOT_TYPES: Array[String]
|
|
66
|
+
# graphql-ruby's own directives, whose definitions the SDL may repeat.
|
|
67
|
+
BUILT_IN_DIRECTIVES: Array[String]
|
|
64
68
|
|
|
65
69
|
def self?.build: (String sdl, ?registry: DirectiveRegistry) -> String
|
|
66
70
|
end
|