nulogy_graphql_api 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +15 -7
- data/lib/nulogy_graphql_api.rb +2 -0
- data/lib/nulogy_graphql_api/tasks/schema_changes_checker.rb +32 -0
- data/lib/nulogy_graphql_api/tasks/schema_generator.rb +40 -0
- data/lib/nulogy_graphql_api/version.rb +1 -1
- data/lib/tasks/graphql_schema.rake +5 -69
- data/nulogy_graphql_api.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db0c5e715fef76694b02bf7886fc6448576ef73aa0e2821dca7e3344843df29
|
4
|
+
data.tar.gz: 4238d07b94c47897ee083813a1845070c5021749d533eae83715c6e5f1e2397a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 686d0b9cab9be582ab6b83165c25e629013390024607370d9216e3a1f23324d8d3b28c3603af66ddac4854632b5c8058b14456f1c3becc56173a6c1b8e04fc48
|
7
|
+
data.tar.gz: fcc317f4c19cc3d75f24cf2613d5863c0ef2ac0b8931693ac62941467bc09e245d48bf52b526312d32ac1b2c0ef78fe069f76925757ad83ba6fdd9ced862e2ec
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.5.0
|
6
|
+
|
7
|
+
**Breaking Changes**
|
8
|
+
|
9
|
+
* Add `context` to the Rake task that generates the schema file.
|
10
|
+
This changes the way the schema is parsed. Please refer to the README file to see an example of how to use `context`.
|
11
|
+
|
5
12
|
## 0.4.0 (2020-07-06)
|
6
13
|
|
7
14
|
**Breaking Changes**
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "nulogy_graphql_api", "0.4.0"
|
8
|
+
gem "nulogy_graphql_api", "0.4.0"
|
9
9
|
```
|
10
10
|
|
11
11
|
And then execute:
|
@@ -126,15 +126,23 @@ end
|
|
126
126
|
There is a Rake task to generate the `schema.graphql` file. All you need to provide is the path to the old and the new schema files so that the task can detect breaking changes. If you don't have an old schema file because it's your first time generating it then the rake task will just create one for you.
|
127
127
|
|
128
128
|
```ruby
|
129
|
-
namespace :
|
129
|
+
namespace :graphql_api do
|
130
130
|
desc "Generate the graphql schema of the api."
|
131
131
|
|
132
132
|
task :generate_schema => :environment do
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
schema_file_path = MyApp::Engine.root.join("schema.graphql")
|
134
|
+
schema_definition_path = MyApp::Engine.root.join("path/to/schema/root/schema.rb")
|
135
|
+
|
136
|
+
# Context is an optional parameter, but may be required if you change the visibility of nodes in your graph
|
137
|
+
# i.e.
|
138
|
+
# def visible?(context)
|
139
|
+
# context[:current_user].superuser?
|
140
|
+
# end
|
141
|
+
context = {}
|
142
|
+
|
143
|
+
NulogyGraphqlApi::Tasks::SchemaGenerator
|
144
|
+
.new(schema_file_path, schema_definition_path, context: context)
|
145
|
+
.generate_schema
|
138
146
|
end
|
139
147
|
end
|
140
148
|
```
|
data/lib/nulogy_graphql_api.rb
CHANGED
@@ -4,6 +4,8 @@ require "nulogy_graphql_api/error_handling"
|
|
4
4
|
require "nulogy_graphql_api/graphql_executor"
|
5
5
|
require "nulogy_graphql_api/graphql_response"
|
6
6
|
require "nulogy_graphql_api/transaction_service"
|
7
|
+
require "nulogy_graphql_api/tasks/schema_changes_checker"
|
8
|
+
require "nulogy_graphql_api/tasks/schema_generator"
|
7
9
|
require "nulogy_graphql_api/types/user_error_type"
|
8
10
|
require "nulogy_graphql_api/types/uuid"
|
9
11
|
require "nulogy_graphql_api/version"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "graphql/schema_comparator"
|
2
|
+
require "rainbow"
|
3
|
+
|
4
|
+
module NulogyGraphqlApi
|
5
|
+
module Tasks
|
6
|
+
class SchemaChangesChecker
|
7
|
+
def check_changes(old_schema, new_schema)
|
8
|
+
compare_result = GraphQL::SchemaComparator.compare(old_schema, new_schema)
|
9
|
+
|
10
|
+
abort "Task aborted!\n #{Rainbow('No schema changes found.').green}" if compare_result.identical?
|
11
|
+
abort "Task aborted!" unless accept_breaking_changes?(compare_result)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def accept_breaking_changes?(compare_result)
|
17
|
+
return true if !compare_result.breaking? && compare_result.dangerous_changes.none?
|
18
|
+
|
19
|
+
puts Rainbow("\nThe current GraphQL Schema has breaking or dangerous changes:").yellow
|
20
|
+
|
21
|
+
compare_result.breaking_changes.concat(compare_result.dangerous_changes).each do |change|
|
22
|
+
puts Rainbow("\n\n- #{change.message} #{change.dangerous? ? '(Dangerous)' : '(Breaking)'}").yellow
|
23
|
+
puts Rainbow(" #{change.criticality.reason}").yellow
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "\n\nDo you want to update the schema anyway? [Y/n]"
|
27
|
+
|
28
|
+
STDIN.gets.chomp.downcase != "n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module NulogyGraphqlApi
|
2
|
+
module Tasks
|
3
|
+
class SchemaGenerator
|
4
|
+
def initialize(schema_output_path, schema_definition_path, context: {})
|
5
|
+
@schema_output_path = schema_output_path
|
6
|
+
@schema_definition_path = schema_definition_path
|
7
|
+
@context = context
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_schema
|
11
|
+
check_changes
|
12
|
+
write_schema_to_file
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def check_changes
|
18
|
+
return if old_schema.blank?
|
19
|
+
|
20
|
+
SchemaChangesChecker.new.check_changes(old_schema, schema_definition)
|
21
|
+
end
|
22
|
+
|
23
|
+
def old_schema
|
24
|
+
return unless File.exist?(@schema_output_path)
|
25
|
+
|
26
|
+
File.read(@schema_output_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def schema_definition
|
30
|
+
require @schema_definition_path
|
31
|
+
@schema_definition ||= GraphQL::Schema.descendants.first.to_definition(context: @context)
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_schema_to_file
|
35
|
+
File.write(@schema_output_path, schema_definition)
|
36
|
+
puts Rainbow("\nSuccessfully updated #{@schema_output_path}").green
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,75 +1,11 @@
|
|
1
1
|
namespace :nulogy_graphql_api do
|
2
2
|
desc "Generate a schema.graphql file"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
compare_result = GraphQL::SchemaComparator.compare(old_schema, new_schema)
|
4
|
+
task :generate_schema, [:schema_output_path, :schema_definition_path] => :environment do |_task, args|
|
5
|
+
abort "schema_definition_path is required" unless args.key?(:schema_definition_path)
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def accept_breaking_changes?(compare_result)
|
15
|
-
return true if !compare_result.breaking? && compare_result.dangerous_changes.none?
|
16
|
-
|
17
|
-
puts Rainbow("\nThe current GraphQL Schema has breaking or dangerous changes:").yellow
|
18
|
-
|
19
|
-
compare_result.breaking_changes.concat(compare_result.dangerous_changes).each do |change|
|
20
|
-
puts Rainbow("\n\n- #{change.message} #{change.dangerous? ? '(Dangerous)' : '(Breaking)'}").yellow
|
21
|
-
puts Rainbow(" #{change.criticality.reason}").yellow
|
22
|
-
end
|
23
|
-
|
24
|
-
puts "\n\nDo you want to update the schema anyway? [Y/n]"
|
25
|
-
|
26
|
-
STDIN.gets.chomp != "n"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class GraphqlSchemaGenerator
|
31
|
-
SCHEMA_FILE_NAME = "schema.graphql"
|
32
|
-
|
33
|
-
def generate_schema(old_schema_file_path, new_schema_file_path)
|
34
|
-
@old_schema_file_path = old_schema_file_path
|
35
|
-
@new_schema_file_path = new_schema_file_path
|
36
|
-
|
37
|
-
generate_schema_file
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def check_changes(old_schema, new_schema)
|
43
|
-
GraphqlSchemaChangesChecker.new.check_changes(old_schema, new_schema)
|
44
|
-
end
|
45
|
-
|
46
|
-
def new_schema
|
47
|
-
require @new_schema_file_path
|
48
|
-
|
49
|
-
GraphQL::Schema.descendants.first.to_definition
|
50
|
-
end
|
51
|
-
|
52
|
-
def old_schema
|
53
|
-
return nil unless File.exists?(@old_schema_file_path)
|
54
|
-
|
55
|
-
File.read(@old_schema_file_path)
|
56
|
-
end
|
57
|
-
|
58
|
-
def generate_schema_file
|
59
|
-
check_changes(old_schema, new_schema) if old_schema
|
60
|
-
|
61
|
-
write_new_schema_file
|
62
|
-
end
|
63
|
-
|
64
|
-
def write_new_schema_file
|
65
|
-
File.write(@old_schema_file_path, new_schema)
|
66
|
-
puts Rainbow("\nSuccessfully updated #{@old_schema_file_path}").green
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
task :generate_schema, [:old_schema_file_path, :new_schema_file_path] => :environment do |_task, args|
|
71
|
-
abort "new_schema_file_path is required" unless args.key?(:new_schema_file_path)
|
72
|
-
|
73
|
-
GraphqlSchemaGenerator.new.generate_schema(args[:old_schema_file_path], args[:new_schema_file_path])
|
7
|
+
NulogyGraphqlApi::Tasks::SchemaGenerator
|
8
|
+
.new(args[:schema_output_path], args[:schema_definition_path], context: {})
|
9
|
+
.generate_schema
|
74
10
|
end
|
75
11
|
end
|
data/nulogy_graphql_api.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_dependency "graphql", "~> 1.9"
|
32
32
|
spec.add_dependency "graphql-schema_comparator", "~> 0.6.1"
|
33
33
|
spec.add_dependency "rails", ">= 5.2.4", "< 6.1.0"
|
34
|
+
spec.add_dependency "rainbow", "~> 3.0.0"
|
34
35
|
|
35
36
|
spec.add_development_dependency "appraisal", "~> 2.1.0"
|
36
37
|
spec.add_development_dependency "rspec-rails", "~> 3.9.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nulogy_graphql_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: 6.1.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rainbow
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 3.0.0
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.0.0
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: appraisal
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +189,8 @@ files:
|
|
175
189
|
- lib/nulogy_graphql_api/rspec.rb
|
176
190
|
- lib/nulogy_graphql_api/rspec/graphql_helpers.rb
|
177
191
|
- lib/nulogy_graphql_api/rspec/graphql_matchers.rb
|
192
|
+
- lib/nulogy_graphql_api/tasks/schema_changes_checker.rb
|
193
|
+
- lib/nulogy_graphql_api/tasks/schema_generator.rb
|
178
194
|
- lib/nulogy_graphql_api/transaction_service.rb
|
179
195
|
- lib/nulogy_graphql_api/types/user_error_type.rb
|
180
196
|
- lib/nulogy_graphql_api/types/uuid.rb
|