ibrain-core 0.4.6 → 0.4.7
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/ibrain/base_controller.rb +14 -12
- data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
- data/app/graphql/ibrain/base_schema.rb +52 -50
- data/app/graphql/ibrain/extentions/default_value.rb +11 -7
- data/app/graphql/ibrain/extentions/roles.rb +20 -15
- data/app/graphql/ibrain/extentions/session_required.rb +14 -10
- data/app/graphql/ibrain/lazy/base.rb +6 -2
- data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
- data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
- data/app/graphql/ibrain/policies/base_policy.rb +47 -43
- data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
- data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
- data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
- data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
- data/app/graphql/ibrain/types/attribute_type.rb +5 -2
- data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
- data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
- data/app/graphql/ibrain/types/base_api_field.rb +11 -7
- data/app/graphql/ibrain/types/base_api_object.rb +10 -6
- data/app/graphql/ibrain/types/base_argument.rb +7 -3
- data/app/graphql/ibrain/types/base_connection.rb +11 -7
- data/app/graphql/ibrain/types/base_edge.rb +7 -3
- data/app/graphql/ibrain/types/base_enum.rb +5 -1
- data/app/graphql/ibrain/types/base_field.rb +10 -6
- data/app/graphql/ibrain/types/base_input_object.rb +10 -6
- data/app/graphql/ibrain/types/base_interface.rb +9 -5
- data/app/graphql/ibrain/types/base_object.rb +16 -12
- data/app/graphql/ibrain/types/base_scalar.rb +5 -1
- data/app/graphql/ibrain/types/base_type.rb +10 -4
- data/app/graphql/ibrain/types/base_union.rb +7 -3
- data/app/graphql/ibrain/types/filter_type.rb +5 -1
- data/app/graphql/ibrain/types/node_type.rb +8 -4
- data/app/graphql/ibrain/util/field_combiner.rb +9 -5
- data/app/graphql/ibrain/util/query_combiner.rb +8 -4
- data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
- data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
- data/app/models/concerns/ibrain/user_methods.rb +13 -11
- data/app/models/ibrain/ability.rb +32 -31
- data/app/models/ibrain/aggregate.rb +7 -5
- data/app/models/ibrain/application_record.rb +4 -2
- data/app/models/ibrain/legacy_user.rb +13 -7
- data/app/models/ibrain/role.rb +8 -6
- data/app/models/ibrain/role_user.rb +10 -8
- data/app/repositories/ibrain/base_repository.rb +11 -9
- data/lib/generators/ibrain/core/model_generator.rb +21 -17
- data/lib/generators/ibrain/graphql/core.rb +59 -55
- data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
- data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
- data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
- data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
- data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
- data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
- data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
- data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
- data/lib/generators/ibrain/install/install_generator.rb +140 -137
- data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
- data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
- data/lib/ibrain/app_configuration.rb +36 -34
- data/lib/ibrain/core/class_constantizer.rb +33 -30
- data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
- data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
- data/lib/ibrain/core/controller_helpers/response.rb +49 -43
- data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
- data/lib/ibrain/core/engine.rb +9 -5
- data/lib/ibrain/core/environment.rb +9 -5
- data/lib/ibrain/core/environment_extension.rb +17 -13
- data/lib/ibrain/core/role_configuration.rb +54 -52
- data/lib/ibrain/core/validators/email.rb +17 -15
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core/versioned_value.rb +65 -61
- data/lib/ibrain/encryptor.rb +20 -18
- data/lib/ibrain/logger.rb +15 -13
- data/lib/ibrain/permission_sets/base.rb +26 -22
- data/lib/ibrain/permission_sets/super_user.rb +7 -3
- data/lib/ibrain/permitted_attributes.rb +20 -18
- data/lib/ibrain/preferences/configuration.rb +137 -135
- data/lib/ibrain/preferences/preferable.rb +162 -158
- data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
- data/lib/ibrain/user_class_handle.rb +24 -22
- data/lib/ibrain_core.rb +1 -7
- metadata +1 -1
|
@@ -7,106 +7,110 @@ require 'active_support'
|
|
|
7
7
|
require 'active_support/core_ext/string/inflections'
|
|
8
8
|
require_relative 'core'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
module Ibrain
|
|
11
|
+
module Graphql
|
|
12
|
+
class TypeGeneratorBase < Rails::Generators::Base
|
|
13
|
+
include Core
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
argument :type_name,
|
|
16
|
+
type: :string,
|
|
17
|
+
banner: "TypeName",
|
|
18
|
+
desc: "Name of this object type (expressed as Ruby or GraphQL)"
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else
|
|
40
|
-
case mode
|
|
41
|
-
when :ruby
|
|
42
|
-
case type_expression
|
|
43
|
-
when "Int"
|
|
44
|
-
["Integer", null]
|
|
45
|
-
when "Integer", "Float", "Boolean", "String", "ID"
|
|
46
|
-
[type_expression, null]
|
|
20
|
+
# Take a type expression in any combination of GraphQL or Ruby styles
|
|
21
|
+
# and return it in a specified output style
|
|
22
|
+
# TODO: nullability / list with `mode: :graphql` doesn't work
|
|
23
|
+
# @param type_expresson [String]
|
|
24
|
+
# @param mode [Symbol]
|
|
25
|
+
# @param null [Boolean]
|
|
26
|
+
# @return [(String, Boolean)] The type expression, followed by `null:` value
|
|
27
|
+
def self.normalize_type_expression(type_expression, mode:, null: false)
|
|
28
|
+
if type_expression.start_with?("!")
|
|
29
|
+
normalize_type_expression(type_expression[1..-1], mode: mode, null: false)
|
|
30
|
+
elsif type_expression.end_with?("!")
|
|
31
|
+
normalize_type_expression(type_expression[0..-2], mode: mode, null: false)
|
|
32
|
+
elsif type_expression.start_with?("[") && type_expression.end_with?("]")
|
|
33
|
+
name, is_null = normalize_type_expression(type_expression[1..-2], mode: mode, null: null)
|
|
34
|
+
["[#{name}]", is_null]
|
|
35
|
+
elsif type_expression.end_with?("Type")
|
|
36
|
+
normalize_type_expression(type_expression[0..-5], mode: mode, null: null)
|
|
37
|
+
elsif type_expression.start_with?("Types::")
|
|
38
|
+
normalize_type_expression(type_expression[7..-1], mode: mode, null: null)
|
|
39
|
+
elsif type_expression.start_with?("types.")
|
|
40
|
+
normalize_type_expression(type_expression[6..-1], mode: mode, null: null)
|
|
47
41
|
else
|
|
48
|
-
|
|
42
|
+
case mode
|
|
43
|
+
when :ruby
|
|
44
|
+
case type_expression
|
|
45
|
+
when "Int"
|
|
46
|
+
["Integer", null]
|
|
47
|
+
when "Integer", "Float", "Boolean", "String", "ID"
|
|
48
|
+
[type_expression, null]
|
|
49
|
+
else
|
|
50
|
+
["Types::#{type_expression.camelize}Type", null]
|
|
51
|
+
end
|
|
52
|
+
when :input
|
|
53
|
+
["Types::#{type_expression.camelize}Input", null]
|
|
54
|
+
when :graphql
|
|
55
|
+
[type_expression.camelize, null]
|
|
56
|
+
else
|
|
57
|
+
raise "Unexpected normalize mode: #{mode}"
|
|
58
|
+
end
|
|
49
59
|
end
|
|
50
|
-
when :input
|
|
51
|
-
["Types::#{type_expression.camelize}Input", null]
|
|
52
|
-
when :graphql
|
|
53
|
-
[type_expression.camelize, null]
|
|
54
|
-
else
|
|
55
|
-
raise "Unexpected normalize mode: #{mode}"
|
|
56
60
|
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
private
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
# @return [String] The user-provided type name, normalized to Ruby code
|
|
65
|
+
def type_ruby_name
|
|
66
|
+
@type_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :ruby)[0]
|
|
67
|
+
end
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
# @return [String] The user-provided type name, as a GraphQL name
|
|
70
|
+
def type_graphql_name
|
|
71
|
+
@type_graphql_name ||= self.class.normalize_type_expression(type_name, mode: :graphql)[0]
|
|
72
|
+
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
# @return [String] The user-provided type name, as a file name (without extension)
|
|
75
|
+
def type_file_name
|
|
76
|
+
@type_file_name ||= "#{type_graphql_name}Type".underscore
|
|
77
|
+
end
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
# @return [String] The user-provided type name, as a file name (without extension)
|
|
80
|
+
def input_file_name
|
|
81
|
+
@input_file_name ||= "#{type_graphql_name}Input".underscore
|
|
82
|
+
end
|
|
81
83
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
def input_ruby_name
|
|
85
|
+
@input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
|
|
86
|
+
end
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
# @return [Array<NormalizedField>] User-provided fields, in `(name, Ruby type name)` pairs
|
|
89
|
+
def normalized_fields
|
|
90
|
+
skip_fields = ["created_at:!Datetime", "updated_at:!Datetime"]
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
@normalized_fields ||= fields.reject { |f| skip_fields.include?(f) }.map { |f|
|
|
93
|
+
name, raw_type = f.split(":", 2)
|
|
94
|
+
type_expr, null = self.class.normalize_type_expression(raw_type, mode: :ruby)
|
|
95
|
+
NormalizedField.new(name, type_expr, null)
|
|
96
|
+
}
|
|
97
|
+
end
|
|
96
98
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
class NormalizedField
|
|
100
|
+
def initialize(name, type_expr, null)
|
|
101
|
+
@name = name
|
|
102
|
+
@type_expr = type_expr
|
|
103
|
+
@null = null
|
|
104
|
+
end
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
def to_ruby
|
|
107
|
+
"field :#{@name}, #{@type_expr}, null: #{@null}"
|
|
108
|
+
end
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
def to_argument
|
|
111
|
+
"argument :#{@name}, #{@type_expr}, required: #{@null}"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
110
114
|
end
|
|
111
115
|
end
|
|
112
116
|
end
|
|
@@ -3,175 +3,178 @@
|
|
|
3
3
|
require 'rails/generators'
|
|
4
4
|
require 'ibrain/logger'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
module Ibrain
|
|
7
|
+
# @private
|
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
|
9
|
+
CORE_MOUNT_ROUTE = "mount Ibrain::Core::Engine"
|
|
10
|
+
source_root File.expand_path('templates', __dir__)
|
|
11
|
+
|
|
12
|
+
class_option :user_class, type: :string
|
|
13
|
+
class_option :with_authentication, type: :boolean, default: true
|
|
14
|
+
class_option :with_rubocop, type: :boolean, default: true
|
|
15
|
+
class_option :with_graphql, type: :boolean, default: false
|
|
16
|
+
class_option :with_annotation, type: :boolean, default: true
|
|
17
|
+
class_option :with_sendgrid, type: :boolean, default: false
|
|
18
|
+
class_option :enforce_available_locales, type: :boolean, default: nil
|
|
19
|
+
class_option :with_ridgepole, type: :boolean, default: true
|
|
20
|
+
|
|
21
|
+
def additional_tweaks
|
|
22
|
+
return unless File.exist? 'public/robots.txt'
|
|
23
|
+
|
|
24
|
+
append_file "public/robots.txt", <<-ROBOTS.strip_heredoc
|
|
25
|
+
User-agent: *
|
|
26
|
+
Disallow: /user
|
|
27
|
+
Disallow: /account
|
|
28
|
+
Disallow: /api
|
|
29
|
+
Disallow: /password
|
|
30
|
+
ROBOTS
|
|
31
|
+
end
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
def create_overrides_directory
|
|
34
|
+
empty_directory "app/overrides"
|
|
35
|
+
end
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
def configure_application
|
|
38
|
+
if !options[:enforce_available_locales].nil?
|
|
39
|
+
application <<-RUBY
|
|
40
|
+
I18n.enforce_available_locales = #{options[:enforce_available_locales]}
|
|
41
|
+
RUBY
|
|
42
|
+
end
|
|
40
43
|
end
|
|
41
|
-
end
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
def plugin_install_preparation
|
|
46
|
+
@plugins_to_be_installed = []
|
|
47
|
+
@plugin_generators_to_run = []
|
|
48
|
+
end
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
def install_auth_plugin
|
|
51
|
+
if options[:with_authentication] && (options[:auto_accept] || !no?("
|
|
52
|
+
Ibrain has a default authentication extension that uses Devise.
|
|
53
|
+
You can find more info at https://github.com/john-techfox/ibrain-auth.git.
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
Would you like to install it? (Y/n)"))
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
@plugins_to_be_installed << 'ibrain-auth' unless system('gem list | grep ibrain-auth')
|
|
58
|
+
@plugin_generators_to_run << "ibrain:auth:install --with-ridgpole=#{options[:with_ridgepole]}"
|
|
59
|
+
end
|
|
57
60
|
end
|
|
58
|
-
end
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
def run_bundle_install_if_needed_by_plugins
|
|
63
|
+
@plugins_to_be_installed.each do |plugin_name|
|
|
64
|
+
gem plugin_name
|
|
65
|
+
end
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
if options[:with_rubocop]
|
|
68
|
+
append_gem('rubocop', '1.23.0', 'development')
|
|
69
|
+
append_gem('rubocop-performance', '1.12.0', 'development')
|
|
70
|
+
append_gem('rubocop-rails', '2.12.4', 'development')
|
|
71
|
+
append_gem('rubocop-graphql', '0.11.2', 'development')
|
|
72
|
+
end
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
if options[:with_graphql]
|
|
75
|
+
append_gem('graphql', '1.12.6')
|
|
76
|
+
append_gem('graphql-batch', '0.4.3')
|
|
77
|
+
append_gem('graphql-guard', '2.0.0')
|
|
78
|
+
append_gem('graphql-rails-generators', '1.1.2', 'development')
|
|
79
|
+
append_gem('graphiql-rails', '1.8.0', 'development')
|
|
80
|
+
append_gem('apollo_upload_server', '2.1')
|
|
81
|
+
end
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
|
|
84
|
+
append_gem('sendgrid-ruby', '6.6.0') if options[:with_sendgrid]
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
if options[:with_ridgepole]
|
|
87
|
+
append_gem('ridgepole', '1.0.0', 'development')
|
|
88
|
+
else
|
|
89
|
+
remove_gem('ridgepole')
|
|
90
|
+
end
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
|
|
93
|
+
run "spring stop" if defined?(Spring)
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
@plugin_generators_to_run.each do |plugin_generator_name|
|
|
96
|
+
generate plugin_generator_name.to_s
|
|
97
|
+
end
|
|
95
98
|
end
|
|
96
|
-
end
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
def install_routes
|
|
101
|
+
routes_file_path = File.join('config', 'routes.rb')
|
|
102
|
+
unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
|
|
103
|
+
insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
|
|
104
|
+
<<-RUBY
|
|
105
|
+
# This line mounts Ibrain's routes at the root of your application.
|
|
106
|
+
# This means, any requests to URLs such as /graphql, will go to Ibrain::GraphqlController,
|
|
107
|
+
# any requests to URLS such as /auth, will go to Ibrain::AuthController,
|
|
108
|
+
# If you would like to change where this engine is mounted, simply change the :at option to something different.
|
|
109
|
+
#
|
|
110
|
+
# We ask that you don't use the :as option here, as Ibrain relies on it being the default of "ibrain"
|
|
111
|
+
#{CORE_MOUNT_ROUTE}, at: '/'
|
|
112
|
+
|
|
113
|
+
# Please contact to Tai Nguyen Van <tainv@its-global.vn> if you have any question?
|
|
114
|
+
RUBY
|
|
115
|
+
end
|
|
113
116
|
end
|
|
114
|
-
end
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
unless options[:quiet]
|
|
119
|
+
Ibrain::Logger.info "*" * 50
|
|
120
|
+
Ibrain::Logger.info "We added the following line to your application's config/routes.rb file:"
|
|
121
|
+
Ibrain::Logger.info " "
|
|
122
|
+
Ibrain::Logger.info " #{CORE_MOUNT_ROUTE}, at: '/'"
|
|
123
|
+
end
|
|
121
124
|
end
|
|
122
|
-
end
|
|
123
125
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
def add_files
|
|
127
|
+
template 'config/initializers/ibrain.rb.tt', 'config/initializers/ibrain.rb', { skip: true }
|
|
128
|
+
template 'config/initializers/cors.tt', 'config/initializers/cors.rb'
|
|
129
|
+
template 'config/puma.tt', 'config/puma.rb'
|
|
130
|
+
yml_template 'config/database.tt', 'config/database.yml'
|
|
131
|
+
template 'rubocop.yml.tt', '.rubocop.yml' if options[:with_rubocop]
|
|
132
|
+
|
|
133
|
+
if options[:with_graphql]
|
|
134
|
+
template 'graphql/app_schema.rb.tt', 'app/graphql/app_schema.rb', { skip: true }
|
|
135
|
+
template 'graphql/types/mutation_type.rb.tt', 'app/graphql/types/mutation_type.rb', { skip: true }
|
|
136
|
+
template 'graphql/types/query_type.rb.tt', 'app/graphql/types/query_type.rb', { skip: true }
|
|
137
|
+
end
|
|
135
138
|
end
|
|
136
|
-
end
|
|
137
139
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
def complete
|
|
141
|
+
unless options[:quiet]
|
|
142
|
+
Ibrain::Logger.info "*" * 50
|
|
143
|
+
Ibrain::Logger.info "Ibrain has been installed successfully. You're all ready to go!"
|
|
144
|
+
Ibrain::Logger.info " "
|
|
145
|
+
Ibrain::Logger.info "Enjoy!"
|
|
146
|
+
end
|
|
144
147
|
end
|
|
145
|
-
end
|
|
146
148
|
|
|
147
|
-
|
|
149
|
+
private
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
def bundle_cleanly(&block)
|
|
152
|
+
Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block)
|
|
153
|
+
end
|
|
152
154
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
def append_gem(name, version, group_name = nil)
|
|
156
|
+
shell_command = ["\ngem '#{name}', '~> #{version}'"]
|
|
157
|
+
shell_command.push("group: :#{group_name}") if group_name.present?
|
|
158
|
+
string_command = shell_command.join(', ')
|
|
159
|
+
gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
system( `echo "#{string_command}" >> Gemfile` ) unless gems.include?("#{name}-")
|
|
162
|
+
end
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
+
def remove_gem(name)
|
|
165
|
+
gems = Gem.loaded_specs.values.map(&:full_name).join(' ')
|
|
164
166
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
system( "bundle remove #{name}" ) if gems.include?("#{name}-")
|
|
168
|
+
end
|
|
167
169
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
def yml_template(source, *args)
|
|
171
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
|
172
|
+
destination = args.first || source.sub(/#{TEMPLATE_EXTNAME}$/o, "")
|
|
173
|
+
source = File.expand_path(find_in_source_paths(source.to_s))
|
|
172
174
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
create_file destination, nil, config do
|
|
176
|
+
File.read(source)
|
|
177
|
+
end
|
|
175
178
|
end
|
|
176
179
|
end
|
|
177
180
|
end
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module Types
|
|
4
|
+
class MutationType < Ibrain::Types::BaseApiObject
|
|
5
|
+
description 'Define all mutation for client'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
# TODO: remove me
|
|
8
|
+
# Default session_required is true, set false if yout want to skip authenticated
|
|
9
|
+
field :test_authenticated_field, , String, null: false,
|
|
10
|
+
description: 'An example field added by the generator'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
field :test_field, String, null: false,
|
|
13
|
+
description: 'An example field added by the generator', session_required: false
|
|
14
|
+
def test_field
|
|
15
|
+
'Hello World'
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
def test_authenticated_field
|
|
19
|
+
'Im logged in!'
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module Types
|
|
4
|
+
class QueryType < Ibrain::Types::BaseApiObject
|
|
5
|
+
description 'Define all resolver for client'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
# Add `node(id: ID!) and `nodes(ids: [ID!]!)`
|
|
8
|
+
include GraphQL::Types::Relay::HasNodeField
|
|
9
|
+
include GraphQL::Types::Relay::HasNodesField
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
# Add root-level fields here.
|
|
12
|
+
# Default session_required is true, set false if yout want to skip authenticated
|
|
13
|
+
# They will be entry points for queries on your schema.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
# Example with user resolvers
|
|
16
|
+
# field :authenticated_users, resolver: Resolvers::UsersResolver
|
|
17
|
+
# field :users, resolver: Resolvers::UsersResolver, session_required: false
|
|
18
|
+
end
|
|
17
19
|
end
|