hai 0.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 +7 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +16 -0
- data/hai-0.0.1.gem +0 -0
- data/lib/hai/create.rb +13 -0
- data/lib/hai/graphql/create_mutations.rb +25 -0
- data/lib/hai/graphql/list_queries.rb +36 -0
- data/lib/hai/graphql/read_queries.rb +27 -0
- data/lib/hai/graphql/types.rb +48 -0
- data/lib/hai/graphql.rb +35 -0
- data/lib/hai/mbgr.code-workspace +17 -0
- data/lib/hai/read.rb +97 -0
- data/lib/hai/types/arel/datetime_input_type.rb +17 -0
- data/lib/hai/types/arel/int_input_type.rb +17 -0
- data/lib/hai/types/arel/string_input_type.rb +17 -0
- data/lib/hai/update.rb +15 -0
- data/lib/hai/version.rb +5 -0
- data/lib/hai.rb +12 -0
- data/sig/yasashii.rbs +4 -0
- data/todo.md +44 -0
- metadata +111 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2055a088c784b6ffa1ef52d9ce4bdcfd41c024742bb070f4776c67ae125e4cdb
|
|
4
|
+
data.tar.gz: 81d7c516af333b982b74511b466232cd922e69d892d6577316f8cd5f9842be0c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 244f6fa084d19a44b84d7530708928ba219f9204e3102b59c19c8917368193f02bb7099eb1238f8b870f44839b8d48bb4f0147df134ff3050be9db45133754dd
|
|
7
|
+
data.tar.gz: f1e925b0e23c14d019e58a302dffa2bee6b56313757af5540419e370aef8edd0fc08c269d693de10173f1631421a32d787fc43c85bd3f2320fcaab2d2b69ba74
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in hai.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem "rake", "~> 13.0"
|
|
9
|
+
|
|
10
|
+
gem "minitest", "~> 5.0"
|
|
11
|
+
|
|
12
|
+
gem "factory_bot"
|
|
13
|
+
gem "graphql"
|
|
14
|
+
gem "pry"
|
|
15
|
+
gem "rubocop", "~> 1.21"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
hai (0.0.1)
|
|
5
|
+
activerecord (~> 7.0)
|
|
6
|
+
pg (~> 1.3.5)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
activemodel (7.0.3)
|
|
12
|
+
activesupport (= 7.0.3)
|
|
13
|
+
activerecord (7.0.3)
|
|
14
|
+
activemodel (= 7.0.3)
|
|
15
|
+
activesupport (= 7.0.3)
|
|
16
|
+
activesupport (7.0.3)
|
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
18
|
+
i18n (>= 1.6, < 2)
|
|
19
|
+
minitest (>= 5.1)
|
|
20
|
+
tzinfo (~> 2.0)
|
|
21
|
+
ast (2.4.2)
|
|
22
|
+
coderay (1.1.3)
|
|
23
|
+
concurrent-ruby (1.1.10)
|
|
24
|
+
factory_bot (6.2.1)
|
|
25
|
+
activesupport (>= 5.0.0)
|
|
26
|
+
graphql (2.0.9)
|
|
27
|
+
i18n (1.10.0)
|
|
28
|
+
concurrent-ruby (~> 1.0)
|
|
29
|
+
method_source (1.0.0)
|
|
30
|
+
minitest (5.16.0)
|
|
31
|
+
parallel (1.21.0)
|
|
32
|
+
parser (3.1.1.0)
|
|
33
|
+
ast (~> 2.4.1)
|
|
34
|
+
pg (1.3.5)
|
|
35
|
+
pry (0.14.1)
|
|
36
|
+
coderay (~> 1.1)
|
|
37
|
+
method_source (~> 1.0)
|
|
38
|
+
rainbow (3.1.1)
|
|
39
|
+
rake (13.0.6)
|
|
40
|
+
regexp_parser (2.5.0)
|
|
41
|
+
rexml (3.2.5)
|
|
42
|
+
rubocop (1.25.1)
|
|
43
|
+
parallel (~> 1.10)
|
|
44
|
+
parser (>= 3.1.0.0)
|
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
46
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
47
|
+
rexml
|
|
48
|
+
rubocop-ast (>= 1.15.1, < 2.0)
|
|
49
|
+
ruby-progressbar (~> 1.7)
|
|
50
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
51
|
+
rubocop-ast (1.16.0)
|
|
52
|
+
parser (>= 3.1.1.0)
|
|
53
|
+
ruby-progressbar (1.11.0)
|
|
54
|
+
tzinfo (2.0.4)
|
|
55
|
+
concurrent-ruby (~> 1.0)
|
|
56
|
+
unicode-display_width (2.1.0)
|
|
57
|
+
|
|
58
|
+
PLATFORMS
|
|
59
|
+
x86_64-darwin-21
|
|
60
|
+
|
|
61
|
+
DEPENDENCIES
|
|
62
|
+
activesupport (~> 7.0)
|
|
63
|
+
factory_bot
|
|
64
|
+
graphql
|
|
65
|
+
hai!
|
|
66
|
+
minitest (~> 5.0)
|
|
67
|
+
pry
|
|
68
|
+
rake (~> 13.0)
|
|
69
|
+
rubocop (~> 1.21)
|
|
70
|
+
|
|
71
|
+
BUNDLED WITH
|
|
72
|
+
2.3.5
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 basicbrogrammer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Hai
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hai`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'hai'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle install
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install hai
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hai.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.libs << "lib"
|
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require "rubocop/rake_task"
|
|
13
|
+
|
|
14
|
+
RuboCop::RakeTask.new
|
|
15
|
+
|
|
16
|
+
task default: %i[test rubocop]
|
data/hai-0.0.1.gem
ADDED
|
Binary file
|
data/lib/hai/create.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
class CreateMutations
|
|
4
|
+
class << self
|
|
5
|
+
def add(mutation_type, model)
|
|
6
|
+
add_field(mutation_type, model)
|
|
7
|
+
define_create_method(mutation_type, model)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_field(mutation_type, model)
|
|
11
|
+
mutation_type.field("create_#{model.name.downcase}", "Types::#{model}Type".constantize) do
|
|
12
|
+
mutation_type.description("Create a #{model}.")
|
|
13
|
+
argument(:attributes, "Types::#{model}Attributes")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def define_create_method(mutation_type, model)
|
|
18
|
+
mutation_type.define_method("create_#{model.name.downcase}") do |attributes:|
|
|
19
|
+
Hai::Create.new(model).execute(**attributes.to_h)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
class ListQueries
|
|
4
|
+
class << self
|
|
5
|
+
def add(query_type, model)
|
|
6
|
+
define_filter_type(model)
|
|
7
|
+
add_field(query_type, model)
|
|
8
|
+
define_list_method(query_type, model)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def define_filter_type(model)
|
|
12
|
+
filter_klass = Class.new(::GraphQL::Schema::InputObject)
|
|
13
|
+
model.attribute_types.each do |attr, type|
|
|
14
|
+
filter_klass.send(:argument, attr, AREL_TYPE_CAST[type.class], required: false)
|
|
15
|
+
end
|
|
16
|
+
Object.const_set "#{model}FilterInputType", filter_klass
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def add_field(query_type, model)
|
|
20
|
+
query_type.field "list_#{model.name.downcase}", ["Types::#{model}Type".constantize] do
|
|
21
|
+
query_type.description "List of #{model}."
|
|
22
|
+
argument :filter, "#{model}FilterInputType".constantize, required: false
|
|
23
|
+
argument :limit, ::GraphQL::Types::Int, required: false
|
|
24
|
+
argument :offset, ::GraphQL::Types::Int, required: false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def define_list_method(query_type, model)
|
|
29
|
+
query_type.define_method("list_#{model.name.downcase}") do |**args|
|
|
30
|
+
Hai::Read.new(model).list(args.transform_values { |v| v.is_a?(Integer) ? v : v.to_h })
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
class ReadQueries
|
|
4
|
+
class << self
|
|
5
|
+
def add(query_type, model)
|
|
6
|
+
add_field(query_type, model)
|
|
7
|
+
define_read_method(query_type, model)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_field(query_type, model)
|
|
11
|
+
query_type.field("read_#{model.name.downcase}", "Types::#{model}Type".constantize) do
|
|
12
|
+
query_type.description("List a single #{model}.")
|
|
13
|
+
model.attribute_types.each do |attr, type|
|
|
14
|
+
argument(attr, Hai::GraphQL::AREL_TYPE_CAST[type.class], required: false)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def define_read_method(query_type, model)
|
|
20
|
+
query_type.define_method("read_#{model.name.downcase}") do |**args|
|
|
21
|
+
Hai::Read.new(model).read(args.transform_values(&:to_h))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "hai/types/arel/int_input_type"
|
|
2
|
+
require "hai/types/arel/string_input_type"
|
|
3
|
+
require "hai/types/arel/datetime_input_type"
|
|
4
|
+
|
|
5
|
+
module Hai
|
|
6
|
+
module GraphQL
|
|
7
|
+
module Types
|
|
8
|
+
module Arel; end
|
|
9
|
+
ALLOWED_TYPES = ::GraphQL::Types.constants - %i[Relay JSON]
|
|
10
|
+
|
|
11
|
+
def self.included(base)
|
|
12
|
+
base.extend(ClassMethods)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module ClassMethods
|
|
16
|
+
def yasashii_type(model)
|
|
17
|
+
return if const_defined? "Types::#{model}Type"
|
|
18
|
+
|
|
19
|
+
klass = Class.new(::Types::BaseObject)
|
|
20
|
+
model.attribute_types.each do |attr, _type|
|
|
21
|
+
klass.send(:field, attr, ::GraphQL::Types::String)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
::Types.const_set "#{model}Type", klass
|
|
25
|
+
|
|
26
|
+
model.reflections.each do |name, ref|
|
|
27
|
+
yasashii_type(ref.klass)
|
|
28
|
+
if name == ref.plural_name
|
|
29
|
+
klass.send(:field, name, "[Types::#{ref.klass}Type]")
|
|
30
|
+
else
|
|
31
|
+
klass.send(:field, name, "Types::#{ref.klass}Type")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# input objects
|
|
36
|
+
klass = Class.new(::Types::BaseInputObject)
|
|
37
|
+
klass.description("Attributes for creating or updating a #{model}.")
|
|
38
|
+
model.attribute_types.each do |attr, type|
|
|
39
|
+
next if %w[id created_at updated_at].include?(attr)
|
|
40
|
+
|
|
41
|
+
klass.argument(attr, Hai::GraphQL::TYPE_CAST[type.class], required: false)
|
|
42
|
+
end
|
|
43
|
+
::Types.const_set "#{model}Attributes", klass
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/hai/graphql.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "hai/graphql/read_queries"
|
|
2
|
+
require "hai/graphql/list_queries"
|
|
3
|
+
require "hai/graphql/create_mutations"
|
|
4
|
+
require "hai/types/arel/int_input_type"
|
|
5
|
+
require "hai/types/arel/string_input_type"
|
|
6
|
+
require "hai/types/arel/datetime_input_type"
|
|
7
|
+
|
|
8
|
+
module Hai
|
|
9
|
+
module GraphQL
|
|
10
|
+
TYPE_CAST = {
|
|
11
|
+
ActiveModel::Type::Integer => ::GraphQL::Types::Int,
|
|
12
|
+
ActiveModel::Type::String => ::GraphQL::Types::String,
|
|
13
|
+
ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter => ::GraphQL::Types::ISO8601DateTime
|
|
14
|
+
}.freeze
|
|
15
|
+
AREL_TYPE_CAST = {
|
|
16
|
+
ActiveModel::Type::Integer => Hai::GraphQL::Types::Arel::IntInputType,
|
|
17
|
+
ActiveModel::Type::String => Hai::GraphQL::Types::Arel::StringInputType,
|
|
18
|
+
ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter => Hai::GraphQL::Types::Arel::DateTimeInputType
|
|
19
|
+
}.freeze
|
|
20
|
+
def self.included(base)
|
|
21
|
+
base.extend(ClassMethods)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module ClassMethods
|
|
25
|
+
def yasashii_query(model)
|
|
26
|
+
Hai::GraphQL::ReadQueries.add(self, model)
|
|
27
|
+
Hai::GraphQL::ListQueries.add(self, model)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def yasashii_mutation(model)
|
|
31
|
+
Hai::GraphQL::CreateMutations.add(self, model)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/hai/read.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
class Read
|
|
3
|
+
attr_accessor :model
|
|
4
|
+
attr_reader :table
|
|
5
|
+
|
|
6
|
+
def initialize(model)
|
|
7
|
+
@model = model
|
|
8
|
+
@table = model.arel_table
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# return [] or ActiveRecord::Relationship
|
|
12
|
+
def list(query_hash)
|
|
13
|
+
limit = query_hash.delete(:limit)
|
|
14
|
+
offset = query_hash.delete(:offset)
|
|
15
|
+
filter = query_hash.delete(:filter)
|
|
16
|
+
|
|
17
|
+
reflection_queries = build_reflection_queries(filter) if filter
|
|
18
|
+
query = filter.present? ? model.where(build_query(filter)) : model.all
|
|
19
|
+
if filter
|
|
20
|
+
reflection_queries.each do |ref, q|
|
|
21
|
+
query = query.joins(ref).merge(q)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
query = query.limit(limit) if limit
|
|
26
|
+
query = query.offset(offset) if offset
|
|
27
|
+
query
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# return nil or model
|
|
31
|
+
def read(query_hash)
|
|
32
|
+
model.find_by(build_query(query_hash))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# TODO: prolly can remove this
|
|
38
|
+
def select_manager
|
|
39
|
+
@select_manager ||= Arel::SelectManager.new(table)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def reflections
|
|
43
|
+
@reflections ||= model.reflections.symbolize_keys
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def query_reflections(query_hash)
|
|
47
|
+
reflections.each_with_object({}) do |(ref, _info), acc|
|
|
48
|
+
acc[ref] = query_hash.delete(ref)
|
|
49
|
+
end.compact
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def build_reflection_queries(query_hash)
|
|
53
|
+
reflections.each_with_object({}) do |(ref, info), acc|
|
|
54
|
+
q_hash = query_hash.delete(ref)
|
|
55
|
+
acc[ref] = info.klass.where(where_clause(info.klass.arel_table, q_hash)) if q_hash
|
|
56
|
+
end.compact
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def build_query(query_hash)
|
|
60
|
+
or_branch = query_hash.delete(:or)
|
|
61
|
+
query = where_clause(model.arel_table, query_hash)
|
|
62
|
+
|
|
63
|
+
return query unless or_branch
|
|
64
|
+
|
|
65
|
+
add_sub_query(query, or_branch)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def add_sub_query(query, or_branch)
|
|
69
|
+
query.or(build_query(or_branch))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def where_clause(table, query_hash)
|
|
73
|
+
query_hash.inject(table) do |acc, (attribute, filter)|
|
|
74
|
+
predicate, value = filter.first
|
|
75
|
+
if acc.is_a?(Arel::Table)
|
|
76
|
+
acc[attribute].send(predicate, value)
|
|
77
|
+
else
|
|
78
|
+
acc.and(table[attribute].send(predicate, value))
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def limit; end
|
|
84
|
+
|
|
85
|
+
def offset; end
|
|
86
|
+
|
|
87
|
+
def having; end
|
|
88
|
+
|
|
89
|
+
def group; end
|
|
90
|
+
|
|
91
|
+
def order; end
|
|
92
|
+
|
|
93
|
+
def select; end
|
|
94
|
+
|
|
95
|
+
def distinct; end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
module Types
|
|
4
|
+
module Arel
|
|
5
|
+
class DateTimeInputType < ::GraphQL::Schema::InputObject
|
|
6
|
+
::Arel::Predications.instance_methods.each do |predication|
|
|
7
|
+
# TODO: add these predications
|
|
8
|
+
next if %i[in when].include?(predication)
|
|
9
|
+
|
|
10
|
+
# TODO: find array predicates
|
|
11
|
+
argument predication, ::GraphQL::Types::ISO8601DateTime, required: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
module Types
|
|
4
|
+
module Arel
|
|
5
|
+
class IntInputType < ::GraphQL::Schema::InputObject
|
|
6
|
+
::Arel::Predications.instance_methods.each do |predication|
|
|
7
|
+
# TODO: add these predications
|
|
8
|
+
next if %i[in when].include?(predication)
|
|
9
|
+
|
|
10
|
+
# TODO: find array predicates
|
|
11
|
+
argument predication, ::GraphQL::Types::Int, required: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Hai
|
|
2
|
+
module GraphQL
|
|
3
|
+
module Types
|
|
4
|
+
module Arel
|
|
5
|
+
class StringInputType < ::GraphQL::Schema::InputObject
|
|
6
|
+
::Arel::Predications.instance_methods.each do |predication|
|
|
7
|
+
# TODO: add these predications
|
|
8
|
+
next if %i[in when].include?(predication)
|
|
9
|
+
|
|
10
|
+
# TODO: find array predicates
|
|
11
|
+
argument predication, ::GraphQL::Types::String, required: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/hai/update.rb
ADDED
data/lib/hai/version.rb
ADDED
data/lib/hai.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "hai/version"
|
|
4
|
+
require_relative "hai/read"
|
|
5
|
+
require_relative "hai/create"
|
|
6
|
+
require_relative "hai/graphql"
|
|
7
|
+
require_relative "hai/graphql/types"
|
|
8
|
+
|
|
9
|
+
module Hai
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
# Your code goes here...
|
|
12
|
+
end
|
data/sig/yasashii.rbs
ADDED
data/todo.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
### x - tested
|
|
2
|
+
### / - untested
|
|
3
|
+
|
|
4
|
+
------------------------------------------
|
|
5
|
+
|
|
6
|
+
- [/] read(single | multiple)
|
|
7
|
+
- [x] Single or query
|
|
8
|
+
- [x] limit
|
|
9
|
+
- [x] offset
|
|
10
|
+
- [x] multiple ors?
|
|
11
|
+
- [x] relationships
|
|
12
|
+
- [/] create
|
|
13
|
+
- [/] attributes
|
|
14
|
+
- [] required or not
|
|
15
|
+
- [] update
|
|
16
|
+
- [] id + attributes
|
|
17
|
+
- [] destroy
|
|
18
|
+
- [] id
|
|
19
|
+
- [] authorization [current_user]
|
|
20
|
+
|
|
21
|
+
------------------------------------------
|
|
22
|
+
|
|
23
|
+
- [] graphql
|
|
24
|
+
- [/] Types
|
|
25
|
+
- [/] models
|
|
26
|
+
- [/] Arel
|
|
27
|
+
- [/] inputs
|
|
28
|
+
- [/] read
|
|
29
|
+
- [/] read
|
|
30
|
+
- [/] list
|
|
31
|
+
- [/] relationships
|
|
32
|
+
- [/] create
|
|
33
|
+
- [ ] callback for current_user/context
|
|
34
|
+
- [] update
|
|
35
|
+
- [ ] callback for current_user/context
|
|
36
|
+
- [] destroy
|
|
37
|
+
------
|
|
38
|
+
- [/] gemify
|
|
39
|
+
|
|
40
|
+
## Post gem
|
|
41
|
+
- [] Multiple or queries
|
|
42
|
+
- [] geolocation
|
|
43
|
+
- [] private attrs
|
|
44
|
+
- [] allowed actions
|
metadata
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hai
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- basicbrogrammer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-07-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '7.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pg
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.3.5
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.3.5
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activesupport
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '7.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '7.0'
|
|
55
|
+
description: Will finish later.
|
|
56
|
+
email:
|
|
57
|
+
- basicbrogrammer@pm.me
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".rubocop.yml"
|
|
63
|
+
- CHANGELOG.md
|
|
64
|
+
- Gemfile
|
|
65
|
+
- Gemfile.lock
|
|
66
|
+
- LICENSE.txt
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- hai-0.0.1.gem
|
|
70
|
+
- lib/hai.rb
|
|
71
|
+
- lib/hai/create.rb
|
|
72
|
+
- lib/hai/graphql.rb
|
|
73
|
+
- lib/hai/graphql/create_mutations.rb
|
|
74
|
+
- lib/hai/graphql/list_queries.rb
|
|
75
|
+
- lib/hai/graphql/read_queries.rb
|
|
76
|
+
- lib/hai/graphql/types.rb
|
|
77
|
+
- lib/hai/mbgr.code-workspace
|
|
78
|
+
- lib/hai/read.rb
|
|
79
|
+
- lib/hai/types/arel/datetime_input_type.rb
|
|
80
|
+
- lib/hai/types/arel/int_input_type.rb
|
|
81
|
+
- lib/hai/types/arel/string_input_type.rb
|
|
82
|
+
- lib/hai/update.rb
|
|
83
|
+
- lib/hai/version.rb
|
|
84
|
+
- sig/yasashii.rbs
|
|
85
|
+
- todo.md
|
|
86
|
+
homepage: https://github.com/basicbrogrammer/hai
|
|
87
|
+
licenses:
|
|
88
|
+
- MIT
|
|
89
|
+
metadata:
|
|
90
|
+
homepage_uri: https://github.com/basicbrogrammer/hai
|
|
91
|
+
source_code_uri: https://github.com/basicbrogrammer/hai
|
|
92
|
+
post_install_message:
|
|
93
|
+
rdoc_options: []
|
|
94
|
+
require_paths:
|
|
95
|
+
- lib
|
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: 2.6.0
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - ">="
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: '0'
|
|
106
|
+
requirements: []
|
|
107
|
+
rubygems_version: 3.2.32
|
|
108
|
+
signing_key:
|
|
109
|
+
specification_version: 4
|
|
110
|
+
summary: A CRUD api built on ActiveRecord
|
|
111
|
+
test_files: []
|