graphql_rails 1.2.3 → 2.1.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +18 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +27 -25
- data/docs/README.md +1 -1
- data/docs/components/model.md +107 -13
- data/docs/other_tools/schema_dump.md +8 -8
- data/lib/graphql_rails/attributes/attributable.rb +6 -14
- data/lib/graphql_rails/attributes/attribute.rb +10 -34
- data/lib/graphql_rails/attributes/attribute_configurable.rb +45 -0
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +7 -7
- data/lib/graphql_rails/attributes/input_attribute.rb +20 -14
- data/lib/graphql_rails/attributes/input_type_parser.rb +5 -7
- data/lib/graphql_rails/attributes/type_parseable.rb +55 -19
- data/lib/graphql_rails/attributes/type_parser.rb +4 -9
- data/lib/graphql_rails/concerns/chainable_options.rb +49 -0
- data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb +3 -0
- data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
- data/lib/graphql_rails/input_configurable.rb +10 -8
- data/lib/graphql_rails/model/build_graphql_input_type.rb +4 -2
- data/lib/graphql_rails/model/configurable.rb +30 -8
- data/lib/graphql_rails/model/configuration.rb +26 -12
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +23 -21
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +2 -1
- data/lib/graphql_rails/model/input.rb +10 -26
- data/lib/graphql_rails/model.rb +1 -1
- data/lib/graphql_rails/query_runner.rb +9 -3
- data/lib/graphql_rails/router/route.rb +2 -2
- data/lib/graphql_rails/tasks/dump_graphql_schema.rb +18 -27
- data/lib/graphql_rails/tasks/dump_graphql_schemas.rb +57 -0
- data/lib/graphql_rails/tasks/schema.rake +8 -5
- data/lib/graphql_rails/types/argument_type.rb +12 -0
- data/lib/graphql_rails/types/field_type.rb +14 -0
- data/lib/graphql_rails/types/hidable_by_group.rb +32 -0
- data/lib/graphql_rails/types/object_type.rb +12 -0
- data/lib/graphql_rails/version.rb +1 -1
- metadata +15 -8
- data/.travis.yml +0 -5
@@ -8,12 +8,13 @@ module GraphqlRails
|
|
8
8
|
|
9
9
|
include ::GraphqlRails::Service
|
10
10
|
|
11
|
-
def initialize(
|
11
|
+
def initialize(params:, context: {}, schema: nil, router: nil, group: nil, **schema_options) # rubocop:disable Metrics/ParameterLists
|
12
12
|
@group = group
|
13
13
|
@graphql_schema = schema
|
14
14
|
@params = params
|
15
|
-
@schema_options = schema_options
|
16
15
|
@router = router
|
16
|
+
@initial_context = context
|
17
|
+
@schema_options = schema_options
|
17
18
|
end
|
18
19
|
|
19
20
|
def call
|
@@ -21,13 +22,18 @@ module GraphqlRails
|
|
21
22
|
params[:query],
|
22
23
|
variables: variables,
|
23
24
|
operation_name: params[:operationName],
|
25
|
+
context: context,
|
24
26
|
**schema_options
|
25
27
|
)
|
26
28
|
end
|
27
29
|
|
28
30
|
private
|
29
31
|
|
30
|
-
attr_reader :schema_options, :params, :group
|
32
|
+
attr_reader :schema_options, :params, :group, :initial_context
|
33
|
+
|
34
|
+
def context
|
35
|
+
initial_context.merge(graphql_group: group)
|
36
|
+
end
|
31
37
|
|
32
38
|
def variables
|
33
39
|
ensure_hash(params[:variables])
|
@@ -6,7 +6,7 @@ module GraphqlRails
|
|
6
6
|
class Router
|
7
7
|
# Generic class for any type graphql action. Should not be used directly
|
8
8
|
class Route
|
9
|
-
attr_reader :name, :module_name, :on, :relative_path
|
9
|
+
attr_reader :name, :module_name, :on, :relative_path, :groups
|
10
10
|
|
11
11
|
def initialize(name, to: '', on:, groups: nil, **options)
|
12
12
|
@name = name.to_s.camelize(:lower)
|
@@ -43,7 +43,7 @@ module GraphqlRails
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
attr_reader :function
|
46
|
+
attr_reader :function
|
47
47
|
|
48
48
|
def resolver
|
49
49
|
@resolver ||= Controller::BuildControllerActionResolver.call(route: self)
|
@@ -7,51 +7,42 @@ module GraphqlRails
|
|
7
7
|
|
8
8
|
class MissingGraphqlRouterError < GraphqlRails::Error; end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def self.call(*args)
|
13
|
-
new(*args).call
|
10
|
+
def self.call(**args)
|
11
|
+
new(**args).call
|
14
12
|
end
|
15
13
|
|
16
|
-
def initialize(
|
17
|
-
@
|
14
|
+
def initialize(group:, router:, dump_dir: nil)
|
15
|
+
@group = group
|
16
|
+
@router = router
|
17
|
+
@dump_dir = dump_dir
|
18
18
|
end
|
19
19
|
|
20
20
|
def call
|
21
|
-
|
22
|
-
File.write(schema_path, schema.to_definition)
|
21
|
+
File.write(schema_path, schema_dump)
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
|
28
|
-
return if router
|
29
|
-
|
30
|
-
error_message = \
|
31
|
-
'GraphqlRouter is missing. ' \
|
32
|
-
'Run `rails g graphql_rails:install` to build it'
|
33
|
-
raise MissingGraphqlRouterError, error_message
|
34
|
-
end
|
26
|
+
attr_reader :router, :group
|
35
27
|
|
36
|
-
def
|
37
|
-
|
28
|
+
def schema_dump
|
29
|
+
context = { graphql_group: group }
|
30
|
+
schema.to_definition(context: context)
|
38
31
|
end
|
39
32
|
|
40
33
|
def schema
|
41
|
-
@schema ||=
|
34
|
+
@schema ||= router.graphql_schema(group.presence)
|
42
35
|
end
|
43
36
|
|
44
37
|
def schema_path
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def default_schema_path
|
49
|
-
schema_folder_path = Rails.root.join('spec', 'fixtures')
|
38
|
+
FileUtils.mkdir_p(dump_dir)
|
39
|
+
file_name = group.present? ? "graphql_#{group}_schema.graphql" : 'graphql_schema.graphql'
|
50
40
|
|
51
|
-
|
52
|
-
|
41
|
+
"#{dump_dir}/#{file_name}"
|
42
|
+
end
|
53
43
|
|
54
|
-
|
44
|
+
def dump_dir
|
45
|
+
@dump_dir ||= Rails.root.join('spec/fixtures').to_s
|
55
46
|
end
|
56
47
|
end
|
57
48
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/tasks/dump_graphql_schema'
|
4
|
+
|
5
|
+
module GraphqlRails
|
6
|
+
# Generates graphql schema dump files
|
7
|
+
class DumpGraphqlSchemas
|
8
|
+
require 'graphql_rails/errors/error'
|
9
|
+
|
10
|
+
class MissingGraphqlRouterError < GraphqlRails::Error; end
|
11
|
+
|
12
|
+
def self.call(**args)
|
13
|
+
new(**args).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(dump_dir:, groups: nil)
|
17
|
+
@groups = groups.presence
|
18
|
+
@dump_dir = dump_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
validate
|
23
|
+
return dump_default_schema if groups.empty?
|
24
|
+
|
25
|
+
groups.each { |group| dump_graphql_schema(group) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :dump_dir
|
31
|
+
|
32
|
+
def dump_default_schema
|
33
|
+
dump_graphql_schema('')
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump_graphql_schema(group)
|
37
|
+
DumpGraphqlSchema.call(group: group, router: router, dump_dir: dump_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate
|
41
|
+
return if router
|
42
|
+
|
43
|
+
error_message = \
|
44
|
+
'GraphqlRouter is missing. ' \
|
45
|
+
'Run `rails g graphql_rails:install` to build it'
|
46
|
+
raise MissingGraphqlRouterError, error_message
|
47
|
+
end
|
48
|
+
|
49
|
+
def router
|
50
|
+
@router ||= '::GraphqlRouter'.safe_constantize
|
51
|
+
end
|
52
|
+
|
53
|
+
def groups
|
54
|
+
@groups ||= router.routes.flat_map(&:groups).uniq
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'graphql_rails/tasks/
|
3
|
+
require 'graphql_rails/tasks/dump_graphql_schemas'
|
4
4
|
|
5
5
|
namespace :graphql_rails do
|
6
6
|
namespace :schema do
|
7
7
|
desc 'Dump GraphQL schema'
|
8
|
-
task(:
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
task(dump: :environment) do |_, args|
|
9
|
+
groups_from_args = args.extras
|
10
|
+
groups_from_env = ENV['SCHEMA_GROUP_NAME'].to_s.split(',').map(&:strip)
|
11
|
+
groups = groups_from_args + groups_from_env
|
12
|
+
dump_dir = ENV.fetch('GRAPHQL_SCHEMA_DUMP_DIR') { Rails.root.join('spec/fixtures').to_s }
|
13
|
+
|
14
|
+
GraphqlRails::DumpGraphqlSchemas.call(groups: groups, dump_dir: dump_dir)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/types/hidable_by_group'
|
4
|
+
|
5
|
+
module GraphqlRails
|
6
|
+
module Types
|
7
|
+
# Base argument type for all GraphqlRails inputs
|
8
|
+
class ArgumentType < GraphQL::Schema::Argument
|
9
|
+
include GraphqlRails::Types::HidableByGroup
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/types/argument_type'
|
4
|
+
require 'graphql_rails/types/hidable_by_group'
|
5
|
+
|
6
|
+
module GraphqlRails
|
7
|
+
module Types
|
8
|
+
# Base field for all GraphqlRails model fields
|
9
|
+
class FieldType < GraphQL::Schema::Field
|
10
|
+
include GraphqlRails::Types::HidableByGroup
|
11
|
+
argument_class(GraphqlRails::Types::ArgumentType)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/types/argument_type'
|
4
|
+
|
5
|
+
module GraphqlRails
|
6
|
+
module Types
|
7
|
+
# Add visibility option based on groups
|
8
|
+
module HidableByGroup
|
9
|
+
def initialize(*args, groups: [], **kwargs, &block)
|
10
|
+
super(*args, **kwargs, &block)
|
11
|
+
|
12
|
+
@groups = groups.map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def visible?(context)
|
16
|
+
super && visible_in_context_group?(context)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def groups
|
22
|
+
@groups
|
23
|
+
end
|
24
|
+
|
25
|
+
def visible_in_context_group?(context)
|
26
|
+
group = context[:graphql_group] || context['graphql_group']
|
27
|
+
|
28
|
+
group.nil? || groups.empty? || groups.include?(group.to_s)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/types/field_type'
|
4
|
+
|
5
|
+
module GraphqlRails
|
6
|
+
module Types
|
7
|
+
# Base graphql type class for all GraphqlRails models
|
8
|
+
class ObjectType < GraphQL::Schema::Object
|
9
|
+
field_class(GraphqlRails::Types::FieldType)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Povilas Jurčys
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -128,19 +128,19 @@ dependencies:
|
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '6'
|
131
|
-
description:
|
131
|
+
description:
|
132
132
|
email:
|
133
133
|
- po.jurcys@gmail.com
|
134
134
|
executables: []
|
135
135
|
extensions: []
|
136
136
|
extra_rdoc_files: []
|
137
137
|
files:
|
138
|
+
- ".github/workflows/ruby.yml"
|
138
139
|
- ".gitignore"
|
139
140
|
- ".hound.yml"
|
140
141
|
- ".rspec"
|
141
142
|
- ".rubocop.yml"
|
142
143
|
- ".ruby-version"
|
143
|
-
- ".travis.yml"
|
144
144
|
- CHANGELOG.md
|
145
145
|
- CODE_OF_CONDUCT.md
|
146
146
|
- Gemfile
|
@@ -174,12 +174,14 @@ files:
|
|
174
174
|
- lib/graphql_rails/attributes.rb
|
175
175
|
- lib/graphql_rails/attributes/attributable.rb
|
176
176
|
- lib/graphql_rails/attributes/attribute.rb
|
177
|
+
- lib/graphql_rails/attributes/attribute_configurable.rb
|
177
178
|
- lib/graphql_rails/attributes/attribute_name_parser.rb
|
178
179
|
- lib/graphql_rails/attributes/input_attribute.rb
|
179
180
|
- lib/graphql_rails/attributes/input_type_parser.rb
|
180
181
|
- lib/graphql_rails/attributes/type_name_info.rb
|
181
182
|
- lib/graphql_rails/attributes/type_parseable.rb
|
182
183
|
- lib/graphql_rails/attributes/type_parser.rb
|
184
|
+
- lib/graphql_rails/concerns/chainable_options.rb
|
183
185
|
- lib/graphql_rails/concerns/service.rb
|
184
186
|
- lib/graphql_rails/controller.rb
|
185
187
|
- lib/graphql_rails/controller/action.rb
|
@@ -226,13 +228,18 @@ files:
|
|
226
228
|
- lib/graphql_rails/router/schema_builder.rb
|
227
229
|
- lib/graphql_rails/rspec_controller_helpers.rb
|
228
230
|
- lib/graphql_rails/tasks/dump_graphql_schema.rb
|
231
|
+
- lib/graphql_rails/tasks/dump_graphql_schemas.rb
|
229
232
|
- lib/graphql_rails/tasks/schema.rake
|
233
|
+
- lib/graphql_rails/types/argument_type.rb
|
234
|
+
- lib/graphql_rails/types/field_type.rb
|
235
|
+
- lib/graphql_rails/types/hidable_by_group.rb
|
236
|
+
- lib/graphql_rails/types/object_type.rb
|
230
237
|
- lib/graphql_rails/version.rb
|
231
238
|
homepage: https://github.com/samesystem/graphql_rails
|
232
239
|
licenses:
|
233
240
|
- MIT
|
234
241
|
metadata: {}
|
235
|
-
post_install_message:
|
242
|
+
post_install_message:
|
236
243
|
rdoc_options: []
|
237
244
|
require_paths:
|
238
245
|
- lib
|
@@ -247,8 +254,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
254
|
- !ruby/object:Gem::Version
|
248
255
|
version: '0'
|
249
256
|
requirements: []
|
250
|
-
rubygems_version: 3.
|
251
|
-
signing_key:
|
257
|
+
rubygems_version: 3.2.15
|
258
|
+
signing_key:
|
252
259
|
specification_version: 4
|
253
260
|
summary: Rails style structure for GraphQL API.
|
254
261
|
test_files: []
|