ibrain-core 0.2.8 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '085ed2e1adbafa549c23f84cfb156aaf4dd1b1fb93bd244f222c856f57627db1'
4
- data.tar.gz: 293a36cbcf387d597f4ea99cb19fea23e96db8d881fb286ec7cec9ac74289105
3
+ metadata.gz: c6772a14bc161414c6518bbf33f3c389e99c3d88d028aab31249ec9128b05522
4
+ data.tar.gz: 38ef4afc995c693376a7dd81f4a731c71c7d8339c8b834be7251a020ba97e88e
5
5
  SHA512:
6
- metadata.gz: 943dedeb3760b54cffbccf106bdc66674da92d5e460688c836e8d8799fc435bccc0e2724b257c2b353d897ffb0fbe7dbcf6743bfaeba841b86d3d4c6357583ae
7
- data.tar.gz: 3529b0ddb63f473d34c58b28d9cc56d9b8198bb6380c22bce8981967822167da914c03389d62f7755e0c9af71cd10a4d69803844bd0b405afb81b036840a943a
6
+ metadata.gz: 919f8893a7f5d61ab4578873d2f0e7a0178ed2382fdd00fc4768fd5b00f6e6f181912e8288b61c18bf4ed3c065c26ccd56761036de793aab250edac1d1a683ae
7
+ data.tar.gz: 5ea76bd948c0dc92ae50a62a0e1f33e93220452b1539313c985bda94b773c2832a11b4714531a391d73148b7841611f002fea0955acfd91994e533c5c42c646f
@@ -32,7 +32,8 @@ module Ibrain
32
32
  protected
33
33
 
34
34
  def normalize_entity
35
- return [params[:query], params[:operationName], prepare_variables(params[:variables])] if params[:variables].present?
35
+ return [params[:query], prepare_variables(params[:variables]), params[:operationName]] if params[:variables].present?
36
+ return [params[:query], prepare_variables(params[:variables]), 'IntrospectionQuery'] if params[:query].try(:include?, 'IntrospectionQuery')
36
37
 
37
38
  operations = prepare_variables(params[:operations])
38
39
  query = operations['query']
@@ -4,6 +4,12 @@ module Ibrain
4
4
  module Types
5
5
  class BaseInputObject < GraphQL::Schema::InputObject
6
6
  argument_class Ibrain::Types::BaseArgument
7
+
8
+ def to_params
9
+ ActionController::Parameters.new(
10
+ to_h.with_indifferent_access.transform_keys(&:underscore)
11
+ )
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -32,6 +32,7 @@ module Ibrain
32
32
  create_dir('app/repositories') unless Dir.exist?('app/repositories')
33
33
 
34
34
  template "object.erb", "#{options[:directory]}/types/objects/#{type_file_name}.rb"
35
+ template "input.erb", "#{options[:directory]}/types/input/#{input_file_name}.rb"
35
36
  template "repository.erb", "app/repositories/#{type_name}_repository.rb"
36
37
  end
37
38
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% module_namespacing_when_supported do -%>
4
+ module Types
5
+ module Input
6
+ class <%= input_ruby_name.split('::')[-1] %> < Ibrain::Types::BaseInputObject
7
+ description '<%= input_ruby_name.split('::')[-1] %>'
8
+
9
+ <% normalized_fields.each do |f| %> <%= f.to_argument %>
10
+ <% end %>end
11
+ end
12
+ end
13
+ <% end -%>
@@ -11,6 +11,7 @@ module Mutations
11
11
 
12
12
  # TODO: define arguments
13
13
  # argument :name, String, required: true
14
+ # argument :<%= model_name.underscore %>, Types::Input::<%= model_name %>Input, required: true
14
15
 
15
16
  # TODO: define resolve method
16
17
  def resolve(args)
@@ -49,6 +49,8 @@ module Ibrain
49
49
  else
50
50
  ["Types::#{type_expression.camelize}Type", null]
51
51
  end
52
+ when :input
53
+ ["Types::#{type_expression.camelize}Input", null]
52
54
  when :graphql
53
55
  [type_expression.camelize, null]
54
56
  else
@@ -74,6 +76,15 @@ module Ibrain
74
76
  @type_file_name ||= "#{type_graphql_name}Type".underscore
75
77
  end
76
78
 
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
83
+
84
+ def input_ruby_name
85
+ @input_ruby_name ||= self.class.normalize_type_expression(type_name, mode: :input)[0]
86
+ end
87
+
77
88
  # @return [Array<NormalizedField>] User-provided fields, in `(name, Ruby type name)` pairs
78
89
  def normalized_fields
79
90
  skip_fields = ["created_at:!Datetime", "updated_at:!Datetime"]
@@ -95,6 +106,10 @@ module Ibrain
95
106
  def to_ruby
96
107
  "field :#{@name}, #{@type_expr}, null: #{@null}"
97
108
  end
109
+
110
+ def to_argument
111
+ "argument :#{@name}, #{@type_expr}, required: #{@null}"
112
+ end
98
113
  end
99
114
  end
100
115
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibrain
4
- VERSION = "0.2.8"
4
+ VERSION = "0.3.1"
5
5
 
6
6
  def self.ibrain_version
7
7
  VERSION
8
8
  end
9
9
 
10
10
  def self.previous_ibrain_minor_version
11
- '0.2.7'
11
+ '0.3.0'
12
12
  end
13
13
 
14
14
  def self.ibrain_gem_version
@@ -16,7 +16,8 @@ namespace :ridgepole do
16
16
  desc 'import seed data'
17
17
  task seed: :environment do
18
18
  path = Rails.root.join("db/seeds/#{Rails.env}.rb")
19
- path = path.sub(Rails.env, 'development') unless File.exist?(path)
19
+ path = path.sub(Rails.env, ENV.fetch('RAILS_ENV', 'development')) unless File.exist?(path)
20
+
20
21
  require path
21
22
  end
22
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-07 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-session_store
@@ -241,6 +241,7 @@ files:
241
241
  - lib/generators/ibrain/graphql/resolver_generator.rb
242
242
  - lib/generators/ibrain/graphql/resolvers_generator.rb
243
243
  - lib/generators/ibrain/graphql/templates/aggregate.erb
244
+ - lib/generators/ibrain/graphql/templates/input.erb
244
245
  - lib/generators/ibrain/graphql/templates/mutation.erb
245
246
  - lib/generators/ibrain/graphql/templates/object.erb
246
247
  - lib/generators/ibrain/graphql/templates/repository.erb