graphql-extras 0.2.4 → 0.2.5

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
- SHA1:
3
- metadata.gz: 18eadb182c9a76519d6d2edeb5b0d4e1878fa09d
4
- data.tar.gz: 2c25c5003f3734e0c7c2c083cc47a76531eda759
2
+ SHA256:
3
+ metadata.gz: 0e0eea726ab643425fcc8b63f518a757a132549b2f4d7bc15fa9be79ac2cf830
4
+ data.tar.gz: '08847c52f2c42c505e8201147c3826adebf21f33919385d4985cb6f334300493'
5
5
  SHA512:
6
- metadata.gz: 7966e2f06aa836e34f0f42eecfdc1606f5a278f83d0c717f6001ab5c234424e6f50a3dd959ec57c477d9f74f9a35b25e25bbf38e47cda60216b70af3633b3231
7
- data.tar.gz: 291c570bd60ce89c6eb3beef5beab2a420967286c74ffbf19543f7623b3387feb70dc6871a3746463e01a2b611356d92e41d3fa3487755ec9061afe92db59b7b
6
+ metadata.gz: 41487444c67cba8707b0fc8bea877bcb9ad659f6d3732e2a28a79823d451ba20bf7ccb32a9d3c3e739dd8ba6237423c661f70fe3bf0a7a543bdae870e3ef1091
7
+ data.tar.gz: 3c2557eefb6bcd90f68a09ac019fa967743c0cd89a23f0bdce1708363daf26877d53a975aa11057bde08d9b0b3f4bc8e3d18989f61083648cd6bef90448cb256
@@ -6,10 +6,8 @@ module GraphQL
6
6
  module Extras
7
7
  module RSpec
8
8
  class Queries
9
- def initialize(values)
10
- values.each do |key, value|
11
- define_singleton_method(key) { value }
12
- end
9
+ def add(key, value)
10
+ define_singleton_method(key) { value }
13
11
  end
14
12
  end
15
13
 
@@ -63,19 +61,51 @@ module GraphQL
63
61
  end
64
62
  end
65
63
 
66
- def graphql_fixture(filename)
67
- root = ::RSpec.configuration.graphql_fixture_path
68
- contents = File.read(File.join(root, filename))
64
+ class Parser
65
+ include ::GraphQL::Language
66
+
67
+ def initialize(document)
68
+ @operations = document.definitions
69
+ .grep(Nodes::OperationDefinition)
70
+
71
+ @fragments = document.definitions
72
+ .grep(Nodes::FragmentDefinition)
73
+ .reduce({}) { |acc, f| acc.merge(f.name => f) }
74
+ end
69
75
 
70
- parts = contents.split(/^(?=fragment|query|mutation|subscription)/)
71
- queries, fragments = parts.partition { |query| query !~ /^fragment/ }
76
+ def parse
77
+ queries = Queries.new
78
+ printer = Printer.new
72
79
 
73
- result = queries.reduce({}) { |acc, query|
74
- name = query.split(/\W+/).at(1).underscore.to_sym
75
- acc.merge(name => [*fragments, query].join)
76
- }
80
+ @operations.each do |op|
81
+ nodes = [op, *find_fragments(op)]
82
+ nodes = nodes.map { |node| printer.print(node) }
83
+ queries.add op.name.underscore, nodes.join
84
+ end
77
85
 
78
- Queries.new(result)
86
+ queries
87
+ end
88
+
89
+ private
90
+
91
+ def find_fragments(node)
92
+ node.selections.flat_map do |field|
93
+ if field.is_a? Nodes::FragmentSpread
94
+ fragment = @fragments.fetch(field.name)
95
+ [fragment, *find_fragments(fragment)]
96
+ else
97
+ find_fragments(field)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def graphql_fixture(filename)
104
+ root = ::RSpec.configuration.graphql_fixture_path
105
+ file = File.join(root, filename)
106
+ document = ::GraphQL.parse_file(file)
107
+ parser = Parser.new(document)
108
+ parser.parse
79
109
  end
80
110
 
81
111
  def use_schema(*args)
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Extras
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-04 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -192,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.6.14
195
+ rubygems_version: 3.1.2
197
196
  signing_key:
198
197
  specification_version: 4
199
198
  summary: Utiltities for building GraphQL APIs.