hq-graphql 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/hq-graphql.rb +0 -2
- data/lib/hq/graphql.rb +29 -20
- data/lib/hq/graphql/active_record_extensions.rb +23 -27
- data/lib/hq/graphql/association_loader.rb +49 -0
- data/lib/hq/graphql/comparator.rb +1 -6
- data/lib/hq/graphql/config.rb +17 -11
- data/lib/hq/graphql/engine.rb +0 -1
- data/lib/hq/graphql/enum.rb +78 -0
- data/lib/hq/graphql/enum/sort_by.rb +8 -0
- data/lib/hq/graphql/enum/sort_order.rb +8 -0
- data/lib/hq/graphql/field.rb +26 -6
- data/lib/hq/graphql/input_object.rb +8 -7
- data/lib/hq/graphql/inputs.rb +4 -3
- data/lib/hq/graphql/mutation.rb +0 -1
- data/lib/hq/graphql/object.rb +15 -4
- data/lib/hq/graphql/paginated_association_loader.rb +138 -0
- data/lib/hq/graphql/resource.rb +47 -156
- data/lib/hq/graphql/resource/auto_mutation.rb +159 -0
- data/lib/hq/graphql/root_mutation.rb +1 -2
- data/lib/hq/graphql/root_query.rb +0 -1
- data/lib/hq/graphql/scalars.rb +0 -1
- data/lib/hq/graphql/schema.rb +22 -0
- data/lib/hq/graphql/types.rb +19 -8
- data/lib/hq/graphql/types/object.rb +7 -11
- data/lib/hq/graphql/types/uuid.rb +7 -14
- data/lib/hq/graphql/version.rb +1 -2
- metadata +9 -39
- data/lib/hq/graphql/loaders.rb +0 -4
- data/lib/hq/graphql/loaders/association.rb +0 -52
- data/lib/hq/graphql/resource/mutation.rb +0 -39
data/lib/hq/graphql/loaders.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# typed: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module HQ
|
5
|
-
module GraphQL
|
6
|
-
module Loaders
|
7
|
-
class Association < ::GraphQL::Batch::Loader
|
8
|
-
def initialize(model, association_name)
|
9
|
-
@model = model
|
10
|
-
@association_name = association_name
|
11
|
-
validate
|
12
|
-
end
|
13
|
-
|
14
|
-
def load(record)
|
15
|
-
raise TypeError, "#{@model} loader can't load association for #{record.class}" unless record.is_a?(@model)
|
16
|
-
return Promise.resolve(read_association(record)) if association_loaded?(record)
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
# We want to load the associations on all records, even if they have the same id
|
21
|
-
def cache_key(record)
|
22
|
-
record.object_id
|
23
|
-
end
|
24
|
-
|
25
|
-
def perform(records)
|
26
|
-
preload_association(records)
|
27
|
-
records.each { |record| fulfill(record, read_association(record)) }
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def validate
|
33
|
-
unless @model.reflect_on_association(@association_name)
|
34
|
-
raise ArgumentError, "No association #{@association_name} on #{@model}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def preload_association(records)
|
39
|
-
::ActiveRecord::Associations::Preloader.new.preload(records, @association_name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def read_association(record)
|
43
|
-
record.public_send(@association_name)
|
44
|
-
end
|
45
|
-
|
46
|
-
def association_loaded?(record)
|
47
|
-
record.association(@association_name).loaded?
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# typed: false
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module HQ
|
5
|
-
module GraphQL
|
6
|
-
module Resource
|
7
|
-
module Mutation
|
8
|
-
def self.build(model_name, action:, graphql_name:, require_primary_key: false, nil_klass: false, &block)
|
9
|
-
Class.new(::HQ::GraphQL::Mutation) do
|
10
|
-
graphql_name graphql_name
|
11
|
-
|
12
|
-
define_method(:ready?) do |*args|
|
13
|
-
super(*args) && ::HQ::GraphQL.authorized?(action, model_name, context)
|
14
|
-
end
|
15
|
-
|
16
|
-
lazy_load do
|
17
|
-
field :errors, ::HQ::GraphQL::Types::Object, null: false
|
18
|
-
field :resource, ::HQ::GraphQL::Types[model_name, nil_klass], null: true
|
19
|
-
end
|
20
|
-
|
21
|
-
instance_eval(&block)
|
22
|
-
|
23
|
-
if require_primary_key
|
24
|
-
lazy_load do
|
25
|
-
klass = model_name.constantize
|
26
|
-
primary_key = klass.primary_key
|
27
|
-
argument primary_key, ::GraphQL::Types::ID, required: true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def errors_from_resource(resource)
|
32
|
-
resource.errors.to_h.deep_transform_keys { |k| k.to_s.camelize(:lower) }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|