hq-graphql 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +11 -9
- data/lib/hq/graphql/active_record_extensions.rb +25 -8
- data/lib/hq/graphql/config.rb +12 -0
- data/lib/hq/graphql/engine.rb +3 -0
- data/lib/hq/graphql/input_object.rb +6 -7
- data/lib/hq/graphql/inputs.rb +4 -2
- data/lib/hq/graphql/mutation.rb +3 -1
- data/lib/hq/graphql/object.rb +4 -2
- data/lib/hq/graphql/resource/mutation.rb +3 -2
- data/lib/hq/graphql/resource.rb +54 -11
- data/lib/hq/graphql/root_mutation.rb +3 -2
- data/lib/hq/graphql/root_query.rb +3 -2
- data/lib/hq/graphql/scalars.rb +3 -0
- data/lib/hq/graphql/types/object.rb +8 -3
- data/lib/hq/graphql/types/uuid.rb +11 -2
- data/lib/hq/graphql/types.rb +21 -16
- data/lib/hq/graphql/version.rb +4 -1
- data/lib/hq/graphql.rb +16 -3
- data/lib/hq-graphql.rb +6 -0
- metadata +159 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f7f2421a64474e031ddd0a97ef63d36c03218fdfc51bf759f0f1150e1ae5cb
|
4
|
+
data.tar.gz: 19addd42ac2c2f4bae1b985cacbda91998a3616b71f2e9923e19e89e8937d111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0777580cb64e038700a3d16e6a20ef1883fe5d39575a7d7db13df5e64950bf263946581463546b6dfe53ec4aab262a07cc9114896c7755c1aaf2428e3a81c22a'
|
7
|
+
data.tar.gz: e51c0b4555486894697b81420264f6abd515bb81eeeff5df4869b0a3ebb46430e6a20a3c5179e4a6d1b32e930e7253e2706377dc127394b8a66d53831986a3da
|
data/Rakefile
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "bundler/setup"
|
3
5
|
rescue LoadError
|
4
|
-
puts
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
7
|
end
|
6
8
|
|
7
|
-
require
|
9
|
+
require "rdoc/task"
|
8
10
|
|
9
11
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title =
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
12
|
+
rdoc.rdoc_dir = "rdoc"
|
13
|
+
rdoc.title = "HQ::GraphQL"
|
14
|
+
rdoc.options << "--line-numbers"
|
15
|
+
rdoc.rdoc_files.include("README.rdoc")
|
16
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
17
|
end
|
16
18
|
|
17
|
-
require
|
19
|
+
require "bundler/gem_tasks"
|
@@ -1,27 +1,34 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module ActiveRecordExtensions
|
4
|
-
|
5
|
-
|
6
|
-
MISSING_ATTR_MSG = "Can't find attr %{model}.%{attr}'`".freeze
|
7
|
-
MISSING_ASSOC_MSG = "Can't find association %{model}.%{assoc}'`".freeze
|
8
|
-
end
|
7
|
+
extend T::Sig
|
8
|
+
extend T::Helpers
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
class Error < StandardError
|
11
|
+
MISSING_MODEL_MSG = "Your GraphQL object must be connected to a model: `::HQ::GraphQL::Object.with_model 'User'`"
|
12
|
+
MISSING_ATTR_MSG = "Can't find attr %{model}.%{attr}'`"
|
13
|
+
MISSING_ASSOC_MSG = "Can't find association %{model}.%{assoc}'`"
|
12
14
|
end
|
13
15
|
|
14
16
|
module ClassMethods
|
17
|
+
extend T::Sig
|
18
|
+
include Kernel
|
19
|
+
|
15
20
|
attr_accessor :model_name,
|
16
21
|
:auto_load_attributes,
|
17
22
|
:auto_load_associations
|
18
23
|
|
24
|
+
sig { params(block: T.nilable(T.proc.void)).returns(T::Array[T.proc.void]) }
|
19
25
|
def lazy_load(&block)
|
20
26
|
@lazy_load ||= []
|
21
27
|
@lazy_load << block if block
|
22
28
|
@lazy_load
|
23
29
|
end
|
24
30
|
|
31
|
+
sig { void }
|
25
32
|
def lazy_load!
|
26
33
|
lazy_load.map(&:call)
|
27
34
|
@lazy_load = []
|
@@ -57,6 +64,7 @@ module HQ
|
|
57
64
|
|
58
65
|
private
|
59
66
|
|
67
|
+
sig { params(attrs: T.any(String, Symbol)).void }
|
60
68
|
def add_attributes(*attrs)
|
61
69
|
validate_model!
|
62
70
|
added_attributes.concat attrs.map(&:to_sym)
|
@@ -65,6 +73,7 @@ module HQ
|
|
65
73
|
alias_method :add_attrs, :add_attributes
|
66
74
|
alias_method :add_attr, :add_attributes
|
67
75
|
|
76
|
+
sig { params(attrs: T.any(String, Symbol)).void }
|
68
77
|
def remove_attributes(*attrs)
|
69
78
|
validate_model!
|
70
79
|
removed_attributes.concat attrs.map(&:to_sym)
|
@@ -73,12 +82,14 @@ module HQ
|
|
73
82
|
alias_method :remove_attrs, :remove_attributes
|
74
83
|
alias_method :remove_attr, :remove_attributes
|
75
84
|
|
85
|
+
sig { params(associations: T.any(String, Symbol)).void }
|
76
86
|
def add_associations(*associations)
|
77
87
|
validate_model!
|
78
88
|
added_associations.concat associations.map(&:to_sym)
|
79
89
|
end
|
80
90
|
alias_method :add_association, :add_associations
|
81
91
|
|
92
|
+
sig { params(associations: T.any(String, Symbol)).void }
|
82
93
|
def remove_associations(*associations)
|
83
94
|
validate_model!
|
84
95
|
removed_associations.concat associations.map(&:to_sym)
|
@@ -89,6 +100,7 @@ module HQ
|
|
89
100
|
@model_klass ||= model_name.constantize
|
90
101
|
end
|
91
102
|
|
103
|
+
sig { params(attr: Symbol).returns(T.untyped) }
|
92
104
|
def column_from_model(attr)
|
93
105
|
model_klass.columns_hash[attr.to_s] || raise(Error, Error::MISSING_ATTR_MSG % { model: model_name, attr: attr })
|
94
106
|
end
|
@@ -97,29 +109,34 @@ module HQ
|
|
97
109
|
model_klass.reflect_on_association(association) || raise(Error, Error::MISSING_ASSOC_MSG % { model: model_name, assoc: association })
|
98
110
|
end
|
99
111
|
|
112
|
+
sig { returns(T::Array[Symbol]) }
|
100
113
|
def added_attributes
|
101
114
|
@added_attributes ||= []
|
102
115
|
end
|
103
116
|
|
117
|
+
sig { returns(T::Array[Symbol]) }
|
104
118
|
def removed_attributes
|
105
119
|
@removed_attributes ||= []
|
106
120
|
end
|
107
121
|
|
122
|
+
sig { returns(T::Array[Symbol]) }
|
108
123
|
def added_associations
|
109
124
|
@added_associations ||= []
|
110
125
|
end
|
111
126
|
|
127
|
+
sig { returns(T::Array[Symbol]) }
|
112
128
|
def removed_associations
|
113
129
|
@removed_associations ||= []
|
114
130
|
end
|
115
131
|
|
132
|
+
sig { void }
|
116
133
|
def validate_model!
|
117
134
|
lazy_load do
|
118
135
|
model_name || raise(Error, Error::MISSING_MODEL_MSG)
|
119
136
|
end
|
120
137
|
end
|
121
|
-
|
122
138
|
end
|
139
|
+
mixes_in_class_methods(ClassMethods)
|
123
140
|
end
|
124
141
|
end
|
125
142
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# typed: strict
|
4
|
+
|
5
|
+
module HQ
|
6
|
+
module GraphQL
|
7
|
+
class Config < T::Struct
|
8
|
+
DefaultScopeProc = T.type_alias(T.proc.params(arg0: T.untyped, arg1: ::GraphQL::Query::Context).returns(T.untyped))
|
9
|
+
prop :default_scope, DefaultScopeProc, default: ->(scope, _context) { scope }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/hq/graphql/engine.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
class InputObject < ::GraphQL::Schema::InputObject
|
7
|
+
extend T::Sig
|
4
8
|
include Scalars
|
5
9
|
include ::HQ::GraphQL::ActiveRecordExtensions
|
6
10
|
|
@@ -25,12 +29,8 @@ module HQ
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def with_indifferent_access
|
29
|
-
to_h.with_indifferent_access
|
30
|
-
end
|
31
|
-
|
32
32
|
#### Class Methods ####
|
33
|
-
|
33
|
+
sig { params(model_name: String, attributes: T::Boolean, associations: T::Boolean).void }
|
34
34
|
def self.with_model(model_name, attributes: true, associations: false)
|
35
35
|
self.model_name = model_name
|
36
36
|
self.auto_load_attributes = attributes
|
@@ -72,7 +72,7 @@ module HQ
|
|
72
72
|
argument name, input, required: false
|
73
73
|
end
|
74
74
|
|
75
|
-
if !model_klass.nested_attributes_options.
|
75
|
+
if !model_klass.nested_attributes_options.key?(name.to_sym)
|
76
76
|
model_klass.accepts_nested_attributes_for name, allow_destroy: true
|
77
77
|
end
|
78
78
|
|
@@ -85,7 +85,6 @@ module HQ
|
|
85
85
|
argument column.name, ::HQ::GraphQL::Types.type_from_column(column), required: false
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|
data/lib/hq/graphql/inputs.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module Inputs
|
4
7
|
class Error < StandardError
|
5
|
-
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing."
|
8
|
+
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing."
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.[](key)
|
@@ -26,7 +29,6 @@ module HQ
|
|
26
29
|
raise(Error, Error::MISSING_TYPE_MSG % { klass: klass.name })
|
27
30
|
end
|
28
31
|
end
|
29
|
-
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/hq/graphql/mutation.rb
CHANGED
data/lib/hq/graphql/object.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
class Object < ::GraphQL::Schema::Object
|
@@ -42,10 +45,9 @@ module HQ
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def field_from_column(column)
|
45
|
-
field column.name, ::HQ::GraphQL::Types.type_from_column(column), null:
|
48
|
+
field column.name, ::HQ::GraphQL::Types.type_from_column(column), null: true
|
46
49
|
end
|
47
50
|
end
|
48
|
-
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module Resource
|
4
7
|
module Mutation
|
5
|
-
|
6
8
|
def self.build(model_name, graphql_name:, require_primary_key: false, &block)
|
7
9
|
Class.new(::HQ::GraphQL::Mutation) do
|
8
10
|
graphql_name graphql_name
|
@@ -29,7 +31,6 @@ module HQ
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
|
-
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
data/lib/hq/graphql/resource.rb
CHANGED
@@ -1,24 +1,38 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
require "hq/graphql/resource/mutation"
|
2
5
|
|
3
6
|
module HQ
|
4
7
|
module GraphQL
|
5
8
|
module Resource
|
9
|
+
extend T::Helpers
|
6
10
|
|
7
11
|
def self.included(base)
|
12
|
+
super
|
8
13
|
::HQ::GraphQL.types << base
|
9
14
|
base.include Scalars
|
10
|
-
base.extend ClassMethods
|
11
15
|
end
|
12
16
|
|
13
17
|
module ClassMethods
|
14
18
|
attr_writer :graphql_name, :model_name
|
15
19
|
|
20
|
+
def scope(context)
|
21
|
+
scope = model_klass
|
22
|
+
scope = ::HQ::GraphQL.default_scope(scope, context)
|
23
|
+
@default_scope&.call(scope, context) || scope
|
24
|
+
end
|
25
|
+
|
16
26
|
def find_record(attrs, context)
|
17
27
|
primary_key = model_klass.primary_key.to_sym
|
18
28
|
primary_key_value = attrs[primary_key]
|
19
29
|
scope(context).find_by(primary_key => primary_key_value)
|
20
30
|
end
|
21
31
|
|
32
|
+
def new_record(context)
|
33
|
+
scope(context).new
|
34
|
+
end
|
35
|
+
|
22
36
|
def graphql_name
|
23
37
|
@graphql_name || model_name.demodulize
|
24
38
|
end
|
@@ -53,7 +67,7 @@ module HQ
|
|
53
67
|
@input_klass = build_input_object(**options, &block)
|
54
68
|
end
|
55
69
|
|
56
|
-
def mutations(create: true, update: true, destroy: true)
|
70
|
+
def mutations(create: true, copy: true, update: true, destroy: true)
|
57
71
|
scoped_graphql_name = graphql_name
|
58
72
|
scoped_model_name = model_name
|
59
73
|
scoped_self = self
|
@@ -61,7 +75,7 @@ module HQ
|
|
61
75
|
if create
|
62
76
|
create_mutation = ::HQ::GraphQL::Resource::Mutation.build(model_name, graphql_name: "#{scoped_graphql_name}Create") do
|
63
77
|
define_method(:resolve) do |**args|
|
64
|
-
resource = scoped_self.
|
78
|
+
resource = scoped_self.new_record(context)
|
65
79
|
resource.assign_attributes(args[:attributes].format_nested_attributes)
|
66
80
|
if resource.save
|
67
81
|
{
|
@@ -84,6 +98,40 @@ module HQ
|
|
84
98
|
mutation_klasses["create_#{scoped_graphql_name.underscore}"] = create_mutation
|
85
99
|
end
|
86
100
|
|
101
|
+
if copy
|
102
|
+
copy_mutation = ::HQ::GraphQL::Resource::Mutation.build(
|
103
|
+
model_name,
|
104
|
+
graphql_name: "#{scoped_graphql_name}Copy",
|
105
|
+
require_primary_key: true
|
106
|
+
) do
|
107
|
+
define_method(:resolve) do |**args|
|
108
|
+
resource = scoped_self.find_record(args, context)
|
109
|
+
|
110
|
+
if resource
|
111
|
+
copy = resource.copy
|
112
|
+
if copy.save
|
113
|
+
{
|
114
|
+
resource: copy,
|
115
|
+
errors: {},
|
116
|
+
}
|
117
|
+
else
|
118
|
+
{
|
119
|
+
resource: copy,
|
120
|
+
errors: errors_from_resource(copy)
|
121
|
+
}
|
122
|
+
end
|
123
|
+
else
|
124
|
+
{
|
125
|
+
resource: nil,
|
126
|
+
errors: { resource: "Unable to find #{scoped_graphql_name}" }
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
mutation_klasses["copy_#{scoped_graphql_name.underscore}"] = copy_mutation
|
133
|
+
end
|
134
|
+
|
87
135
|
if update
|
88
136
|
update_mutation = ::HQ::GraphQL::Resource::Mutation.build(
|
89
137
|
model_name,
|
@@ -194,19 +242,13 @@ module HQ
|
|
194
242
|
|
195
243
|
if find_all
|
196
244
|
def_root field_name.pluralize, is_array: true, null: false do
|
197
|
-
define_method(:resolve) do |**
|
245
|
+
define_method(:resolve) do |**_attrs|
|
198
246
|
scoped_self.scope(context).all
|
199
247
|
end
|
200
248
|
end
|
201
249
|
end
|
202
250
|
end
|
203
251
|
|
204
|
-
def scope(context)
|
205
|
-
scope = model_klass
|
206
|
-
scope = ::HQ::GraphQL.default_scope(scope, context)
|
207
|
-
@default_scope&.call(scope, context) || scope
|
208
|
-
end
|
209
|
-
|
210
252
|
private
|
211
253
|
|
212
254
|
def build_graphql_object(**options, &block)
|
@@ -232,8 +274,9 @@ module HQ
|
|
232
274
|
class_eval(&block) if block
|
233
275
|
end
|
234
276
|
end
|
235
|
-
|
236
277
|
end
|
278
|
+
|
279
|
+
mixes_in_class_methods(ClassMethods)
|
237
280
|
end
|
238
281
|
end
|
239
282
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
class RootMutation < ::HQ::GraphQL::Object
|
4
|
-
|
5
7
|
def self.inherited(base)
|
6
8
|
super
|
7
9
|
base.class_eval do
|
@@ -14,7 +16,6 @@ module HQ
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
class RootQuery < ::HQ::GraphQL::Object
|
4
|
-
|
5
7
|
def self.inherited(base)
|
6
8
|
super
|
7
9
|
base.class_eval do
|
@@ -12,7 +14,6 @@ module HQ
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/hq/graphql/scalars.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module Types
|
@@ -5,11 +8,13 @@ module HQ
|
|
5
8
|
description "Object"
|
6
9
|
|
7
10
|
class << self
|
8
|
-
|
11
|
+
extend T::Sig
|
12
|
+
|
13
|
+
def coerce_input(value, _context)
|
9
14
|
validate_and_return_object(value)
|
10
15
|
end
|
11
16
|
|
12
|
-
def coerce_result(value,
|
17
|
+
def coerce_result(value, _context)
|
13
18
|
validate_and_return_object(value)
|
14
19
|
end
|
15
20
|
|
@@ -23,10 +28,10 @@ module HQ
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
31
|
+
sig { params(value: T.untyped).returns(T::Boolean) }
|
26
32
|
def validate_object(value)
|
27
33
|
value.is_a?(Hash)
|
28
34
|
end
|
29
|
-
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module Types
|
@@ -5,16 +8,21 @@ module HQ
|
|
5
8
|
description "UUID"
|
6
9
|
|
7
10
|
class << self
|
8
|
-
|
11
|
+
extend T::Sig
|
12
|
+
|
13
|
+
sig { params(value: T.untyped, _context: T.untyped).returns(String) }
|
14
|
+
def coerce_input(value, _context)
|
9
15
|
validate_and_return_uuid(value)
|
10
16
|
end
|
11
17
|
|
12
|
-
|
18
|
+
sig { params(value: T.untyped, _context: T.untyped).returns(String) }
|
19
|
+
def coerce_result(value, _context)
|
13
20
|
validate_and_return_uuid(value)
|
14
21
|
end
|
15
22
|
|
16
23
|
private
|
17
24
|
|
25
|
+
sig { params(value: T.untyped).returns(String) }
|
18
26
|
def validate_and_return_uuid(value)
|
19
27
|
if validate_uuid(value)
|
20
28
|
value
|
@@ -23,6 +31,7 @@ module HQ
|
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
34
|
+
sig { params(value: T.untyped).returns(T::Boolean) }
|
26
35
|
def validate_uuid(value)
|
27
36
|
!!value.to_s.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
|
28
37
|
end
|
data/lib/hq/graphql/types.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module HQ
|
2
5
|
module GraphQL
|
3
6
|
module Types
|
4
7
|
class Error < StandardError
|
5
|
-
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing."
|
8
|
+
MISSING_TYPE_MSG = "The GraphQL type for `%{klass}` is missing."
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.[](key)
|
@@ -13,20 +16,23 @@ module HQ
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def self.type_from_column(column)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
graphql_type =
|
20
|
+
case column.type
|
21
|
+
when :uuid
|
22
|
+
::HQ::GraphQL::Types::UUID
|
23
|
+
when :json, :jsonb
|
24
|
+
::HQ::GraphQL::Types::Object
|
25
|
+
when :integer
|
26
|
+
::GraphQL::Types::Int
|
27
|
+
when :decimal
|
28
|
+
::GraphQL::Types::Float
|
29
|
+
when :boolean
|
30
|
+
::GraphQL::Types::Boolean
|
31
|
+
else
|
32
|
+
::GraphQL::Types::String
|
33
|
+
end
|
34
|
+
|
35
|
+
column.array ? [graphql_type] : graphql_type
|
30
36
|
end
|
31
37
|
|
32
38
|
# Only being used in testing
|
@@ -44,7 +50,6 @@ module HQ
|
|
44
50
|
raise(Error, Error::MISSING_TYPE_MSG % { klass: klass.name })
|
45
51
|
end
|
46
52
|
end
|
47
|
-
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
data/lib/hq/graphql/version.rb
CHANGED
data/lib/hq/graphql.rb
CHANGED
@@ -1,20 +1,33 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "rails"
|
1
5
|
require "graphql"
|
6
|
+
require "sorbet-runtime"
|
7
|
+
require "hq/graphql/config"
|
2
8
|
|
3
9
|
module HQ
|
4
10
|
module GraphQL
|
11
|
+
extend T::Sig
|
12
|
+
extend T::Generic
|
13
|
+
|
14
|
+
@config = T.let(::HQ::GraphQL::Config.new, ::HQ::GraphQL::Config)
|
5
15
|
|
16
|
+
sig { returns(::HQ::GraphQL::Config) }
|
6
17
|
def self.config
|
7
|
-
@config
|
18
|
+
@config
|
8
19
|
end
|
9
20
|
|
10
21
|
def self.configure(&block)
|
11
22
|
config.instance_eval(&block)
|
12
23
|
end
|
13
24
|
|
25
|
+
sig { params(scope: T.untyped, context: ::GraphQL::Query::Context).returns(T.untyped) }
|
14
26
|
def self.default_scope(scope, context)
|
15
|
-
config.default_scope
|
27
|
+
config.default_scope.call(scope, context)
|
16
28
|
end
|
17
29
|
|
30
|
+
sig { void }
|
18
31
|
def self.reset!
|
19
32
|
@root_queries = nil
|
20
33
|
@types = nil
|
@@ -26,10 +39,10 @@ module HQ
|
|
26
39
|
@root_queries ||= Set.new
|
27
40
|
end
|
28
41
|
|
42
|
+
# sig { returns(T::Set[::HQ::GraphQL::Resource]) }
|
29
43
|
def self.types
|
30
44
|
@types ||= Set.new
|
31
45
|
end
|
32
|
-
|
33
46
|
end
|
34
47
|
end
|
35
48
|
|
data/lib/hq-graphql.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hq-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: graphql
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,45 +45,187 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.9.6
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: pg
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '1.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.1'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: sorbet-runtime
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
54
72
|
- - ">="
|
55
73
|
- !ruby/object:Gem::Version
|
56
|
-
version: 0
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: byebug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '11.0'
|
57
82
|
type: :development
|
58
83
|
prerelease: false
|
59
84
|
version_requirements: !ruby/object:Gem::Requirement
|
60
85
|
requirements:
|
61
86
|
- - "~>"
|
62
87
|
- !ruby/object:Gem::Version
|
63
|
-
version: '0
|
64
|
-
|
88
|
+
version: '11.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: combustion
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
65
94
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
95
|
+
version: '1.1'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.1'
|
67
103
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
104
|
+
name: database_cleaner
|
69
105
|
requirement: !ruby/object:Gem::Requirement
|
70
106
|
requirements:
|
71
107
|
- - "~>"
|
72
108
|
- !ruby/object:Gem::Version
|
73
|
-
version: '1.
|
109
|
+
version: '1.7'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.7'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: factory_bot_rails
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '5.0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '5.0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: faker
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '2.1'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '2.1'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: rspec
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '3.8'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - "~>"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '3.8'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rspec-rails
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
74
163
|
- - ">="
|
75
164
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
165
|
+
version: 4.0.0beta2
|
77
166
|
type: :development
|
78
167
|
prerelease: false
|
79
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 4.0.0beta2
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: rubocop
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
80
176
|
requirements:
|
81
177
|
- - "~>"
|
82
178
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
179
|
+
version: '0.7'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0.7'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: rubocop-performance
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - "~>"
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '1.4'
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - "~>"
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '1.4'
|
201
|
+
- !ruby/object:Gem::Dependency
|
202
|
+
name: rubocop-rails
|
203
|
+
requirement: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - "~>"
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '2.3'
|
208
|
+
type: :development
|
209
|
+
prerelease: false
|
210
|
+
version_requirements: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - "~>"
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '2.3'
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: sorbet
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
type: :development
|
223
|
+
prerelease: false
|
224
|
+
version_requirements: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
84
226
|
- - ">="
|
85
227
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
228
|
+
version: '0'
|
87
229
|
description: OneHQ GraphQL Library
|
88
230
|
email:
|
89
231
|
- dpjones09@gmail.com
|
@@ -97,6 +239,7 @@ files:
|
|
97
239
|
- lib/hq-graphql.rb
|
98
240
|
- lib/hq/graphql.rb
|
99
241
|
- lib/hq/graphql/active_record_extensions.rb
|
242
|
+
- lib/hq/graphql/config.rb
|
100
243
|
- lib/hq/graphql/engine.rb
|
101
244
|
- lib/hq/graphql/input_object.rb
|
102
245
|
- lib/hq/graphql/inputs.rb
|
@@ -130,8 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
273
|
- !ruby/object:Gem::Version
|
131
274
|
version: '0'
|
132
275
|
requirements: []
|
133
|
-
|
134
|
-
rubygems_version: 2.7.6
|
276
|
+
rubygems_version: 3.0.3
|
135
277
|
signing_key:
|
136
278
|
specification_version: 4
|
137
279
|
summary: OneHQ GraphQL Library
|