graphql-rails-generators 1.1.1 → 1.1.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 +4 -4
- data/README.md +4 -4
- data/lib/generators/gql/gql_generator_base.rb +14 -0
- data/lib/generators/gql/input_generator.rb +1 -1
- data/lib/generators/gql/templates/delete_mutation.rb +1 -1
- data/lib/generators/gql/templates/input_template.rb +9 -0
- data/lib/generators/gql/templates/model_mutation.rb +1 -1
- data/lib/generators/gql/templates/update_mutation.rb +1 -1
- data/lib/graphql-rails-generators/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d1f19fe2c22034491865750f8ec36200eb0e7a4b61988fecfe19b7436b19b2c
|
4
|
+
data.tar.gz: 63fd8fa193b7e7bb5e7b8b3096473d7ea7187e1c93f855e9c7e92ef4708d6fa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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,
|
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
|
-
|
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,
|
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 =
|
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,
|
5
|
+
argument :id, GraphQL::Types::ID, required: true
|
6
6
|
|
7
7
|
def resolve(id:)
|
8
8
|
model = <%= class_name %>.find(id)
|
@@ -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,
|
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,
|
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:)
|
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.
|
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
|
-
|
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
|