lighthouse-graphql 0.9.1 → 0.10.0
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 +64 -1
- data/README.md +14 -8
- data/docs/configuration.md +4 -10
- data/docs/federation.md +250 -75
- data/docs/getting-started.md +2 -4
- data/docs/subscriptions.md +142 -2
- data/lib/generators/lighthouse/install/templates/initializer.rb.tt +2 -4
- data/lib/lighthouse/controller.rb +35 -8
- data/lib/lighthouse/directives/pagination_manipulator.rb +7 -1
- data/lib/lighthouse/event_stream.rb +188 -0
- data/lib/lighthouse/federation/any.rb +19 -0
- data/lib/lighthouse/federation/apollo_federation_check.rb +89 -0
- data/lib/lighthouse/federation/callback_subscriptions.rb +261 -0
- data/lib/lighthouse/federation/definitions.rb +83 -0
- data/lib/lighthouse/federation/entities.rb +265 -0
- data/lib/lighthouse/federation/link.rb +89 -0
- data/lib/lighthouse/federation/printer.rb +44 -0
- data/lib/lighthouse/federation.rb +145 -0
- data/lib/lighthouse/graphql/version.rb +1 -1
- data/lib/lighthouse/graphql_ruby_patches.rb +7 -1
- data/lib/lighthouse/namespaces.rb +1 -0
- data/lib/lighthouse/rb_lighthouse.rb +9 -2
- data/lib/lighthouse/scalar_coercion.rb +3 -2
- data/lib/lighthouse/schema_generator.rb +12 -17
- data/lib/lighthouse/schema_printer.rb +3 -1
- data/lib/lighthouse/type_resolution.rb +5 -4
- data/sig/lighthouse/federation.rbs +51 -0
- data/sig/lighthouse/graphql.rbs +29 -0
- data/sig/lighthouse.rbs +6 -0
- metadata +11 -3
- data/lib/lighthouse/federation_directives.rb +0 -53
- data/lib/lighthouse/reference_resolver.rb +0 -22
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Object-level Apollo Federation directives (@key, @extends, @shareable,
|
|
4
|
-
# @inaccessible, @interfaceObject) applied to the types built from SDL, so the
|
|
5
|
-
# Apollo Federation helper can detect entities and add _entities. Only types
|
|
6
|
-
# that know federation (they answer `key`) are touched.
|
|
7
|
-
module Lighthouse::GraphQL::FederationDirectives
|
|
8
|
-
# Directive => the type's federation method it calls. Each is called only
|
|
9
|
-
# when the type has it, so a partial federation setup still builds.
|
|
10
|
-
FLAGS = {
|
|
11
|
-
'extends' => :extend_type,
|
|
12
|
-
'shareable' => :shareable,
|
|
13
|
-
'inaccessible' => :inaccessible,
|
|
14
|
-
'interfaceObject' => :interface_object
|
|
15
|
-
}.freeze
|
|
16
|
-
|
|
17
|
-
module_function
|
|
18
|
-
|
|
19
|
-
def apply(type)
|
|
20
|
-
return unless type.ast_node && type.respond_to?(:key)
|
|
21
|
-
|
|
22
|
-
type.ast_node.directives.each do |dnode|
|
|
23
|
-
if dnode.name == 'key'
|
|
24
|
-
apply_key(type, dnode)
|
|
25
|
-
elsif (flag = FLAGS[dnode.name]) && type.respond_to?(flag)
|
|
26
|
-
type.public_send(flag)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def apply_key(type, dnode)
|
|
32
|
-
arg = dnode.arguments.find { |a| a.name == 'fields' }
|
|
33
|
-
type.key(fields: arg.value) if arg.respond_to?(:value)
|
|
34
|
-
|
|
35
|
-
resolve_references(type)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Setup federation resolve_reference: prefer a custom resolver
|
|
39
|
-
# registered with ReferenceResolver, but fall back to the base
|
|
40
|
-
# type's own resolve_reference (e.g. BaseObject's default model
|
|
41
|
-
# lookup) so direct-model entities resolve without a custom
|
|
42
|
-
# handler. Capture the inherited implementation before shadowing.
|
|
43
|
-
def resolve_references(type)
|
|
44
|
-
default_resolve_reference = type.respond_to?(:resolve_reference) ? type.method(:resolve_reference) : nil
|
|
45
|
-
|
|
46
|
-
type.define_singleton_method(:resolve_reference) do |reference, context|
|
|
47
|
-
resolved = ::Lighthouse::ReferenceResolver.resolve(type.graphql_name, reference, context)
|
|
48
|
-
next resolved unless resolved.nil?
|
|
49
|
-
|
|
50
|
-
default_resolve_reference&.call(reference, context)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class Lighthouse::ReferenceResolver
|
|
4
|
-
@resolvers = {}
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
def register(typename, &block)
|
|
8
|
-
@resolvers[typename.to_s] = block
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def resolve(typename, reference, context)
|
|
12
|
-
resolver = @resolvers[typename.to_s]
|
|
13
|
-
return nil unless resolver
|
|
14
|
-
|
|
15
|
-
resolver.call(reference, context)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def clear!
|
|
19
|
-
@resolvers.clear
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|