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 +5 -5
- data/lib/graphql/extras/rspec.rb +44 -14
- data/lib/graphql/extras/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e0eea726ab643425fcc8b63f518a757a132549b2f4d7bc15fa9be79ac2cf830
|
4
|
+
data.tar.gz: '08847c52f2c42c505e8201147c3826adebf21f33919385d4985cb6f334300493'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41487444c67cba8707b0fc8bea877bcb9ad659f6d3732e2a28a79823d451ba20bf7ccb32a9d3c3e739dd8ba6237423c661f70fe3bf0a7a543bdae870e3ef1091
|
7
|
+
data.tar.gz: 3c2557eefb6bcd90f68a09ac019fa967743c0cd89a23f0bdce1708363daf26877d53a975aa11057bde08d9b0b3f4bc8e3d18989f61083648cd6bef90448cb256
|
data/lib/graphql/extras/rspec.rb
CHANGED
@@ -6,10 +6,8 @@ module GraphQL
|
|
6
6
|
module Extras
|
7
7
|
module RSpec
|
8
8
|
class Queries
|
9
|
-
def
|
10
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
76
|
+
def parse
|
77
|
+
queries = Queries.new
|
78
|
+
printer = Printer.new
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
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)
|
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
|
+
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:
|
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
|
-
|
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.
|