graphql 0.18.3 → 0.18.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a2831bb2cf4c54f83f856f5e614a64b4e2a06e
|
4
|
+
data.tar.gz: ca550cdf4e4e9772f0facd364295754bf2bc1440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b52b0fd7948401ad258096f00611d63d7576d83981bd7efbda85a5d34fb7e3938ec661f357d92ab7d8bcf158a3e56ccc2be60a8402249746a9f14cda3edc601
|
7
|
+
data.tar.gz: 06cab8b10aa6f6d1fd03049e24cdca3f97c014801d16fbc127d6adb6f81b55bad57797c35cfeacf4e0958834cd5e74e9e8925ca304b9e70439028ae31e1f9ba7
|
@@ -5,13 +5,12 @@ module GraphQL
|
|
5
5
|
def initialize(field_name, value)
|
6
6
|
@field_name = field_name
|
7
7
|
@value = value
|
8
|
+
super("Cannot return null for non-nullable field #{@field_name}")
|
8
9
|
end
|
9
10
|
|
10
11
|
# @return [Hash] An entry for the response's "errors" key
|
11
12
|
def to_h
|
12
|
-
{
|
13
|
-
"message" => "Cannot return null for non-nullable field #{@field_name}"
|
14
|
-
}
|
13
|
+
{ "message" => message }
|
15
14
|
end
|
16
15
|
|
17
16
|
# @return [Boolean] Whether the null in question was caused by another error
|
data/lib/graphql/query.rb
CHANGED
@@ -63,30 +63,33 @@ module GraphQL
|
|
63
63
|
end
|
64
64
|
|
65
65
|
@arguments_cache = Hash.new { |h, k| h[k] = {} }
|
66
|
+
@validation_errors = []
|
67
|
+
@analysis_errors = []
|
68
|
+
@internal_representation = nil
|
69
|
+
@was_validated = false
|
66
70
|
end
|
67
71
|
|
68
72
|
# Get the result for this query, executing it once
|
69
73
|
def result
|
70
74
|
@result ||= begin
|
71
|
-
if
|
72
|
-
|
75
|
+
if !valid?
|
76
|
+
all_errors = validation_errors + analysis_errors
|
77
|
+
if all_errors.any?
|
78
|
+
{ "errors" => all_errors }
|
79
|
+
else
|
80
|
+
nil
|
81
|
+
end
|
73
82
|
else
|
74
83
|
Executor.new(self).result
|
75
84
|
end
|
76
85
|
end
|
77
|
-
|
78
86
|
end
|
79
87
|
|
80
88
|
|
81
89
|
# This is the operation to run for this query.
|
82
90
|
# If more than one operation is present, it must be named at runtime.
|
83
91
|
# @return [GraphQL::Language::Nodes::OperationDefinition, nil]
|
84
|
-
|
85
|
-
@selected_operation ||= begin
|
86
|
-
perform_validation
|
87
|
-
@selected_operation
|
88
|
-
end
|
89
|
-
end
|
92
|
+
attr_reader :selected_operation
|
90
93
|
|
91
94
|
# Determine the values for variables of this query, using default values
|
92
95
|
# if a value isn't provided at runtime.
|
@@ -101,18 +104,25 @@ module GraphQL
|
|
101
104
|
)
|
102
105
|
end
|
103
106
|
|
107
|
+
# @return [Hash<String, nil => GraphQL::InternalRepresentation::Node] Operation name -> Irep node pairs
|
104
108
|
def internal_representation
|
105
|
-
|
106
|
-
|
107
|
-
@internal_representation
|
108
|
-
end
|
109
|
+
valid?
|
110
|
+
@internal_representation
|
109
111
|
end
|
110
112
|
|
113
|
+
# TODO this should probably contain error instances, not hashes
|
114
|
+
# @return [Array<Hash>] Static validation errors for the query string
|
111
115
|
def validation_errors
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
valid?
|
117
|
+
@validation_errors
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
# TODO this should probably contain error instances, not hashes
|
122
|
+
# @return [Array<Hash>] Errors for this particular query run (eg, exceeds max complexity)
|
123
|
+
def analysis_errors
|
124
|
+
valid?
|
125
|
+
@analysis_errors
|
116
126
|
end
|
117
127
|
|
118
128
|
# Node-level cache for calculating arguments. Used during execution and query analysis.
|
@@ -127,24 +137,59 @@ module GraphQL
|
|
127
137
|
end
|
128
138
|
end
|
129
139
|
|
140
|
+
# @return [GraphQL::Language::Nodes::Document, nil]
|
141
|
+
def selected_operation
|
142
|
+
@selected_operation ||= find_operation(@operations, @operation_name)
|
143
|
+
end
|
144
|
+
|
145
|
+
def valid?
|
146
|
+
if !@was_validated
|
147
|
+
@was_validated = true
|
148
|
+
@valid = if @validate
|
149
|
+
document_valid? && query_possible? && query_valid?
|
150
|
+
else
|
151
|
+
true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
@valid
|
156
|
+
end
|
157
|
+
|
130
158
|
private
|
131
159
|
|
132
|
-
|
133
|
-
|
160
|
+
# Assert that the passed-in query string is internally consistent
|
161
|
+
def document_valid?
|
134
162
|
validation_result = schema.static_validator.validate(self)
|
135
163
|
@validation_errors = validation_result[:errors]
|
136
164
|
@internal_representation = validation_result[:irep]
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
165
|
+
@validation_errors.none?
|
166
|
+
end
|
167
|
+
|
168
|
+
# Given that the document is valid, do we have what we need to
|
169
|
+
# execute the document this time?
|
170
|
+
# - Is there an operation to run?
|
171
|
+
# - Are all variables accounted for?
|
172
|
+
def query_possible?
|
173
|
+
!selected_operation.nil? && variables
|
174
|
+
true
|
142
175
|
rescue GraphQL::Query::OperationNameMissingError, GraphQL::Query::VariableValidationError => err
|
143
|
-
@validation_errors
|
144
|
-
|
145
|
-
nil
|
176
|
+
@validation_errors << err.to_h
|
177
|
+
false
|
146
178
|
end
|
147
179
|
|
180
|
+
# Given that we _could_ execute this query, _should_ we?
|
181
|
+
# - Does it violate any query analyzers?
|
182
|
+
def query_valid?
|
183
|
+
@analysis_errors = begin
|
184
|
+
if @query_analyzers.any?
|
185
|
+
reduce_results = GraphQL::Analysis.analyze_query(self, @query_analyzers)
|
186
|
+
reduce_results.select { |r| r.is_a?(GraphQL::AnalysisError) }.map(&:to_h)
|
187
|
+
else
|
188
|
+
[]
|
189
|
+
end
|
190
|
+
end
|
191
|
+
@analysis_errors.none?
|
192
|
+
end
|
148
193
|
|
149
194
|
def find_operation(operations, operation_name)
|
150
195
|
if operations.length == 1
|
@@ -157,19 +202,5 @@ module GraphQL
|
|
157
202
|
operations[operation_name]
|
158
203
|
end
|
159
204
|
end
|
160
|
-
|
161
|
-
def analysis_errors
|
162
|
-
@analysis_errors ||= begin
|
163
|
-
if validation_errors.any?
|
164
|
-
# Can't reduce an invalid query
|
165
|
-
[]
|
166
|
-
elsif @query_analyzers.any?
|
167
|
-
reduce_results = GraphQL::Analysis.analyze_query(self, @query_analyzers)
|
168
|
-
reduce_results.select { |r| r.is_a?(GraphQL::AnalysisError) }.map(&:to_h)
|
169
|
-
else
|
170
|
-
[]
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
205
|
end
|
175
206
|
end
|
data/lib/graphql/version.rb
CHANGED
@@ -30,4 +30,14 @@ describe GraphQL::StaticValidation::FragmentsAreUsed do
|
|
30
30
|
"path"=>["query getCheese", "... undefinedFields"]
|
31
31
|
})
|
32
32
|
end
|
33
|
+
|
34
|
+
describe "queries that are comments" do
|
35
|
+
let(:query_string) {%|
|
36
|
+
# I am a comment.
|
37
|
+
|}
|
38
|
+
let(:result) { DummySchema.execute(query_string) }
|
39
|
+
it "handles them gracefully" do
|
40
|
+
assert_equal({}, result)
|
41
|
+
end
|
42
|
+
end
|
33
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|