graphql 0.17.1 → 0.17.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f5960d6a384a464a175999b3cdfa5eb4c2860a9
|
4
|
+
data.tar.gz: d7e7aa462056b9782c50fbc9221ee29954eb8e7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 034823d8acddd9ddfc5b1058f2d01994266d6334281660d744046115c8f4f1c89767b6deab971817a71bd495c7de8a2c7cf87e16f4a2551952263f3646cd2379
|
7
|
+
data.tar.gz: b652518f8ca33d1eb7cb73e5b6073e99a5a20305b09da661222e7b901c7035739675a7562c268bf880cd0b81dee184a9f66094e6dbf991c1610f097c0d2d2970
|
@@ -3,12 +3,13 @@ require "set"
|
|
3
3
|
module GraphQL
|
4
4
|
module InternalRepresentation
|
5
5
|
class Node
|
6
|
-
def initialize(ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new)
|
6
|
+
def initialize(parent:, ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new)
|
7
7
|
# Make sure these are kept in sync with #dup
|
8
8
|
@ast_node = ast_node
|
9
9
|
@return_type = return_type
|
10
10
|
@name = name
|
11
11
|
@definition_name = definition_name
|
12
|
+
@parent = parent
|
12
13
|
@definitions = definitions
|
13
14
|
@children = children
|
14
15
|
@spreads = spreads
|
@@ -16,7 +17,7 @@ module GraphQL
|
|
16
17
|
end
|
17
18
|
|
18
19
|
# Note: by the time this gets out of the Rewrite phase, this will be empty -- it's emptied out when fragments are merged back in
|
19
|
-
# @return [Array<GraphQL::
|
20
|
+
# @return [Array<GraphQL::InternalRepresentation::Node>] Fragment names that were spread in this node
|
20
21
|
attr_reader :spreads
|
21
22
|
|
22
23
|
# These are the compiled directives from fragment spreads, inline fragments, and the field itself
|
@@ -57,6 +58,20 @@ module GraphQL
|
|
57
58
|
# @return [Array<GraphQL::Query::Node>]
|
58
59
|
attr_reader :children
|
59
60
|
|
61
|
+
# @return [GraphQL::InternalRepresentation::Node] The node which this node is a child of
|
62
|
+
attr_reader :parent
|
63
|
+
|
64
|
+
# @return [GraphQL::InternalRepresentation::Node] The root node which this node is a (perhaps-distant) child of, or `self` if this is a root node
|
65
|
+
def owner
|
66
|
+
@owner ||= begin
|
67
|
+
if parent.nil?
|
68
|
+
self
|
69
|
+
else
|
70
|
+
parent.owner
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
60
75
|
def inspect(indent = 0)
|
61
76
|
own_indent = " " * indent
|
62
77
|
self_inspect = "#{own_indent}<Node #{name} (#{definition_name}: {#{definitions.keys.join("|")}} -> #{return_type})>"
|
@@ -36,6 +36,7 @@ module GraphQL
|
|
36
36
|
return_type: context.type_definition.unwrap,
|
37
37
|
ast_node: ast_node,
|
38
38
|
name: ast_node.name,
|
39
|
+
parent: nil,
|
39
40
|
)
|
40
41
|
@nodes.push(node)
|
41
42
|
@operations[ast_node.name] = node
|
@@ -53,6 +54,7 @@ module GraphQL
|
|
53
54
|
ast_node: ast_node,
|
54
55
|
name: node_name,
|
55
56
|
definition_name: ast_node.name,
|
57
|
+
parent: parent_node,
|
56
58
|
)
|
57
59
|
end
|
58
60
|
object_type = context.parent_type_definition.unwrap
|
@@ -72,18 +74,21 @@ module GraphQL
|
|
72
74
|
name: ast_node.name,
|
73
75
|
definition_name: ast_node.name,
|
74
76
|
ast_node: ast_node,
|
75
|
-
definitions: [context.directive_definition]
|
77
|
+
definitions: [context.directive_definition],
|
78
|
+
# This isn't used, the directive may have many parents in the case of inline fragment
|
79
|
+
parent: nil,
|
76
80
|
)
|
77
81
|
end
|
78
82
|
}
|
79
83
|
|
80
84
|
visitor[Nodes::FragmentSpread].enter << -> (ast_node, prev_ast_node) {
|
85
|
+
parent_node = @nodes.last
|
81
86
|
# Record _both sides_ of the dependency
|
82
87
|
spread_node = Node.new(
|
88
|
+
parent: parent_node,
|
83
89
|
name: ast_node.name,
|
84
90
|
ast_node: ast_node,
|
85
91
|
)
|
86
|
-
parent_node = @nodes.last
|
87
92
|
# The parent node has a reference to the fragment
|
88
93
|
parent_node.spreads.push(spread_node)
|
89
94
|
# And keep a reference from the fragment to the parent node
|
@@ -94,6 +99,7 @@ module GraphQL
|
|
94
99
|
|
95
100
|
visitor[Nodes::FragmentDefinition].enter << -> (ast_node, prev_ast_node) {
|
96
101
|
node = Node.new(
|
102
|
+
parent: nil,
|
97
103
|
name: ast_node.name,
|
98
104
|
return_type: context.type_definition,
|
99
105
|
ast_node: ast_node,
|
@@ -119,7 +125,7 @@ module GraphQL
|
|
119
125
|
# This fragment doesn't depend on any others,
|
120
126
|
# we should save it as the starting point for dependency resolution
|
121
127
|
frag_node = @nodes.pop
|
122
|
-
if frag_node
|
128
|
+
if !any_fragment_spreads?(frag_node)
|
123
129
|
@independent_fragments << frag_node
|
124
130
|
end
|
125
131
|
}
|
@@ -149,9 +155,9 @@ module GraphQL
|
|
149
155
|
|
150
156
|
# resolve the dependency (merge into dependent node)
|
151
157
|
deep_merge(dependent_node, fragment_node, rejected_spread_nodes.first.directives)
|
152
|
-
|
153
|
-
if
|
154
|
-
@independent_fragments.push(
|
158
|
+
owner = dependent_node.owner
|
159
|
+
if owner.ast_node.is_a?(Nodes::FragmentDefinition) && !any_fragment_spreads?(owner)
|
160
|
+
@independent_fragments.push(owner)
|
155
161
|
end
|
156
162
|
end
|
157
163
|
end
|
@@ -176,6 +182,11 @@ module GraphQL
|
|
176
182
|
end
|
177
183
|
child_node.directives.merge(extra_directives)
|
178
184
|
end
|
185
|
+
|
186
|
+
# return true if node or _any_ children have a fragment spread
|
187
|
+
def any_fragment_spreads?(node)
|
188
|
+
node.spreads.any? || node.children.any? { |name, node| any_fragment_spreads?(node) }
|
189
|
+
end
|
179
190
|
end
|
180
191
|
end
|
181
192
|
end
|
data/lib/graphql/version.rb
CHANGED
@@ -68,10 +68,18 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
68
68
|
fatContent
|
69
69
|
origin
|
70
70
|
}
|
71
|
+
|
71
72
|
... cheeseFields
|
72
73
|
|
73
74
|
... similarCheeseField
|
74
75
|
}
|
76
|
+
|
77
|
+
cheese2: cheese(id: 2) {
|
78
|
+
similarCheese(source: COW) {
|
79
|
+
id
|
80
|
+
}
|
81
|
+
... cheese2Fields
|
82
|
+
}
|
75
83
|
}
|
76
84
|
|
77
85
|
fragment cheeseFields on Cheese {
|
@@ -100,6 +108,18 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
100
108
|
}
|
101
109
|
}
|
102
110
|
}
|
111
|
+
|
112
|
+
fragment cheese2InnerFields on Cheese {
|
113
|
+
id
|
114
|
+
fatContent
|
115
|
+
}
|
116
|
+
|
117
|
+
fragment cheese2Fields on Cheese {
|
118
|
+
similarCheese(source: COW) {
|
119
|
+
... cheese2InnerFields
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
103
123
|
|}
|
104
124
|
|
105
125
|
it "puts all fragment members as children" do
|
@@ -117,6 +137,10 @@ describe GraphQL::InternalRepresentation::Rewrite do
|
|
117
137
|
assert_equal [EdibleInterface], cheese_field.children["origin"].definitions.keys
|
118
138
|
assert_equal [CheeseType, EdibleInterface], cheese_field.children["fatContent"].definitions.keys
|
119
139
|
assert_equal [CheeseType], cheese_field.children["flavor"].definitions.keys
|
140
|
+
|
141
|
+
# nested spread inside fragment definition:
|
142
|
+
cheese_2_field = op_node.children["cheese2"].children["similarCheese"]
|
143
|
+
assert_equal ["id", "fatContent"], cheese_2_field.children.keys
|
120
144
|
end
|
121
145
|
end
|
122
146
|
end
|