stardust_rails 0.1.5 → 0.2.1
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/app/controllers/stardust/graphql_controller.rb +6 -2
- data/lib/stardust/graphql.rb +3 -0
- data/lib/stardust/graphql/collector.rb +81 -5
- data/lib/stardust/graphql/federated.rb +22 -0
- data/lib/stardust/graphql/field.rb +5 -1
- data/lib/stardust/graphql/interface.rb +40 -0
- data/lib/stardust/graphql/mutation.rb +4 -0
- data/lib/stardust/graphql/object.rb +13 -1
- data/lib/stardust/graphql/types/dsl.rb +4 -0
- data/lib/stardust/graphql/warden_patch.rb +16 -0
- data/lib/stardust/version.rb +1 -1
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa6e10e22d8d799f598f60255bb03c98b15cc4902b6ae4ccfbc34eb5965eda70
|
4
|
+
data.tar.gz: b69399a62c129c1641bb2b2ee50e4b014f93d7b6c9625df5ae3b62d82d1d0a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb54381d239ae21badd2bf78765e21a7b34c7b7ccee9c66454c3685f367529a6fc5e39e11b8791a74f27341a01a91709882fe72832d199ef7acedf7a509f0f81
|
7
|
+
data.tar.gz: e8bdf067a1fba4fb033915b4e8df979952d9183d7299c139dd90dbb7d8ad3268ac7f315212fd10169999ea458d5478338055534d92fa89f08141e1c426c46b3a
|
@@ -8,11 +8,11 @@ module Stardust
|
|
8
8
|
result = GraphQL::Schema.execute(
|
9
9
|
query,
|
10
10
|
variables: variables,
|
11
|
-
context: context,
|
11
|
+
context: context.merge({tracing_enabled: tracing_enabled}),
|
12
12
|
operation_name: operation_name
|
13
13
|
)
|
14
14
|
end
|
15
|
-
render json: result
|
15
|
+
render json: ApolloFederation::Tracing.attach_trace_to_result(result)
|
16
16
|
|
17
17
|
|
18
18
|
rescue Stardust::Errors::FailedAuthorization => e
|
@@ -39,6 +39,10 @@ module Stardust
|
|
39
39
|
ensure_hash(params[:variables])
|
40
40
|
end
|
41
41
|
|
42
|
+
def tracing_enabled
|
43
|
+
ApolloFederation::Tracing.should_add_traces(headers)
|
44
|
+
end
|
45
|
+
|
42
46
|
def context
|
43
47
|
setup_context = Stardust.configuration.graphql.setup_context
|
44
48
|
setup_context ? setup_context.(request) : {}
|
data/lib/stardust/graphql.rb
CHANGED
@@ -16,14 +16,17 @@ module Stardust
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
require "stardust/graphql/warden_patch"
|
19
20
|
require "stardust/graphql/collector"
|
20
21
|
require "stardust/graphql/configuration"
|
21
22
|
require "stardust/graphql/field"
|
22
23
|
require "stardust/graphql/input_object"
|
23
24
|
require "stardust/graphql/mutation"
|
25
|
+
require "stardust/graphql/interface"
|
24
26
|
require "stardust/graphql/object"
|
25
27
|
require "stardust/graphql/query"
|
26
28
|
require "stardust/graphql/scalar"
|
27
29
|
require "stardust/graphql/union"
|
28
30
|
require "stardust/graphql/extensions/authorize"
|
29
31
|
require "stardust/graphql/input_object"
|
32
|
+
require "stardust/graphql/federated"
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'apollo-federation/entities_field'
|
2
|
+
require 'apollo-federation/service_field'
|
3
|
+
require 'apollo-federation/any'
|
4
|
+
|
1
5
|
module Stardust
|
2
6
|
module GraphQL
|
3
7
|
module Collector
|
4
8
|
module_function
|
5
9
|
|
6
10
|
FIXED_TYPES = {
|
11
|
+
any: ApolloFederation::Any,
|
7
12
|
id: ::GraphQL::Types::ID,
|
8
13
|
int: Integer,
|
9
14
|
integer: Integer,
|
@@ -19,6 +24,7 @@ module Stardust
|
|
19
24
|
@@__defined_types__ = []
|
20
25
|
@@__queries__ = {}
|
21
26
|
@@__mutations__ = {}
|
27
|
+
@@__lookedup_types__ = []
|
22
28
|
|
23
29
|
def add_type(type, block, object_klass)
|
24
30
|
if type.in?(@@__types__.keys)
|
@@ -27,7 +33,18 @@ module Stardust
|
|
27
33
|
|
28
34
|
@@__defined_types__ << type.to_s.camelize
|
29
35
|
|
30
|
-
klass =
|
36
|
+
klass = nil
|
37
|
+
if object_klass.is_a?(Class)
|
38
|
+
klass = Class.new(object_klass, &block)
|
39
|
+
else
|
40
|
+
# interfaces are modules
|
41
|
+
klass = Module.new
|
42
|
+
klass.include(object_klass)
|
43
|
+
klass.module_eval(&block)
|
44
|
+
unless klass.graphql_name
|
45
|
+
klass.graphql_name type.to_s.camelize
|
46
|
+
end
|
47
|
+
end
|
31
48
|
|
32
49
|
begin
|
33
50
|
klass.graphql_name
|
@@ -46,6 +63,7 @@ module Stardust
|
|
46
63
|
end
|
47
64
|
|
48
65
|
@@__defined_types__ = []
|
66
|
+
@@__lookedup_types__ = []
|
49
67
|
@@__types__ = {}.merge(FIXED_TYPES)
|
50
68
|
@@__queries__ = {}
|
51
69
|
@@__mutations__ = {}
|
@@ -73,16 +91,27 @@ module Stardust
|
|
73
91
|
@@__queries__
|
74
92
|
end
|
75
93
|
|
94
|
+
def self.mutations
|
95
|
+
@@__mutations__
|
96
|
+
end
|
97
|
+
|
76
98
|
def self.lookup_type(type)
|
99
|
+
# puts "looking up #{type.class}: #{type}"
|
100
|
+
|
77
101
|
if type.is_a?(Array)
|
102
|
+
rest = type[1..-1]
|
78
103
|
type = type.first
|
79
104
|
is_a_array = true
|
80
105
|
end
|
81
106
|
|
82
107
|
raise MissingType, type.to_s unless @@__types__[type]
|
83
108
|
|
109
|
+
@@__lookedup_types__ << type
|
110
|
+
@@__lookedup_types__ = @@__lookedup_types__.uniq
|
111
|
+
|
112
|
+
|
84
113
|
if is_a_array
|
85
|
-
[@@__types__[type]]
|
114
|
+
[@@__types__[type]] + rest
|
86
115
|
else
|
87
116
|
@@__types__[type]
|
88
117
|
end
|
@@ -106,13 +135,48 @@ module Stardust
|
|
106
135
|
if Stardust::GraphQL.const_defined?("Schema")
|
107
136
|
Stardust::GraphQL.send(:remove_const, "Schema")
|
108
137
|
end
|
138
|
+
|
109
139
|
klass = Class.new(::GraphQL::Schema) do
|
140
|
+
include ::Stardust::GraphQL::Federated
|
141
|
+
use ApolloFederation::Tracing
|
110
142
|
use ::GraphQL::Batch
|
143
|
+
|
111
144
|
end
|
112
145
|
Stardust::GraphQL.const_set("Schema", klass)
|
113
146
|
|
114
|
-
|
115
|
-
|
147
|
+
|
148
|
+
# a lot of this is extracted from apollo federation gem
|
149
|
+
# to be used in stardust
|
150
|
+
query_class = Class.new(::Stardust::GraphQL::Object) do
|
151
|
+
graphql_name 'Query'
|
152
|
+
|
153
|
+
include ApolloFederation::EntitiesField
|
154
|
+
include ApolloFederation::ServiceField
|
155
|
+
end
|
156
|
+
|
157
|
+
possible_entities =
|
158
|
+
@@__types__
|
159
|
+
.values
|
160
|
+
.select{|i| i < Stardust::GraphQL::Object}
|
161
|
+
.map(&:to_graphql).select do |type|
|
162
|
+
!type.introspection? && !type.default_scalar? &&
|
163
|
+
type.metadata[:federation_directives]&.any? { |directive|
|
164
|
+
directive[:name] == 'key'
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
if !possible_entities.empty?
|
169
|
+
entity_type = Class.new(ApolloFederation::Entity) do
|
170
|
+
possible_types(*possible_entities)
|
171
|
+
end
|
172
|
+
|
173
|
+
@@__types__[:_frederated_entities] = entity_type
|
174
|
+
|
175
|
+
query_class.field(:_entities, [:_frederated_entities, null: true], null: false) do
|
176
|
+
argument :representations, [:any], required: true
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
116
180
|
@@__queries__.each do |name, query|
|
117
181
|
|
118
182
|
block = ->(field) {
|
@@ -149,7 +213,7 @@ module Stardust
|
|
149
213
|
|
150
214
|
|
151
215
|
mutation_class = Class.new(::GraphQL::Schema::Object)
|
152
|
-
mutation_class.graphql_name("
|
216
|
+
mutation_class.graphql_name("Mutation")
|
153
217
|
@@__mutations__.each do |name, mutation|
|
154
218
|
begin
|
155
219
|
mutation.replace_types!
|
@@ -164,6 +228,18 @@ module Stardust
|
|
164
228
|
end
|
165
229
|
end
|
166
230
|
Stardust::GraphQL::Schema.mutation(mutation_class)
|
231
|
+
|
232
|
+
#
|
233
|
+
# orphaned_types =
|
234
|
+
# @@__types__
|
235
|
+
# .select{|k,v|
|
236
|
+
# !k.in?(@@__lookedup_types__) &&
|
237
|
+
# v < Stardust::GraphQL::Object
|
238
|
+
# }
|
239
|
+
# .values
|
240
|
+
# .map(&:to_graphql)
|
241
|
+
#
|
242
|
+
# Stardust::GraphQL::Schema.orphan_types orphaned_types
|
167
243
|
end
|
168
244
|
end
|
169
245
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'apollo-federation/federated_document_from_schema_definition.rb'
|
2
|
+
|
3
|
+
module Stardust
|
4
|
+
module GraphQL
|
5
|
+
module Federated
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def federation_sdl
|
13
|
+
# remove this hack once this https://github.com/apollographql/apollo-server/issues/3100 gets fixed
|
14
|
+
@federation_sdl ||= begin
|
15
|
+
document_from_schema = ApolloFederation::FederatedDocumentFromSchemaDefinition.new(self)
|
16
|
+
::GraphQL::Language::Printer.new.print(document_from_schema.document).gsub("schema {\n query: Query\n mutation: MutationRoot\n}\n\n", "")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'apollo-federation'
|
2
|
+
|
1
3
|
module Stardust
|
2
4
|
module GraphQL
|
3
5
|
class Field < ::GraphQL::Schema::Field
|
4
6
|
|
7
|
+
include ApolloFederation::Field
|
8
|
+
|
5
9
|
def initialize(*args, **kwargs, &block)
|
6
|
-
super(*args, **kwargs, &block)
|
10
|
+
super(*args, connection: false, **kwargs, &block)
|
7
11
|
end
|
8
12
|
|
9
13
|
def authorize(proc, &block)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stardust
|
2
|
+
module GraphQL
|
3
|
+
module Interface
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.module_eval do
|
7
|
+
include ::GraphQL::Schema::Interface
|
8
|
+
|
9
|
+
def self.graphql_name(name = nil)
|
10
|
+
if name
|
11
|
+
@__graphql_name__ = name
|
12
|
+
else
|
13
|
+
@__graphql_name__
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.field(name, type, description = nil, **kwargs, &block)
|
18
|
+
|
19
|
+
@__types_to_lookup__ ||= []
|
20
|
+
@__types_to_lookup__ << ->(klass) {
|
21
|
+
actual_type = Collector.lookup_type(type)
|
22
|
+
|
23
|
+
klass
|
24
|
+
.method(:field)
|
25
|
+
.super_method
|
26
|
+
.call(name, actual_type, description, **kwargs, &block)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.replace_types!
|
31
|
+
return unless @__types_to_lookup__
|
32
|
+
@__types_to_lookup__.each {|lookup| lookup.(self)}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
base
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,11 +1,23 @@
|
|
1
1
|
module Stardust
|
2
2
|
module GraphQL
|
3
3
|
class Object < ::GraphQL::Schema::Object
|
4
|
+
include ApolloFederation::Object
|
4
5
|
|
5
6
|
field_class Field
|
6
7
|
|
7
|
-
def self.
|
8
|
+
def self.implements(type)
|
9
|
+
@__types_to_lookup__ ||= []
|
10
|
+
@__types_to_lookup__ << ->(klass) {
|
11
|
+
actual_type = Collector.lookup_type(type)
|
12
|
+
|
13
|
+
klass
|
14
|
+
.method(:implements)
|
15
|
+
.super_method
|
16
|
+
.call(actual_type)
|
17
|
+
}
|
18
|
+
end
|
8
19
|
|
20
|
+
def self.field(name, type, description = nil, **kwargs, &block)
|
9
21
|
@__types_to_lookup__ ||= []
|
10
22
|
@__types_to_lookup__ << ->(klass) {
|
11
23
|
actual_type = Collector.lookup_type(type)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stardust
|
2
|
+
module GraphQL
|
3
|
+
module WardenPatch
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
# Basically since we want to see
|
8
|
+
# federated fields we want to included orphan_types
|
9
|
+
def referenced?(type_defn)
|
10
|
+
super || @schema.orphan_types.include?(type_defn)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
::GraphQL::Schema::Warden.prepend Stardust::GraphQL::WardenPatch
|
data/lib/stardust/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stardust_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bradley Wittenbrook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.4.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: apollo-federation
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.0
|
97
111
|
description: Modernize API development in Rails
|
98
112
|
email:
|
99
113
|
- bradley.wittenbrook@gmail.com
|
@@ -128,8 +142,10 @@ files:
|
|
128
142
|
- lib/stardust/graphql/configuration.rb
|
129
143
|
- lib/stardust/graphql/dsl.rb
|
130
144
|
- lib/stardust/graphql/extensions/authorize.rb
|
145
|
+
- lib/stardust/graphql/federated.rb
|
131
146
|
- lib/stardust/graphql/field.rb
|
132
147
|
- lib/stardust/graphql/input_object.rb
|
148
|
+
- lib/stardust/graphql/interface.rb
|
133
149
|
- lib/stardust/graphql/mutation.rb
|
134
150
|
- lib/stardust/graphql/object.rb
|
135
151
|
- lib/stardust/graphql/query.rb
|
@@ -137,10 +153,11 @@ files:
|
|
137
153
|
- lib/stardust/graphql/types.rb
|
138
154
|
- lib/stardust/graphql/types/dsl.rb
|
139
155
|
- lib/stardust/graphql/union.rb
|
156
|
+
- lib/stardust/graphql/warden_patch.rb
|
140
157
|
- lib/stardust/instance.rb
|
141
158
|
- lib/stardust/version.rb
|
142
159
|
- lib/tasks/stardust_tasks.rake
|
143
|
-
homepage: https://github.com/
|
160
|
+
homepage: https://github.com/parablesoft/stardust_rails
|
144
161
|
licenses:
|
145
162
|
- MIT
|
146
163
|
metadata:
|
@@ -161,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
178
|
version: '0'
|
162
179
|
requirements: []
|
163
180
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.7.
|
181
|
+
rubygems_version: 2.7.10
|
165
182
|
signing_key:
|
166
183
|
specification_version: 4
|
167
184
|
summary: GraphQL + Rails = Programmer Bliss
|