graphql 2.0.26 → 2.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/graphql/relay.rb +18 -1
- data/lib/graphql/language/lexer.rb +86 -56
- data/lib/graphql/language/parser.rb +706 -691
- data/lib/graphql/language/parser.y +1 -0
- data/lib/graphql/schema/addition.rb +6 -0
- data/lib/graphql/schema/field.rb +1 -1
- data/lib/graphql/schema/resolver.rb +10 -8
- data/lib/graphql/schema/validator.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62749a86dd0b2913ebcb9a8be343d7f0eb7199f1e301bc6b584227ddfa6bdec
|
4
|
+
data.tar.gz: d9de79c247f14d316741a66162c3ff96d5621dd689ab837f488277d53701d66d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11adf0c6bf4279b840b2b5ba1627ec11f4cca4d08957faac1956b261d01b914e7f8c9cc9a737c4ce02fb404bb3abac1904c9fe74255ecf367b7b88dc64133fcf
|
7
|
+
data.tar.gz: b04cfe4e331da788f7c5706671e53fd2f0bfae680da896198a3d127922f6b92609cd6f720e98d7d2fb03cdea532b5a4f1536fd1bd6e154c5beb98b010dcedce5
|
@@ -6,7 +6,24 @@ module Graphql
|
|
6
6
|
# Add Node, `node(id:)`, and `nodes(ids:)`
|
7
7
|
template("node_type.erb", "#{options[:directory]}/types/node_type.rb")
|
8
8
|
in_root do
|
9
|
-
fields =
|
9
|
+
fields = <<-RUBY
|
10
|
+
field :node, Types::NodeType, null: true, description: "Fetches an object given its ID." do
|
11
|
+
argument :id, ID, required: true, description: "ID of the object."
|
12
|
+
end
|
13
|
+
|
14
|
+
def node(id:)
|
15
|
+
context.schema.object_from_id(id, context)
|
16
|
+
end
|
17
|
+
|
18
|
+
field :nodes, [Types::NodeType, null: true], null: true, description: "Fetches a list of objects given a list of IDs." do
|
19
|
+
argument :ids, [ID], required: true, description: "IDs of the objects."
|
20
|
+
end
|
21
|
+
|
22
|
+
def nodes(ids:)
|
23
|
+
ids.map { |id| context.schema.object_from_id(id, context) }
|
24
|
+
end
|
25
|
+
|
26
|
+
RUBY
|
10
27
|
inject_into_file "#{options[:directory]}/types/query_type.rb", fields, after: /class .*QueryType\s*<\s*[^\s]+?\n/m, force: false
|
11
28
|
end
|
12
29
|
|
@@ -4,7 +4,7 @@ require "strscan"
|
|
4
4
|
|
5
5
|
module GraphQL
|
6
6
|
module Language
|
7
|
-
|
7
|
+
class Lexer
|
8
8
|
IDENTIFIER = /[_A-Za-z][_0-9A-Za-z]*/
|
9
9
|
NEWLINE = /[\c\r\n]/
|
10
10
|
BLANK = /[, \t]+/
|
@@ -87,60 +87,81 @@ module GraphQL
|
|
87
87
|
# # catch-all for anything else. must be at the bottom for precedence.
|
88
88
|
UNKNOWN_CHAR = /./
|
89
89
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
tokens: [],
|
95
|
-
previous_token: nil,
|
96
|
-
}
|
90
|
+
def initialize(value)
|
91
|
+
@line = 1
|
92
|
+
@col = 1
|
93
|
+
@previous_token = nil
|
97
94
|
|
95
|
+
@scan = scanner value
|
96
|
+
end
|
97
|
+
|
98
|
+
class BadEncoding < Lexer # :nodoc:
|
99
|
+
def scanner(value)
|
100
|
+
[emit(:BAD_UNICODE_ESCAPE, 0, 0, value)]
|
101
|
+
end
|
102
|
+
|
103
|
+
def next_token
|
104
|
+
@scan.pop
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.tokenize(string)
|
98
109
|
value = string.dup.force_encoding(Encoding::UTF_8)
|
99
110
|
|
100
|
-
|
101
|
-
|
102
|
-
|
111
|
+
scanner = if value.valid_encoding?
|
112
|
+
new value
|
113
|
+
else
|
114
|
+
BadEncoding.new value
|
103
115
|
end
|
104
116
|
|
105
|
-
|
106
|
-
|
107
|
-
while
|
108
|
-
|
109
|
-
|
110
|
-
case
|
111
|
-
when str = scan.scan(FLOAT) then emit(:FLOAT, pos, scan.pos, meta, str)
|
112
|
-
when str = scan.scan(INT) then emit(:INT, pos, scan.pos, meta, str)
|
113
|
-
when str = scan.scan(LIT) then emit(LIT_NAME_LUT[str], pos, scan.pos, meta, -str)
|
114
|
-
when str = scan.scan(IDENTIFIER) then emit(:IDENTIFIER, pos, scan.pos, meta, str)
|
115
|
-
when str = scan.scan(BLOCK_STRING) then emit_block(pos, scan.pos, meta, str.gsub(/^#{BLOCK_QUOTE}|#{BLOCK_QUOTE}$/, ''))
|
116
|
-
when str = scan.scan(QUOTED_STRING) then emit_string(pos, scan.pos, meta, str.gsub(/^"|"$/, ''))
|
117
|
-
when str = scan.scan(COMMENT) then record_comment(pos, scan.pos, meta, str)
|
118
|
-
when str = scan.scan(NEWLINE)
|
119
|
-
meta[:line] += 1
|
120
|
-
meta[:col] = 1
|
121
|
-
when scan.scan(BLANK)
|
122
|
-
meta[:col] += scan.pos - pos
|
123
|
-
when str = scan.scan(UNKNOWN_CHAR) then emit(:UNKNOWN_CHAR, pos, scan.pos, meta, str)
|
124
|
-
else
|
125
|
-
# This should never happen since `UNKNOWN_CHAR` ensures we make progress
|
126
|
-
raise "Unknown string?"
|
127
|
-
end
|
117
|
+
toks = []
|
118
|
+
|
119
|
+
while tok = scanner.next_token
|
120
|
+
toks << tok
|
128
121
|
end
|
129
122
|
|
130
|
-
|
123
|
+
toks
|
124
|
+
end
|
125
|
+
|
126
|
+
def next_token
|
127
|
+
return if @scan.eos?
|
128
|
+
|
129
|
+
pos = @scan.pos
|
130
|
+
|
131
|
+
case
|
132
|
+
when str = @scan.scan(FLOAT) then emit(:FLOAT, pos, @scan.pos, str)
|
133
|
+
when str = @scan.scan(INT) then emit(:INT, pos, @scan.pos, str)
|
134
|
+
when str = @scan.scan(LIT) then emit(LIT_NAME_LUT[str], pos, @scan.pos, -str)
|
135
|
+
when str = @scan.scan(IDENTIFIER) then emit(:IDENTIFIER, pos, @scan.pos, str)
|
136
|
+
when str = @scan.scan(BLOCK_STRING) then emit_block(pos, @scan.pos, str.gsub(/\A#{BLOCK_QUOTE}|#{BLOCK_QUOTE}\z/, ''))
|
137
|
+
when str = @scan.scan(QUOTED_STRING) then emit_string(pos, @scan.pos, str.gsub(/^"|"$/, ''))
|
138
|
+
when str = @scan.scan(COMMENT) then record_comment(pos, @scan.pos, str)
|
139
|
+
when str = @scan.scan(NEWLINE)
|
140
|
+
@line += 1
|
141
|
+
@col = 1
|
142
|
+
next_token
|
143
|
+
when @scan.scan(BLANK)
|
144
|
+
@col += @scan.pos - pos
|
145
|
+
next_token
|
146
|
+
when str = @scan.scan(UNKNOWN_CHAR) then emit(:UNKNOWN_CHAR, pos, @scan.pos, str)
|
147
|
+
else
|
148
|
+
# This should never happen since `UNKNOWN_CHAR` ensures we make progress
|
149
|
+
raise "Unknown string?"
|
150
|
+
end
|
131
151
|
end
|
132
152
|
|
133
|
-
def
|
134
|
-
|
153
|
+
def emit(token_name, ts, te, token_value)
|
154
|
+
token = [
|
135
155
|
token_name,
|
136
|
-
|
137
|
-
|
156
|
+
@line,
|
157
|
+
@col,
|
138
158
|
token_value,
|
139
|
-
|
159
|
+
@previous_token,
|
140
160
|
]
|
141
|
-
|
161
|
+
@previous_token = token
|
142
162
|
# Bump the column counter for the next token
|
143
|
-
|
163
|
+
@col += te - ts
|
164
|
+
token
|
144
165
|
end
|
145
166
|
|
146
167
|
# Replace any escaped unicode or whitespace with the _actual_ characters
|
@@ -169,18 +190,19 @@ module GraphQL
|
|
169
190
|
nil
|
170
191
|
end
|
171
192
|
|
172
|
-
def
|
193
|
+
def record_comment(ts, te, str)
|
173
194
|
token = [
|
174
195
|
:COMMENT,
|
175
|
-
|
176
|
-
|
196
|
+
@line,
|
197
|
+
@col,
|
177
198
|
str,
|
178
|
-
|
199
|
+
@previous_token,
|
179
200
|
]
|
180
201
|
|
181
|
-
|
202
|
+
@previous_token = token
|
182
203
|
|
183
|
-
|
204
|
+
@col += te - ts
|
205
|
+
next_token
|
184
206
|
end
|
185
207
|
|
186
208
|
ESCAPES = /\\["\\\/bfnrt]/
|
@@ -197,26 +219,34 @@ module GraphQL
|
|
197
219
|
UTF_8 = /\\u(?:([\dAa-f]{4})|\{([\da-f]{4,})\})(?:\\u([\dAa-f]{4}))?/i
|
198
220
|
VALID_STRING = /\A(?:[^\\]|#{ESCAPES}|#{UTF_8})*\z/o
|
199
221
|
|
200
|
-
def
|
222
|
+
def emit_block(ts, te, value)
|
201
223
|
line_incr = value.count("\n")
|
202
224
|
value = GraphQL::Language::BlockString.trim_whitespace(value)
|
203
|
-
emit_string(ts, te,
|
204
|
-
|
225
|
+
tok = emit_string(ts, te, value)
|
226
|
+
@line += line_incr
|
227
|
+
tok
|
205
228
|
end
|
206
229
|
|
207
|
-
def
|
230
|
+
def emit_string(ts, te, value)
|
208
231
|
if !value.valid_encoding? || !value.match?(VALID_STRING)
|
209
|
-
emit(:BAD_UNICODE_ESCAPE, ts, te,
|
232
|
+
emit(:BAD_UNICODE_ESCAPE, ts, te, value)
|
210
233
|
else
|
211
|
-
replace_escaped_characters_in_place(value)
|
234
|
+
self.class.replace_escaped_characters_in_place(value)
|
212
235
|
|
213
236
|
if !value.valid_encoding?
|
214
|
-
emit(:BAD_UNICODE_ESCAPE, ts, te,
|
237
|
+
emit(:BAD_UNICODE_ESCAPE, ts, te, value)
|
215
238
|
else
|
216
|
-
emit(:STRING, ts, te,
|
239
|
+
emit(:STRING, ts, te, value)
|
217
240
|
end
|
218
241
|
end
|
219
242
|
end
|
243
|
+
|
244
|
+
private
|
245
|
+
|
246
|
+
def scanner(value)
|
247
|
+
StringScanner.new value
|
248
|
+
end
|
249
|
+
|
220
250
|
end
|
221
251
|
end
|
222
252
|
end
|