hq-graphql 2.0.5 → 2.0.6

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: bbe2582301bf466529f9b30a2afde7e13df59702a15a0119c2a9dbb87753d631
4
- data.tar.gz: 8054919523ba2b197092b30c32bda946310e07bca0133aad0a91b27391fe53bb
3
+ metadata.gz: 29c063cc8a29b6e30df91f11f8ed83bcaebee761fff76630bc2b2e80af9781d2
4
+ data.tar.gz: cb3e76b3c272ee517fd9de9b71c65695b5379e8cd3f2a2b412edb85419b12fe3
5
5
  SHA512:
6
- metadata.gz: 7996cc965c630d3625416f06f03c4188c0a853b66c32414eb8885a4d2728eee17de57fb4608a6b9d8359ac614220654709d9862eeccc66ebc3d63f01928e1e38
7
- data.tar.gz: 1183dd46cafa0683e4caa6d99584f0681d75c5d7e07f74a263fc2fcd894c924f08d40f7e85c6555f6dbd71fc7e0abfaebe9ede2ebefe18daecf9fbb9f4d497c1
6
+ metadata.gz: 992f59fa59af5c4d3d06a5902a85dde3a1839c881ac25fa15586ff8a92d15e4cde75192159a9ec0e939c286c99a2e83a2390203b84bf3de0c151bbf796945213
7
+ data.tar.gz: 242640df93c46a0a1d8f1af7851bf659901b896ae8c5f2e4088ece50909fdd31ea81cd20c6809a5e24f2c965b36db74bfdcb081c18ef698b062f3fb14ad54038
data/lib/hq/graphql.rb CHANGED
@@ -60,7 +60,7 @@ end
60
60
 
61
61
  require "hq/graphql/active_record_extensions"
62
62
  require "hq/graphql/scalars"
63
-
63
+ require "hq/graphql/comparator"
64
64
  require "hq/graphql/inputs"
65
65
  require "hq/graphql/input_object"
66
66
  require "hq/graphql/loaders"
@@ -0,0 +1,50 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require "graphql/schema_comparator"
5
+
6
+ module HQ
7
+ module GraphQL
8
+ class Comparator
9
+ # Higher values will include changes from criticalities with lower values as well.
10
+ # For example, setting the criticality as dangerous will return dangerous and breaking changes.
11
+ CRITICALITY = {
12
+ breaking: 0,
13
+ dangerous: 1,
14
+ non_breaking: 2
15
+ }
16
+
17
+ class << self
18
+ def compare(old_schema, new_schema, criticality: :breaking)
19
+ level = CRITICALITY[criticality]
20
+ raise ::ArgumentError, "Invalid criticality. Possible values are #{CRITICALITY.keys.join(", ")}" unless level
21
+
22
+ result = ::GraphQL::SchemaComparator.compare(convert_schema_to_string(old_schema), convert_schema_to_string(new_schema))
23
+ return nil if result.identical?
24
+
25
+ changes = {}
26
+ changes[:breaking] = result.breaking_changes
27
+ if level >= CRITICALITY[:dangerous]
28
+ changes[:dangerous] = result.dangerous_changes
29
+ end
30
+ if level >= CRITICALITY[:non_breaking]
31
+ changes[:non_breaking] = result.non_breaking_changes
32
+ end
33
+
34
+ changes
35
+ end
36
+
37
+ def dump_schema_to_file(directory:, filename:, schema:)
38
+ ::FileUtils.mkdir_p(directory)
39
+ ::File.open(::File.join(directory, filename), "w") { |file| file.write(schema.to_definition) }
40
+ end
41
+
42
+ private
43
+
44
+ def convert_schema_to_string(schema)
45
+ schema.is_a?(::String) ? schema : schema.to_definition
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module HQ
5
5
  module GraphQL
6
- VERSION = "2.0.5"
6
+ VERSION = "2.0.6"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-14 00:00:00.000000000 Z
11
+ date: 2019-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0.4'
61
+ - !ruby/object:Gem::Dependency
62
+ name: graphql-schema_comparator
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.6'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.6'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: pg
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +281,7 @@ files:
267
281
  - lib/hq-graphql.rb
268
282
  - lib/hq/graphql.rb
269
283
  - lib/hq/graphql/active_record_extensions.rb
284
+ - lib/hq/graphql/comparator.rb
270
285
  - lib/hq/graphql/config.rb
271
286
  - lib/hq/graphql/engine.rb
272
287
  - lib/hq/graphql/field.rb