graphql-relay-walker 0.0.10 → 0.1.0
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 +5 -5
- data/graphql-relay-walker.gemspec +1 -1
- data/lib/graphql/relay/walker/query_builder.rb +64 -56
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 00cf59d81c662ef188eb65959cc248670a7903f1106bdf8fff03f8bfe1806fb4
|
4
|
+
data.tar.gz: cf5fbf3ff44b0021eb52794e79f4344b249652ce27e9b2a70ae4e1405a87a544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2600d978d68cac1e8c68df7ea99afec158079c01eb6499e8870c02a1deab7b4e5afbe9a615751d5ecc02c3fcfcde6ace04d129e918eeac61e8c31c59da16ad5a
|
7
|
+
data.tar.gz: 6df67485eacbb46bfcecda62e8a2314d8a7341961d5eddf63e7ea7fac9e350155567476ba4bdb3b47c3d19ff7d5fe3dec351d3e76ffe0012f60d72655371f926
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'graphql-relay-walker'
|
3
|
-
s.version = '0.0
|
3
|
+
s.version = '0.1.0'
|
4
4
|
s.licenses = ['MIT']
|
5
5
|
s.summary = 'A tool for traversing your GraphQL schema to proactively detect potential data access vulnerabilities.'
|
6
6
|
s.authors = ['Ben Toews']
|
@@ -58,27 +58,6 @@ module GraphQL::Relay::Walker
|
|
58
58
|
true
|
59
59
|
end
|
60
60
|
|
61
|
-
# Private: Make a AST of the given type.
|
62
|
-
#
|
63
|
-
# klass - The GraphQL::Language::Nodes::AbstractNode subclass
|
64
|
-
# to create.
|
65
|
-
# needs_selections: - Boolean. Will this AST be invalid if it doesn't have
|
66
|
-
# any selections?
|
67
|
-
#
|
68
|
-
# Returns a GraphQL::Language::Nodes::AbstractNode subclass instance or nil
|
69
|
-
# if the created AST was invalid for having no selections.
|
70
|
-
def make(klass, needs_selections: true)
|
71
|
-
k_ast = klass.new
|
72
|
-
yield(k_ast) if block_given?
|
73
|
-
k_ast.selections.compact!
|
74
|
-
|
75
|
-
if k_ast.selections.empty? && needs_selections
|
76
|
-
nil
|
77
|
-
else
|
78
|
-
k_ast
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
61
|
# Make an inline fragment AST.
|
83
62
|
#
|
84
63
|
# type - The GraphQL::ObjectType instance to make the fragment
|
@@ -89,21 +68,29 @@ module GraphQL::Relay::Walker
|
|
89
68
|
# Returns a GraphQL::Language::Nodes::InlineFragment instance or nil if the
|
90
69
|
# created AST was invalid for having no selections.
|
91
70
|
def inline_fragment_ast(type, with_children: true)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
elsif connection_field?(field) && include?(field_type)
|
101
|
-
if_ast.selections << connection_field_ast(field)
|
102
|
-
end
|
71
|
+
selections = []
|
72
|
+
if with_children
|
73
|
+
type.all_fields.each do |field|
|
74
|
+
field_type = field.type.unwrap
|
75
|
+
if node_field?(field) && include?(field_type)
|
76
|
+
selections << node_field_ast(field)
|
77
|
+
elsif connection_field?(field) && include?(field_type)
|
78
|
+
selections << connection_field_ast(field)
|
103
79
|
end
|
104
|
-
elsif id = type.get_field('id')
|
105
|
-
if_ast.selections << field_ast(id)
|
106
80
|
end
|
81
|
+
elsif id = type.get_field('id')
|
82
|
+
selections << field_ast(id)
|
83
|
+
end
|
84
|
+
|
85
|
+
selections.compact!
|
86
|
+
|
87
|
+
if selections.none?
|
88
|
+
nil
|
89
|
+
else
|
90
|
+
GraphQL::Language::Nodes::InlineFragment.new(
|
91
|
+
type: make_type_name_node(type.name),
|
92
|
+
selections: selections,
|
93
|
+
)
|
107
94
|
end
|
108
95
|
end
|
109
96
|
|
@@ -120,20 +107,19 @@ module GraphQL::Relay::Walker
|
|
120
107
|
type = field.type.unwrap
|
121
108
|
|
122
109
|
# Bail unless we have the required arguments.
|
123
|
-
|
124
|
-
valid_input?(arg.type, nil)
|
125
|
-
end.all? do |name, _|
|
126
|
-
arguments.key?(name)
|
110
|
+
required_args_are_present = field.arguments.all? do |arg_name, arg|
|
111
|
+
arguments.key?(arg_name) || valid_input?(arg.type, nil)
|
127
112
|
end
|
128
113
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
114
|
+
if !required_args_are_present
|
115
|
+
nil
|
116
|
+
else
|
117
|
+
f_alias = field.name == 'id' ? nil : random_alias
|
118
|
+
f_args = arguments.map do |name, value|
|
133
119
|
GraphQL::Language::Nodes::Argument.new(name: name, value: value)
|
134
120
|
end
|
135
121
|
|
136
|
-
|
122
|
+
GraphQL::Language::Nodes::Field.new(name: field.name, alias: f_alias, arguments: f_args)
|
137
123
|
end
|
138
124
|
end
|
139
125
|
|
@@ -143,17 +129,27 @@ module GraphQL::Relay::Walker
|
|
143
129
|
#
|
144
130
|
# Returns a GraphQL::Language::Nodes::Field instance.
|
145
131
|
def node_field_ast(field)
|
146
|
-
field_ast(field)
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
132
|
+
f_ast = field_ast(field)
|
133
|
+
return nil if f_ast.nil?
|
134
|
+
type = field.type.unwrap
|
135
|
+
selections = f_ast.selections.dup
|
136
|
+
|
137
|
+
if type.kind.object?
|
138
|
+
selections << field_ast(type.get_field('id'))
|
139
|
+
else
|
140
|
+
possible_node_types(type).each do |if_type|
|
141
|
+
selections << inline_fragment_ast(if_type, with_children: false)
|
155
142
|
end
|
156
143
|
end
|
144
|
+
|
145
|
+
selections.compact!
|
146
|
+
|
147
|
+
if f_ast.respond_to?(:merge) # GraphQL-Ruby 1.9+
|
148
|
+
f_ast = f_ast.merge(selections: selections)
|
149
|
+
else
|
150
|
+
f_ast.selections = selections
|
151
|
+
end
|
152
|
+
f_ast
|
157
153
|
end
|
158
154
|
|
159
155
|
# Make a field AST for an edges field.
|
@@ -162,8 +158,14 @@ module GraphQL::Relay::Walker
|
|
162
158
|
#
|
163
159
|
# Returns a GraphQL::Language::Nodes::Field instance.
|
164
160
|
def edges_field_ast(field)
|
165
|
-
field_ast(field)
|
166
|
-
|
161
|
+
f_ast = field_ast(field)
|
162
|
+
return nil if f_ast.nil?
|
163
|
+
node_fields = [node_field_ast(field.type.unwrap.get_field('node'))]
|
164
|
+
if f_ast.respond_to?(:merge) # GraphQL-Ruby 1.9+
|
165
|
+
f_ast.merge(selections: f_ast.selections + node_fields)
|
166
|
+
else
|
167
|
+
f_ast.selections.concat(node_fields)
|
168
|
+
f_ast
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
@@ -174,8 +176,14 @@ module GraphQL::Relay::Walker
|
|
174
176
|
# Returns a GraphQL::Language::Nodes::Field instance or nil if the created
|
175
177
|
# AST was invalid for missing required arguments.
|
176
178
|
def connection_field_ast(field)
|
177
|
-
field_ast(field, connection_arguments)
|
178
|
-
|
179
|
+
f_ast = field_ast(field, connection_arguments)
|
180
|
+
return nil if f_ast.nil?
|
181
|
+
edges_fields = [edges_field_ast(field.type.unwrap.get_field('edges'))]
|
182
|
+
if f_ast.respond_to?(:merge) # GraphQL-Ruby 1.9+
|
183
|
+
f_ast.merge(selections: f_ast.selections + edges_fields)
|
184
|
+
else
|
185
|
+
f_ast.selections.concat(edges_fields)
|
186
|
+
f_ast
|
179
187
|
end
|
180
188
|
end
|
181
189
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-relay-walker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Toews
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.6
|
105
|
+
rubygems_version: 2.7.6
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: A tool for traversing your GraphQL schema to proactively detect potential
|