tinygql 0.1.1 → 0.1.3

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.
@@ -115,12 +115,13 @@ nodes:
115
115
 
116
116
  - name: SchemaDefinition
117
117
  fields:
118
+ - description?
118
119
  - directives?: list
119
120
  - root_operation_definitions: list
120
121
 
121
122
  - name: FieldDefinition
122
123
  fields:
123
- - description?: literal
124
+ - description?
124
125
  - name: literal
125
126
  - arguments_definition?: list
126
127
  - type
@@ -128,7 +129,7 @@ nodes:
128
129
 
129
130
  - name: InputValueDefinition
130
131
  fields:
131
- - description?: literal
132
+ - description?
132
133
  - name: literal
133
134
  - type
134
135
  - default_value?
@@ -136,7 +137,7 @@ nodes:
136
137
 
137
138
  - name: ObjectTypeDefinition
138
139
  fields:
139
- - description?: literal
140
+ - description?
140
141
  - name: literal
141
142
  - implements_interfaces?: list
142
143
  - directives?: list
@@ -144,40 +145,40 @@ nodes:
144
145
 
145
146
  - name: InterfaceTypeDefinition
146
147
  fields:
147
- - description?: literal
148
+ - description?
148
149
  - name: literal
149
150
  - directives?: list
150
151
  - fields_definition?: list
151
152
 
152
153
  - name: UnionTypeDefinition
153
154
  fields:
154
- - description?: literal
155
+ - description?
155
156
  - name: literal
156
157
  - directives?: list
157
158
  - union_member_types?: list
158
159
 
159
160
  - name: ScalarTypeDefinition
160
161
  fields:
161
- - description?: literal
162
+ - description?
162
163
  - name: literal
163
164
  - directives?: list
164
165
 
165
166
  - name: EnumValueDefinition
166
167
  fields:
167
- - description?: literal
168
+ - description?
168
169
  - enum_value
169
170
  - directives?: list
170
171
 
171
172
  - name: EnumTypeDefinition
172
173
  fields:
173
- - description?: literal
174
+ - description?
174
175
  - name: literal
175
176
  - directives?: list
176
177
  - enum_value_definition?: list
177
178
 
178
179
  - name: InputObjectTypeDefinition
179
180
  fields:
180
- - description?: literal
181
+ - description?
181
182
  - name: literal
182
183
  - directives?: list
183
184
  - input_fields_definition?: list
@@ -199,7 +200,7 @@ nodes:
199
200
 
200
201
  - name: DirectiveDefinition
201
202
  fields:
202
- - description?: literal
203
+ - description?
203
204
  - name: literal
204
205
  - arguments_definition?: list
205
206
  - directive_locations: list
@@ -7,7 +7,9 @@ module TinyGQL
7
7
  class Parser
8
8
  class UnexpectedToken < StandardError; end
9
9
 
10
- attr_reader :token_name
10
+ def self.parse doc
11
+ new(doc).parse
12
+ end
11
13
 
12
14
  def initialize doc
13
15
  @lexer = Lexer.new doc
@@ -21,6 +23,8 @@ module TinyGQL
21
23
 
22
24
  private
23
25
 
26
+ attr_reader :token_name
27
+
24
28
  def document
25
29
  Nodes::Document.new definition_list
26
30
  end
@@ -40,7 +44,9 @@ module TinyGQL
40
44
  when :EXTEND
41
45
  type_system_extension
42
46
  else
43
- type_system_definition
47
+ desc = if at?(:STRING); string_value; end
48
+
49
+ type_system_definition desc
44
50
  end
45
51
  end
46
52
 
@@ -62,12 +68,12 @@ module TinyGQL
62
68
  Nodes::ObjectTypeExtension.new(name, implements_interfaces, directives, fields_definition)
63
69
  end
64
70
 
65
- def type_system_definition
71
+ def type_system_definition desc
66
72
  case token_name
67
- when :SCHEMA then schema_definition
68
- when :DIRECTIVE then directive_defintion(nil)
73
+ when :SCHEMA then schema_definition(desc)
74
+ when :DIRECTIVE then directive_defintion(desc)
69
75
  else
70
- type_definition(nil)
76
+ type_definition(desc)
71
77
  end
72
78
  end
73
79
 
@@ -91,9 +97,11 @@ module TinyGQL
91
97
  end
92
98
 
93
99
  def directive_location
94
- case token_name
100
+ directive = expect_token_value :IDENTIFIER
101
+
102
+ case directive
95
103
  when "QUERY", "MUTATION", "SUBSCRIPTION", "FIELD", "FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"
96
- Nodes::ExecutableDirectiveLocation.new(accept_token_value)
104
+ Nodes::ExecutableDirectiveLocation.new(directive)
97
105
  when "SCHEMA",
98
106
  "SCALAR",
99
107
  "OBJECT",
@@ -105,9 +113,9 @@ module TinyGQL
105
113
  "ENUM_VALUE",
106
114
  "INPUT_OBJECT",
107
115
  "INPUT_FIELD_DEFINITION"
108
- Nodes::TypeSystemDirectiveLocation.new(accept_token_value)
116
+ Nodes::TypeSystemDirectiveLocation.new(directive)
109
117
  else
110
- expect_token(:IDENTIFIER); nil # error
118
+ raise UnexpectedToken, "Expected directive #{directive}"
111
119
  end
112
120
  end
113
121
 
@@ -161,7 +169,7 @@ module TinyGQL
161
169
  end
162
170
 
163
171
  def enum_value_definition
164
- description = if at?(:STRING); accept_token_value; end
172
+ description = if at?(:STRING); string_value; end
165
173
  enum_value = self.enum_value
166
174
  directives = if at?(:DIR_SIGN); self.directives; end
167
175
  Nodes::EnumValueDefinition.new(description, enum_value, directives)
@@ -221,7 +229,7 @@ module TinyGQL
221
229
  end
222
230
 
223
231
  def field_definition
224
- description = if at?(:STRING); accept_token_value; end
232
+ description = if at?(:STRING); string_value; end
225
233
  name = self.name
226
234
  arguments_definition = if at?(:LPAREN); self.arguments_definition; end
227
235
  expect_token :COLON
@@ -242,7 +250,7 @@ module TinyGQL
242
250
  end
243
251
 
244
252
  def input_value_definition
245
- description = if at?(:STRING); accept_token_value; end
253
+ description = if at?(:STRING); string_value; end
246
254
  name = self.name
247
255
  expect_token :COLON
248
256
  type = self.type
@@ -262,14 +270,14 @@ module TinyGQL
262
270
  list
263
271
  end
264
272
 
265
- def schema_definition
273
+ def schema_definition desc
266
274
  expect_token :SCHEMA
267
275
 
268
276
  directives = if at?(:DIR_SIGN); self.directives; end
269
277
  expect_token :LCURLY
270
278
  defs = root_operation_type_definition
271
279
  expect_token :RCURLY
272
- Nodes::SchemaDefinition.new(directives, defs)
280
+ Nodes::SchemaDefinition.new(desc, directives, defs)
273
281
  end
274
282
 
275
283
  def root_operation_type_definition
@@ -1,3 +1,3 @@
1
1
  module TinyGQL
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end