graphql_helper_generator 0.0.31 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79eb26879ede6b0db47ae7d5f90e615db3899251fb9967e70f7b3f219c997014
4
- data.tar.gz: ddee13f7d9a8ce8fdcfbfc220c85444b76ef83d902631a6d2f8611efba14b64d
3
+ metadata.gz: 2865963449615858e20b177a63a9e19504d7b70aa0fa3be2d069e9577b353fd8
4
+ data.tar.gz: 1312dbbcbf275a39d3be59139e95f418cb5fd73836fda2ab2d0d6e4a5366f04a
5
5
  SHA512:
6
- metadata.gz: edf6f2107a74de5049d964a4ea07078ed9ebb87484c74a20aa53658fcde9025dcb8771ce392fdf500ff108f9dfff725ccd1d32b0fa6aab90287629d7ef2293a3
7
- data.tar.gz: 3b7d800f902fc9001caeaa70497ddbc6c3e9488e4b11ebe6a7310c8da605d1b9064907e57afe94a78d4ea4d32dbe8478390634cfbc193e2ae323838e3f99d1ad
6
+ metadata.gz: 32164953fa9eff7044f9c0cc8a88822363187b3d1b804861c4702bf90a2a607cf479f2660863bea7fb75aa1c0d01fb266fc0d19c5bf9fc22a51210bd38318917
7
+ data.tar.gz: 9869a0657c1e2bb8c4c18cf2b4fa97a9fd89acf28fa1a7575c57261965d59a203955be2d96ab35157e35aa3f5f4f5a9ae6422f8c0ef33c9f213137e1aaee84a4
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # GraphQLGenerator
2
2
 
3
- > This gem creates a Service Generator so you can use it as a part of rails generators.
4
-
5
3
  ## Installation
6
4
 
7
5
  Add this line to your application's Gemfile:
@@ -17,3 +15,34 @@ And then execute:
17
15
  Or install it yourself as:
18
16
 
19
17
  $ gem install graphql-generator
18
+
19
+ ## Usage
20
+
21
+ To run generator of model Book, run:
22
+
23
+ $ rails generate graphql_model a title:string! num_pages:int! color:str is_for_sale:bool! author:ref!:users --name book
24
+
25
+ This will generate
26
+
27
+ 1. migration
28
+ 2. model
29
+ 3. GraphQL type
30
+ 4. GraphQL mutations: create, update, delete
31
+ 5. Facotry
32
+ 6. Rspec tests for mutations: create, update, delete
33
+
34
+ Follow instructions, add mutation names in your 'mutation_type.rb' file
35
+ ### Note
36
+ * add as_json function to your test environment from lib/graphql_helper_generator/graphql_model/as_json
37
+ * '!' defines if the field is required
38
+ * 'ref' param will create field author with reference to table users. If names are the same, you may not specity reference table
39
+ * 'string, str' note, that both string and str can be used, as well as int:integer, bool:boolean
40
+ * Additional parameter '--input_type true' will create input type of the model
41
+
42
+ Run migration
43
+
44
+ $ rails db:migrate
45
+
46
+ Run tests
47
+
48
+ $ rspec --tag current
@@ -0,0 +1,28 @@
1
+ def as_json(model, *keys)
2
+ attributes = model.attributes
3
+
4
+ attributes =
5
+ if keys.empty?
6
+ attributes
7
+ else
8
+ keys = keys.map(&:to_s)
9
+ attributes.select do |key|
10
+ keys.include?(key)
11
+ end
12
+ end
13
+
14
+ attributes =
15
+ attributes
16
+ .transform_keys { |k| k.camelcase(:lower) }
17
+ .transform_values do |v|
18
+ if v.is_a?(ActiveSupport::TimeWithZone)
19
+ v.to_s
20
+ elsif v.respond_to?(:attributes)
21
+ as_json(v)
22
+ else
23
+ v
24
+ end
25
+ end
26
+
27
+ attributes
28
+ end
@@ -1,3 +1,3 @@
1
1
  module GraphqlHelperGenerator
2
- VERSION = "0.0.31"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_helper_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.31
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Savinov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,6 +53,7 @@ files:
53
53
  - graphql_generator.gemspec
54
54
  - lib/graphql_helper_generator.rb
55
55
  - lib/graphql_helper_generator/graphql_model/USAGE
56
+ - lib/graphql_helper_generator/graphql_model/as_json
56
57
  - lib/graphql_helper_generator/graphql_model/graphql_model_generator.rb
57
58
  - lib/graphql_helper_generator/graphql_model/templates/graphql_types/input_type_template.erb
58
59
  - lib/graphql_helper_generator/graphql_model/templates/graphql_types/type_template.erb