hq-graphql 2.0.1 → 2.0.2
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/lib/hq/graphql/config.rb +1 -1
- data/lib/hq/graphql/resource/mutation.rb +3 -5
- data/lib/hq/graphql/resource.rb +5 -9
- data/lib/hq/graphql/types.rb +4 -4
- data/lib/hq/graphql/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b7415b2d65e1530b8e56c4981759200f341bf15aa5fb6e6ceebc08c806821f
|
4
|
+
data.tar.gz: 4708e50afcb152a7a7cb2b32f6c26d74a69412bea0d1575c96cdde396d596ac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01beff2971f13a64651d3170bde7a0b11396a9fb797bc4dfb8d95560af14bfec55144dd03de0a712344e4cd1aed0c3206964ac09e12a08beab452293d1710e6c
|
7
|
+
data.tar.gz: 4bea766a1789a5228777ea218aabeed5e50c06585d0259989bb97677ff3d0c0cf28b65497d21c35caf3a8e07d742c0c50888917762d563d53999dc1eb2a8d897
|
data/lib/hq/graphql/config.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
module HQ
|
6
6
|
module GraphQL
|
7
7
|
class Config < T::Struct
|
8
|
-
DefaultScopeProc = T.type_alias
|
8
|
+
DefaultScopeProc = T.type_alias { T.proc.params(arg0: T.untyped, arg1: ::GraphQL::Query::Context).returns(T.untyped) }
|
9
9
|
prop :default_scope, DefaultScopeProc, default: ->(scope, _context) { scope }
|
10
10
|
end
|
11
11
|
end
|
@@ -5,13 +5,13 @@ module HQ
|
|
5
5
|
module GraphQL
|
6
6
|
module Resource
|
7
7
|
module Mutation
|
8
|
-
def self.build(model_name, graphql_name:, require_primary_key: false,
|
8
|
+
def self.build(model_name, graphql_name:, require_primary_key: false, nil_klass: false, &block)
|
9
9
|
Class.new(::HQ::GraphQL::Mutation) do
|
10
10
|
graphql_name graphql_name
|
11
11
|
|
12
12
|
lazy_load do
|
13
13
|
field :errors, ::HQ::GraphQL::Types::Object, null: false
|
14
|
-
field :resource, ::HQ::GraphQL::Types[model_name,
|
14
|
+
field :resource, ::HQ::GraphQL::Types[model_name, nil_klass], null: true
|
15
15
|
end
|
16
16
|
|
17
17
|
instance_eval(&block)
|
@@ -20,9 +20,7 @@ module HQ
|
|
20
20
|
lazy_load do
|
21
21
|
klass = model_name.constantize
|
22
22
|
primary_key = klass.primary_key
|
23
|
-
|
24
|
-
|
25
|
-
argument primary_key, ::HQ::GraphQL::Types.type_from_column(pk_column), required: true
|
23
|
+
argument primary_key, ::GraphQL::Types::ID, required: true
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
data/lib/hq/graphql/resource.rb
CHANGED
@@ -12,6 +12,7 @@ module HQ
|
|
12
12
|
super
|
13
13
|
::HQ::GraphQL.types << base
|
14
14
|
base.include Scalars
|
15
|
+
base.include ::GraphQL::Types
|
15
16
|
end
|
16
17
|
|
17
18
|
module ClassMethods
|
@@ -53,8 +54,8 @@ module HQ
|
|
53
54
|
@input_klass ||= build_input_object
|
54
55
|
end
|
55
56
|
|
56
|
-
def
|
57
|
-
@
|
57
|
+
def nil_query_klass
|
58
|
+
@nil_query_klass ||= build_graphql_object(name: "#{graphql_name}Copy", auto_nil: false)
|
58
59
|
end
|
59
60
|
|
60
61
|
def query_klass
|
@@ -71,10 +72,6 @@ module HQ
|
|
71
72
|
@input_klass = build_input_object(**options, &block)
|
72
73
|
end
|
73
74
|
|
74
|
-
def input_result(**options, &block)
|
75
|
-
@input_result_klass = build_graphql_object(name: "#{graphql_name}Copy", **options, auto_nil: false, &block)
|
76
|
-
end
|
77
|
-
|
78
75
|
def mutations(create: true, copy: true, update: true, destroy: true)
|
79
76
|
scoped_graphql_name = graphql_name
|
80
77
|
scoped_model_name = model_name
|
@@ -111,7 +108,7 @@ module HQ
|
|
111
108
|
model_name,
|
112
109
|
graphql_name: "#{scoped_graphql_name}Copy",
|
113
110
|
require_primary_key: true,
|
114
|
-
|
111
|
+
nil_klass: true
|
115
112
|
) do
|
116
113
|
define_method(:resolve) do |**args|
|
117
114
|
resource = scoped_self.find_record(args, context)
|
@@ -239,9 +236,8 @@ module HQ
|
|
239
236
|
def_root field_name, is_array: false, null: true do
|
240
237
|
klass = scoped_self.model_klass
|
241
238
|
primary_key = klass.primary_key
|
242
|
-
pk_column = klass.columns.detect { |c| c.name == primary_key.to_s }
|
243
239
|
|
244
|
-
argument primary_key, ::
|
240
|
+
argument primary_key, ::GraphQL::Types::ID, required: true
|
245
241
|
|
246
242
|
define_method(:resolve) do |**attrs|
|
247
243
|
scoped_self.find_record(attrs, context)
|
data/lib/hq/graphql/types.rb
CHANGED
@@ -10,8 +10,8 @@ module HQ
|
|
10
10
|
|
11
11
|
def self.[](key, *args)
|
12
12
|
@types ||= Hash.new do |hash, options|
|
13
|
-
klass,
|
14
|
-
hash[klass] =
|
13
|
+
klass, nil_klass = Array(options)
|
14
|
+
hash[klass] = nil_klass ? nil_query_klass(klass) : klass_for(klass)
|
15
15
|
end
|
16
16
|
@types[[key, *args]]
|
17
17
|
end
|
@@ -44,8 +44,8 @@ module HQ
|
|
44
44
|
class << self
|
45
45
|
private
|
46
46
|
|
47
|
-
def
|
48
|
-
find_klass(klass_or_string, :
|
47
|
+
def nil_query_klass(klass_or_string)
|
48
|
+
find_klass(klass_or_string, :nil_query_klass)
|
49
49
|
end
|
50
50
|
|
51
51
|
def klass_for(klass_or_string)
|
data/lib/hq/graphql/version.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: 2.0.
|
4
|
+
version: 2.0.2
|
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-10-
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -86,6 +86,20 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sprockets
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "<"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 4.0.0
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 4.0.0
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: byebug
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|