graphql-rails-generators 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b3e945d1874ce80d7b6869974c0ff1ed879ab4c05a0cf7c95f45e92a7353592
4
- data.tar.gz: 303b4b236b892bdf7062153bbd502f198426ca666557a2a3edee34964be8edb1
3
+ metadata.gz: 4d1f19fe2c22034491865750f8ec36200eb0e7a4b61988fecfe19b7436b19b2c
4
+ data.tar.gz: 63fd8fa193b7e7bb5e7b8b3096473d7ea7187e1c93f855e9c7e92ef4708d6fa6
5
5
  SHA512:
6
- metadata.gz: 00fc8c39ac7fc1fbe52c5441af7c23992767837e6416466cb10265ef756195c241f3736aa90b7d8079536f3d75e2efb5ae3b098114be99bf51fbe1c7ed39d03b
7
- data.tar.gz: eb88f4cc1003f4eedfecead2bfb983f1a47aa8ee318a20fd17436cfb03b995073baf456adb7ad76d535f3b9f9205a4294e9ef0a5d1c06915c171f7b9f2c1672b
6
+ metadata.gz: 3449da630a364609b9a7e5fba18fd518ffb8e9cf4728de0526b64c9bb14b750ab5dd8de0319afd6b206b1f8dd37ea38f1ed5468376148f8e2689902e8e9d2185
7
+ data.tar.gz: c023afd1016f7f85a7b1ec840151c605a6d5d4d935ff4ef8fbb27faa63a08a7511e04e5b11113305c0767f4da542c4f94f3c8e9d827b8fef9814f4720622d1ca
data/README.md CHANGED
@@ -31,7 +31,7 @@ $ rails generate gql:model_type MODEL_CLASS
31
31
 
32
32
  #### Options
33
33
 
34
- * `--name` - customize the file/class name, useful if you don't want the default Type suffix.
34
+ - `--name` - customize the file/class name, useful if you don't want the default Type suffix.
35
35
 
36
36
  #### Example
37
37
 
@@ -39,7 +39,7 @@ $ rails generate gql:model_type MODEL_CLASS
39
39
  # app/graphql/post_type.rb
40
40
  module Types
41
41
  class PostType < Types::BaseObject
42
- field :id, Int, null: true
42
+ field :id, GraphQL::Types::ID, null: true
43
43
  field :title, String, null: true
44
44
  field :body, String, null: true
45
45
  field :created_at, GraphQL::Types::ISO8601DateTime, null: true
@@ -58,7 +58,7 @@ rails generate gql:input Post
58
58
 
59
59
  #### Options
60
60
 
61
- * `--name` - customize the file/class name, useful if you don't want the default Input suffix.
61
+ - `--name` - customize the file/class name, useful if you don't want the default Input suffix.
62
62
 
63
63
  #### Example
64
64
 
@@ -117,7 +117,7 @@ module Mutations
117
117
  field :post, Types::PostType, null: true
118
118
 
119
119
  argument :attributes, Types::Input::PostInput, required: true
120
- argument :id, Int, required: false
120
+ argument :id, GraphQL::Types::ID, required: false
121
121
 
122
122
  def resolve(attributes:, id: nil)
123
123
  model = find_or_build_model(id)
@@ -68,5 +68,19 @@ module Gql
68
68
  klass.join("\n")
69
69
  end
70
70
  end
71
+
72
+ def class_with_arguments(namespace, name, superclass, fields)
73
+ wrap_in_namespace(namespace) do |indent|
74
+ klass = []
75
+ klass << sprintf("%sclass %s < %s", " " * indent, name, superclass)
76
+
77
+ fields.each do |field|
78
+ klass << sprintf("%sargument :%s, %s, required: %s", " " * (indent + 1), field[:name], field[:gql_type], !field[:null])
79
+ end
80
+
81
+ klass << sprintf("%send", " " * indent)
82
+ klass.join("\n")
83
+ end
84
+ end
71
85
  end
72
86
  end
@@ -22,7 +22,7 @@ module Gql
22
22
  fields.reject! { |field| !options['include_columns'].include?(field[:name]) }
23
23
  end
24
24
 
25
- code = class_with_fields(options['namespace'], name, superclass, fields)
25
+ code = class_with_arguments(options['namespace'], name, superclass, fields)
26
26
  file_name = File.join(root_directory(options['namespace']), "#{name.underscore}.rb")
27
27
 
28
28
  create_file file_name, code
@@ -2,7 +2,7 @@ module Mutations
2
2
  class <%= prefixed_class_name('Delete') %> < Mutations::BaseMutation
3
3
  field :<%= singular_name %>, Types::<%= name %>Type, null: true
4
4
 
5
- argument :id, Int, required: true
5
+ argument :id, GraphQL::Types::ID, required: true
6
6
 
7
7
  def resolve(id:)
8
8
  model = <%= class_name %>.find(id)
@@ -0,0 +1,9 @@
1
+ module Types
2
+ module Input
3
+ class <%= prefixed_class_name(mutation_prefix) %> < Types::BaseInputObject
4
+ <% fields.each do |field| %>
5
+ argument :<%= field[:name] %>, <%= field[:gql_type] %>, required: false
6
+ <% end %>
7
+ end
8
+ end
9
+ end
@@ -3,7 +3,7 @@ module Mutations
3
3
  field :<%= singular_name %>, Types::<%= @model_name %>Type, null: true
4
4
 
5
5
  argument :attributes, Types::Input::<%= @model_name %>Input, required: true
6
- argument :id, Int, required: false
6
+ argument :id, GraphQL::Types::ID, required: false
7
7
 
8
8
  def resolve(attributes:, id: nil)
9
9
  model = find_or_build_model(id)
@@ -2,7 +2,7 @@ module Mutations
2
2
  class <%= prefixed_class_name('Update') %> < Mutations::BaseMutation
3
3
  field :<%= singular_name %>, Types::<%= name %>Type, null: true
4
4
 
5
- argument :id, Int, required: true
5
+ argument :id, GraphQL::Types::ID, required: true
6
6
  argument :attributes, Types::Input::<%= name %>Input, required: true
7
7
 
8
8
  def resolve(attributes:, id:)
@@ -1,3 +1,3 @@
1
1
  module GraphqlRailsGenerators
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-rails-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Sharp
@@ -27,6 +27,7 @@ files:
27
27
  - lib/generators/gql/mutations_generator.rb
28
28
  - lib/generators/gql/templates/create_mutation.rb
29
29
  - lib/generators/gql/templates/delete_mutation.rb
30
+ - lib/generators/gql/templates/input_template.rb
30
31
  - lib/generators/gql/templates/model_mutation.rb
31
32
  - lib/generators/gql/templates/model_search.rb
32
33
  - lib/generators/gql/templates/model_search_base.rb
@@ -51,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  - !ruby/object:Gem::Version
52
53
  version: '0'
53
54
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.7.9
55
+ rubygems_version: 3.1.6
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: Rails graphql generators