graphql_helper_generator 0.0.29 → 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: '0876cc158fd928020da6eb7c840aef257b0a768527cc0218a796a660e5c7f517'
4
- data.tar.gz: 718825e0ebce8164350fc1c5144f9fb70344a8c65e2094a9c1fabb1110582974
3
+ metadata.gz: 2865963449615858e20b177a63a9e19504d7b70aa0fa3be2d069e9577b353fd8
4
+ data.tar.gz: 1312dbbcbf275a39d3be59139e95f418cb5fd73836fda2ab2d0d6e4a5366f04a
5
5
  SHA512:
6
- metadata.gz: e3ac1e7ffc1c0513779420cdfd91204d9009445bbe2970e38e2a19e10b845ec3a59582926feb8a40f5b76d1356d13e2b80f587fbf01be17fb6439724b89c9817
7
- data.tar.gz: 3df85456d159c9a133c268a305338d30c8b6cc4a79c9144a437a1d8f865f9fb657a5b8bc8a4766025e61d97c8f7c94d9c3b90fd5173d862fdcfeb986c0f48075
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
@@ -167,7 +167,6 @@ class GraphqlModelGenerator < Rails::Generators::NamedBase
167
167
  if field[:type] == 'references' then name += 'Id' end
168
168
  str = "$" + name + ": "
169
169
  type = cast_to_graphql_input(field)
170
- if field[:array].present? then type = '[' + type + ']' end
171
170
  str += type
172
171
  if field[:required].present? then str += "!" end
173
172
  str
@@ -322,6 +321,9 @@ class GraphqlModelGenerator < Rails::Generators::NamedBase
322
321
  elsif type == 'Integer' then type = 'Int'
323
322
  elsif type == 'References' then type = 'ID'
324
323
  end
324
+
325
+ if field[:array].present? then type = '['+type+']' end
326
+
325
327
  type
326
328
  end
327
329
 
@@ -20,8 +20,8 @@ RSpec.describe 'Create<%= @camelize_name %>', type: :request, current: true do
20
20
  end
21
21
 
22
22
  it 'create_<%= @snake_case_name %> success' do
23
- <% for field in @create_reference %><%=field%> <% end %>
24
- <%= @snake_case_name%> = build(:<%= @snake_case_name %> <%= @include_references.map{|x| x}.join%>)
23
+ <% for field in @create_reference %><%=field%><% end %>
24
+ <%= @snake_case_name%> = build(:<%= @snake_case_name %><%= @include_references.map{|x| x}.join%>)
25
25
  variables = as_json(<%= @snake_case_name%>)
26
26
 
27
27
  json = graphql(query, variables: variables)
@@ -13,7 +13,7 @@ FactoryBot.define do
13
13
  when "datetime"
14
14
  "(Time.now + #{rand(1..5)}.hours).to_s"
15
15
  when "json"
16
- {hello: :world, new: 1}
16
+ {"hello": "world", "new": "1"}
17
17
  when "references"
18
18
  "create(:#{field[:name]})"
19
19
  else
@@ -39,7 +39,7 @@ FactoryBot.define do
39
39
  when "datetime"
40
40
  "(Time.now + #{rand(1..5)}.hours).to_s"
41
41
  when "json"
42
- {hello: :updated_world, updated: 100}
42
+ {"hello": "updated_world", "new_field": "100"}
43
43
  when "references"
44
44
  "create(:#{field[:name]})"
45
45
  else
@@ -1,3 +1,3 @@
1
1
  module GraphqlHelperGenerator
2
- VERSION = "0.0.29"
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.29
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-19 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