graphql_scaffold_fan 0.0.2 → 0.0.3
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/.DS_Store +0 -0
- data/.gitignore +2 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +19 -0
- data/README.md +35 -0
- data/Rakefile +4 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/graphql_scaffold_fan.gemspec +31 -0
- data/lib/generators/graphqlscaffold/mutation_generator.rb +80 -0
- data/lib/generators/graphqlscaffold/type_generator.rb +77 -0
- data/lib/generators/templates/admin_filter.haml +17 -0
- data/lib/generators/templates/base_object.haml +68 -0
- data/lib/generators/templates/mutation_create.haml +12 -0
- data/lib/generators/templates/mutation_delete.haml +12 -0
- data/lib/generators/templates/mutation_test.haml +18 -0
- data/lib/generators/templates/mutation_type.haml +8 -0
- data/lib/generators/templates/mutation_update.haml +12 -0
- data/lib/generators/templates/query_test.haml +17 -0
- data/lib/generators/templates/query_type.haml +8 -0
- data/lib/graphql_scaffold_fan/version.rb +5 -0
- data/lib/graphql_scaffold_fan.rb +10 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8af2cbcd7af17b150c39bac5ca03d7ca8641442bc7b14cdad5f1f27c56372eb4
|
4
|
+
data.tar.gz: 8d5b24b65839d5a006e394e1c8923b18664a3b4f577acbbccff9dfd20afa080d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 805b643515818f9c3639f31d7db0d52974f19026bb82d54830cd69f44183ac44f95ace20d0bb7778b755faa6b128825257e180b58cc4445dfac622f9776b1258
|
7
|
+
data.tar.gz: 170c72bed0fe4499cd81614c8a879550fe6ac0baee0f3dbe8fcc815a6b6b65dab4bf2224f5485fbc1a6283ce02a0aba3ebe6c97d87cb83bb13fb9967e83a3019
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
graphql_scaffold_fan (0.0.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
rake (13.0.6)
|
10
|
+
|
11
|
+
PLATFORMS
|
12
|
+
x86_64-darwin-20
|
13
|
+
|
14
|
+
DEPENDENCIES
|
15
|
+
graphql_scaffold_fan!
|
16
|
+
rake (~> 13.0)
|
17
|
+
|
18
|
+
BUNDLED WITH
|
19
|
+
2.2.3
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# DemoGem
|
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/graphql_scaffold_fan`. 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 'graphql_scaffold_fan'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install graphql_scaffold_fan
|
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. 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]/demo_gem.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "graphql_scaffold_fan"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "graphql_scaffold_fan/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "graphql_scaffold_fan"
|
9
|
+
spec.version = GraphqlScaffoldFan::VERSION
|
10
|
+
spec.authors = ["Fan Zhang"]
|
11
|
+
spec.email = ["fan.zhang@pixelforce.com.au"]
|
12
|
+
|
13
|
+
spec.summary = "Helping creating graphql files"
|
14
|
+
spec.description = "Helping creating graphql files"
|
15
|
+
spec.homepage = ''
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
# Uncomment to register a new dependency of your gem
|
27
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
28
|
+
|
29
|
+
# For more information and examples about making a new gem, checkout our
|
30
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
31
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
module Generators
|
3
|
+
module Graphqlscaffold
|
4
|
+
class MutationGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __dir__)
|
6
|
+
|
7
|
+
def create_admin_mutation_folders
|
8
|
+
admin_mutation_dir_path = 'app/graphql/mutations/admin'
|
9
|
+
generator_dir_path = admin_mutation_dir_path + ("/#{@module_name.underscore}" if @module_name.present?).to_s
|
10
|
+
@generator_path = generator_dir_path + "/#{file_name}s"
|
11
|
+
|
12
|
+
FileUtils.mkdir_p(admin_mutation_dir_path) unless File.exist?(admin_mutation_dir_path)
|
13
|
+
if File.exist?(@generator_path)
|
14
|
+
p 'Folder already exist'
|
15
|
+
elsif Dir.mkdir(@generator_path)
|
16
|
+
p 'Folder created successfully'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_admin_mutation_create_file
|
21
|
+
if File.exist?(@generator_path)
|
22
|
+
create_file_path = @generator_path + "/create_#{file_name}.rb"
|
23
|
+
if File.exist?(create_file_path)
|
24
|
+
p 'Create File already exist'
|
25
|
+
else
|
26
|
+
template 'mutation_create.haml', create_file_path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_admin_mutation_update_file
|
32
|
+
if File.exist?(@generator_path)
|
33
|
+
update_file_path = @generator_path + "/update_#{file_name}.rb"
|
34
|
+
if File.exist?(update_file_path)
|
35
|
+
p 'Update File already exist'
|
36
|
+
else
|
37
|
+
template 'mutation_update.haml', update_file_path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_admin_mutation_delete_file
|
43
|
+
if File.exist?(@generator_path)
|
44
|
+
delete_file_path = @generator_path + "/delete_#{file_name}.rb"
|
45
|
+
if File.exist?(delete_file_path)
|
46
|
+
p 'Delete File already exist'
|
47
|
+
else
|
48
|
+
template 'mutation_delete.haml', delete_file_path
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_mutation_type_file
|
54
|
+
mutation_type_dir_path = 'app/graphql/types/admin'
|
55
|
+
generator_dir_path = mutation_type_dir_path
|
56
|
+
generator_path = generator_dir_path + '/mutation_type.rb'
|
57
|
+
|
58
|
+
FileUtils.mkdir_p(mutation_type_dir_path) unless File.exist?(mutation_type_dir_path)
|
59
|
+
FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
|
60
|
+
|
61
|
+
if File.exist?(generator_path)
|
62
|
+
file = File.open(generator_path)
|
63
|
+
file_data = file.read
|
64
|
+
new_file_data = file_data.insert(-15, " has_admin_mutation :#{class_name}\n ")
|
65
|
+
File.write(file, new_file_data)
|
66
|
+
p 'Write to query_type.rb successfully'
|
67
|
+
else
|
68
|
+
template 'mutation_type.haml', generator_path
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_test_file
|
73
|
+
test_dir_path = 'spec/requests/mutations'
|
74
|
+
test_file_path = test_dir_path + "/#{file_name}_spec.rb"
|
75
|
+
FileUtils.mkdir_p(test_dir_path) unless File.exist?(test_dir_path)
|
76
|
+
template 'mutation_test.haml', test_file_path
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
module Generators
|
3
|
+
module Graphqlscaffold
|
4
|
+
class TypeGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __dir__)
|
6
|
+
|
7
|
+
def create_type_file
|
8
|
+
if system("rails g graphql:object #{file_name}")
|
9
|
+
|
10
|
+
src_file = "app/graphql/types/#{file_name}_type.rb"
|
11
|
+
dst_dir = 'app/graphql/types/admin'
|
12
|
+
if File.exist? ("app/graphql/types/#{file_name}_type.rb")
|
13
|
+
FileUtils.mv(src_file, dst_dir)
|
14
|
+
file = File.open("#{dst_dir}/#{file_name}_type.rb")
|
15
|
+
file_data = file.read
|
16
|
+
new_file_data = file_data.insert(21, 'Admin::')
|
17
|
+
File.write(file, new_file_data)
|
18
|
+
else
|
19
|
+
p "can not find #{file_name}_type file to move"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
p "can not create #{file_name}_type file"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_filter_file
|
27
|
+
@module_name = options[:module]
|
28
|
+
|
29
|
+
filter_dir_path = 'app/graphql/types/inputs/admin'
|
30
|
+
generator_dir_path = filter_dir_path + ("/#{@module_name.underscore}" if @module_name.present?).to_s
|
31
|
+
generator_path = generator_dir_path + "/#{file_name}_filter.rb"
|
32
|
+
|
33
|
+
FileUtils.mkdir_p(filter_dir_path) unless File.exist?(filter_dir_path)
|
34
|
+
FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
|
35
|
+
|
36
|
+
template 'admin_filter.haml', generator_path
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_query_type_file
|
40
|
+
query_type_dir_path = 'app/graphql/types/admin'
|
41
|
+
generator_dir_path = query_type_dir_path
|
42
|
+
generator_path = generator_dir_path + '/query_type.rb'
|
43
|
+
|
44
|
+
FileUtils.mkdir_p(query_type_dir_path) unless File.exist?(query_type_dir_path)
|
45
|
+
FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
|
46
|
+
|
47
|
+
if File.exist?(generator_path)
|
48
|
+
file = File.open(generator_path)
|
49
|
+
file_data = file.read
|
50
|
+
new_file_data = file_data.insert(-15, " has_admin_fields :#{class_name}\n ")
|
51
|
+
File.write(file, new_file_data)
|
52
|
+
p 'Write to query_type.rb successfully'
|
53
|
+
else
|
54
|
+
template 'query_type.haml', generator_path
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_base_object_file
|
59
|
+
base_object_dir_path = 'app/graphql/types'
|
60
|
+
generator_dir_path = base_object_dir_path
|
61
|
+
generator_path = generator_dir_path.concat('/base_object.rb')
|
62
|
+
|
63
|
+
FileUtils.mkdir_p(base_object_dir_path) unless File.exist?(base_object_dir_path)
|
64
|
+
FileUtils.mkdir_p(generator_dir_path) unless File.exist?(generator_dir_path)
|
65
|
+
|
66
|
+
template 'base_object.haml', generator_path
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_test_file
|
70
|
+
test_dir_path = 'spec/requests/queries'
|
71
|
+
test_file_path = test_dir_path + "/#{file_name}_spec.rb"
|
72
|
+
FileUtils.mkdir_p(test_dir_path) unless File.exist?(test_dir_path)
|
73
|
+
template 'query_test.haml', test_file_path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Types
|
2
|
+
module Inputs
|
3
|
+
module Admin
|
4
|
+
class <%= class_name %> < Types::BaseInputObject
|
5
|
+
argument :ids, [ID], required: false
|
6
|
+
|
7
|
+
def prepare
|
8
|
+
if ids
|
9
|
+
['id in (:ids)', { ids: ids }]
|
10
|
+
else
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Types
|
2
|
+
class BaseObject < GraphQL::Schema::Object
|
3
|
+
|
4
|
+
def self.has_admin_fields(attach_sttr, **conf)
|
5
|
+
attach_sttr = attach_sttr.to_s
|
6
|
+
get_one = attach_sttr
|
7
|
+
get_many = "all_#{attach_sttr.underscore.pluralize}"
|
8
|
+
get_many_meta = "_all_#{attach_sttr.underscore.pluralize}_meta"
|
9
|
+
type_class = conf[:type_class] || 'Admin'
|
10
|
+
filter_query = conf[:filter_query] || false
|
11
|
+
class_eval %(
|
12
|
+
field :#{get_one}, Types::#{type_class}::#{attach_sttr}Type, null: true do
|
13
|
+
argument :id, ID, required: true
|
14
|
+
end
|
15
|
+
field :#{get_many}, [Types::#{type_class}::#{attach_sttr}Type], null: true do
|
16
|
+
argument :filter, Types::Inputs::Admin::#{attach_sttr}Filter, required: false
|
17
|
+
argument :page, Integer, required: false
|
18
|
+
argument :per_page, Integer, required: false
|
19
|
+
argument :sort_field, String, required: false
|
20
|
+
argument :sort_order, String, required: false
|
21
|
+
end
|
22
|
+
field :#{get_many_meta}, Types::Admin::ListMetadataType, null: true do
|
23
|
+
argument :filter, Types::Inputs::Admin::#{attach_sttr}Filter, required: false
|
24
|
+
argument :page, Integer, required: false
|
25
|
+
argument :per_page, Integer, required: false
|
26
|
+
end
|
27
|
+
|
28
|
+
def #{get_one}(id:)
|
29
|
+
#{get_one}.find_by_id(id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def #{get_many}(filter:, **args)
|
33
|
+
if args[:sort_field] && args[:sort_order] && args[:page] && args[:per_page]
|
34
|
+
if #{filter_query}
|
35
|
+
filter.order("\#{args[:sort_field]} \#{args[:sort_order]}").page(args[:page] + 1).per(args[:per_page])
|
36
|
+
else
|
37
|
+
#{get_one}.where(filter).order("\#{args[:sort_field]} \#{args[:sort_order]}").page(args[:page] + 1).per(args[:per_page])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
if #{filter_query}
|
41
|
+
filter
|
42
|
+
else
|
43
|
+
#{get_one}.where(filter)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def #{get_many_meta}(filter:, **args)
|
49
|
+
if #{filter_query}
|
50
|
+
{ count: filter.count('DISTINCT #{attach_sttr.underscore.pluralize}.id') }
|
51
|
+
else
|
52
|
+
{ count: #{get_one}.where(filter).count }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
), __FILE__, __LINE__ - 44
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.has_admin_mutation(attach_sttr, **_conf)
|
59
|
+
attach_sttr = attach_sttr.to_s
|
60
|
+
|
61
|
+
class_eval %(
|
62
|
+
field :create_#{attach_sttr.underscore}, mutation: Mutations::Admin::#{attach_sttr.pluralize}::Create#{attach_sttr} if defined?(Mutations::Admin::#{attach_sttr.pluralize}::Create#{attach_sttr})
|
63
|
+
field :update_#{attach_sttr.underscore}, mutation: Mutations::Admin::#{attach_sttr.pluralize}::Update#{attach_sttr} if defined?(Mutations::Admin::#{attach_sttr.pluralize}::Update#{attach_sttr})
|
64
|
+
field :delete_#{attach_sttr.underscore}, mutation: Mutations::Admin::#{attach_sttr.pluralize}::Delete#{attach_sttr} if defined?(Mutations::Admin::#{attach_sttr.pluralize}::Delete#{attach_sttr})
|
65
|
+
), __FILE__, __LINE__ - 4
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Mutations::<%= class_name %>, type: :request do
|
4
|
+
|
5
|
+
describe 'resolve' do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
def query(**args)
|
10
|
+
<<~GQL
|
11
|
+
mutation <%= class_name.underscore %>{
|
12
|
+
<%= class_name.underscore %>{
|
13
|
+
|
14
|
+
}
|
15
|
+
}
|
16
|
+
GQL
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Resolvers::<%= class_name %>, type: :request do
|
4
|
+
let(:query) do
|
5
|
+
<<-GRAPHQL
|
6
|
+
query {
|
7
|
+
<%= class_name.underscore %>()
|
8
|
+
}
|
9
|
+
GRAPHQL
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#resolve' do
|
13
|
+
it 'pass' do
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_scaffold_fan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fan Zhang
|
@@ -16,7 +16,29 @@ email:
|
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
|
-
files:
|
19
|
+
files:
|
20
|
+
- ".DS_Store"
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- graphql_scaffold_fan.gemspec
|
29
|
+
- lib/generators/graphqlscaffold/mutation_generator.rb
|
30
|
+
- lib/generators/graphqlscaffold/type_generator.rb
|
31
|
+
- lib/generators/templates/admin_filter.haml
|
32
|
+
- lib/generators/templates/base_object.haml
|
33
|
+
- lib/generators/templates/mutation_create.haml
|
34
|
+
- lib/generators/templates/mutation_delete.haml
|
35
|
+
- lib/generators/templates/mutation_test.haml
|
36
|
+
- lib/generators/templates/mutation_type.haml
|
37
|
+
- lib/generators/templates/mutation_update.haml
|
38
|
+
- lib/generators/templates/query_test.haml
|
39
|
+
- lib/generators/templates/query_type.haml
|
40
|
+
- lib/graphql_scaffold_fan.rb
|
41
|
+
- lib/graphql_scaffold_fan/version.rb
|
20
42
|
homepage: ''
|
21
43
|
licenses: []
|
22
44
|
metadata: {}
|