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.
@@ -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