graphql_scaffold_fan 0.1.3 → 0.1.6

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: 5ba50341e941f5a2367cb3a550f3701fc59eacbbb550184a9e697229b07e8ae4
4
- data.tar.gz: 687c142252f59cb524e2e3f01b8bc3aac8ed8cca769659e4cf5171b2c5710de1
3
+ metadata.gz: 1ca0c115c610c53ece69712300c30d7b6a4b8d604360e1ff12983c5efb58bd5c
4
+ data.tar.gz: 2238a18b5a643e5ae89b31bcc08e44aad0965caedd145d6e72210ebf34c0250a
5
5
  SHA512:
6
- metadata.gz: 63d9ae28ce65ecae2f72ccddde40639eb6185624b12ce6a585d48ff8f70d858d73fa923b6ef3b25b9529c849b17f3d425d87e585a4cb145c79faed8267ab4b39
7
- data.tar.gz: d482fe72bcffba00321c07c0e708864182812655197a415319f8eeca4d695c5d4cf2d6f33edd79ce02a4975c84d3bfe79db938b32bc494be7d469fe07e84ceef
6
+ metadata.gz: 73ce30b9e17ae0d95728e73f46b03eb5470123ad1d85c58de2a7a13a03a28123fc45ae2a7698140f01da4aa93473b4e1fd7a272dd164b3a1eb7752c831c28175
7
+ data.tar.gz: cfc8defe9cf83b6a6aa3a8d7d509fbf316c3c8f6d6f2cddac45b7b359124d5fa19e8b702de67dab3c6334b622ec28646f31936e256bbe1e70850734c16d32981
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in graphql_scaffold_fan.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.0'
8
+ gem 'rake', '~> 13.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_scaffold_fan (0.1.2)
4
+ graphql_scaffold_fan (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -9,6 +9,7 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
+ gem 'graphql'
12
13
  gem 'graphql_scaffold_fan'
13
14
  ```
14
15
 
@@ -22,7 +23,18 @@ Or install it yourself as:
22
23
 
23
24
  ## Usage
24
25
 
25
- TODO: Write usage instructions here
26
+ Run `rails generate -h` to see if the GraphqlScaffold genertors have been loaded correctly
27
+ Example commands:
28
+ `rails generate graphql_scaffold:init <ProjectName>` Initial command will use the root folder name as its ProjectName, so be free to enter any character here.
29
+ `rails generate graphql_scaffold:mutation <MutationName>`
30
+ `rails generate graphql_scaffold:type <TypeName>`
31
+
32
+ If you ever found mutation not loading in schema: pls check the following code
33
+ `config.load_defaults 6.1`
34
+ `# config.autoloader = :zeitwerk`
35
+ Reference link:
36
+ https://guides.rubyonrails.org/classic_to_zeitwerk_howto.html
37
+
26
38
 
27
39
  ## Development
28
40
 
@@ -19,7 +19,7 @@ module GraphqlScaffold
19
19
  def create_admin_schema_file
20
20
  @top_folder_name = File.basename(Dir.getwd)
21
21
  dir_path = 'app/graphql'
22
- file_path = dir_path + "#{@top_folder_name.underscore}_admin_schema.rb"
22
+ file_path = dir_path + "/#{@top_folder_name.underscore}_admin_schema.rb"
23
23
  FileUtils.mkdir_p(dir_path) unless File.exist?(dir_path)
24
24
 
25
25
  if File.exist?(file_path)
@@ -30,7 +30,6 @@ module GraphqlScaffold
30
30
  end
31
31
 
32
32
  def create_admin_controller_file
33
- @top_folder_name = File.basename(Dir.getwd)
34
33
  dir_path = 'app/controllers'
35
34
  file_path = dir_path + '/admin_graphql_controller.rb'
36
35
  FileUtils.mkdir_p(dir_path) unless File.exist?(dir_path)
@@ -41,6 +40,23 @@ module GraphqlScaffold
41
40
  template 'admin_controller.haml', file_path
42
41
  end
43
42
  end
43
+
44
+ def add_route
45
+ route_dir_path = 'config'
46
+ route_file_path = route_dir_path + '/routes.rb'
47
+
48
+ FileUtils.mkdir_p(route_dir_path) unless File.exist?(route_dir_path)
49
+
50
+ if File.exist?(route_file_path)
51
+ file = File.open(route_file_path)
52
+ file_data = file.read
53
+ new_file_data = file_data.insert(-6, "\n mount GraphqlPlayground::Rails::Engine, at: '/graphiql_admin', graphql_path: 'api/admin/graphql', as: :admin_graphiql\n post 'api/admin/graphql', to: 'graphql_admin#execute'")
54
+ File.write(file, new_file_data)
55
+ p 'Write to routes.rb successfully'
56
+ else
57
+ p 'Please create routes.rb file under config folder firstly'
58
+ end
59
+ end
44
60
  end
45
61
  end
46
62
  end
@@ -6,9 +6,9 @@ module GraphqlScaffold
6
6
 
7
7
  def create_base_admin_mutation_file
8
8
  mutations_dir_path = 'app/graphql/mutations'
9
- generator_path = mutation_type_dir_path + '/base_admin_mutation.rb'
9
+ generator_path = mutations_dir_path + '/base_admin_mutation.rb'
10
10
 
11
- FileUtils.mkdir_p(mutation_type_dir_path) unless File.exist?(mutation_type_dir_path)
11
+ FileUtils.mkdir_p(mutations_dir_path) unless File.exist?(mutations_dir_path)
12
12
 
13
13
  if File.exist?(generator_path)
14
14
  p 'File base_admin_mutation.rb already exists'
@@ -117,7 +117,7 @@ module GraphqlScaffold
117
117
  file_data = file.read
118
118
  new_file_data = file_data.insert(-15, " has_admin_mutation :#{class_name}\n ")
119
119
  File.write(file, new_file_data)
120
- p 'Write to query_type.rb successfully'
120
+ p 'Write to mutation_type.rb successfully'
121
121
  else
122
122
  template 'mutation_type.haml', generator_path
123
123
  end
@@ -7,7 +7,6 @@ class AdminGraphqlController < ApplicationController
7
7
  # This allows for outside API access while preventing CSRF attacks,
8
8
  # but you'll have to authenticate your user separately
9
9
  protect_from_forgery with: :null_session
10
- after_action :track_action
11
10
 
12
11
  def execute
13
12
  variables = prepare_variables(params[:variables])
@@ -18,7 +17,7 @@ class AdminGraphqlController < ApplicationController
18
17
 
19
18
  @current_resource = context[:current_resource]
20
19
 
21
- result = <%= @top_folder_name.camelize %>AdminSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
20
+ result = <%= class_name %>AdminSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
22
21
  render json: result
23
22
  rescue StandardError => e
24
23
  raise e unless Rails.env.development?
@@ -54,11 +53,4 @@ class AdminGraphqlController < ApplicationController
54
53
 
55
54
  render json: { errors: [{ message: err.message, backtrace: err.backtrace }], data: {} }, status: :internal_server_error
56
55
  end
57
-
58
- def track_action
59
- variables = prepare_variables(params[:variables])
60
- query = params[:query]
61
- operation_name = params[:operationName]
62
- ahoy.track 'Admin Portal', query: query, variables: variables, operation_name: operation_name
63
- end
64
56
  end
@@ -1,4 +1,4 @@
1
- class <%= @top_folder_name.camelize %>AdminSchema < GraphQL::Schema
1
+ class <%= class_name %>AdminSchema < GraphQL::Schema
2
2
  use GraphQL::Tracing::NewRelicTracing, set_transaction_name: true
3
3
  use GraphqlDevise::SchemaPlugin.new(
4
4
  query: Types::Query::AdminUserQueryType,
@@ -6,7 +6,7 @@ module Mutations
6
6
 
7
7
  def resolve(**args)
8
8
  <%= class_name.underscore %> = <%= class_name %>.new(args)
9
- if <%= class_name.underscore %>.save
9
+ if <%= class_name.underscore %>.save
10
10
  <%= class_name.underscore %>
11
11
  else
12
12
  context.add_error(GraphQL::ExecutionError.new( <%= class_name.underscore %>.errors.full_messages.join(', ')))
@@ -5,7 +5,7 @@ module Mutations
5
5
  type Types::Admin::<%= class_name %>Type
6
6
 
7
7
  def resolve(id:)
8
- <%= class_name.underscore %> = ::<%= class_name %>.find(id)
8
+ <%= class_name.underscore %> = <%= class_name %>.find(id)
9
9
  <%= class_name.underscore %>.destroy!
10
10
  <%= class_name.underscore %>
11
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlScaffoldFan
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_scaffold_fan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fan Zhang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-28 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Helping creating graphql files
14
14
  email: