graphql-libgraphqlparser 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 991f9f625b2275609b07eab64c3002d1579f511e
4
- data.tar.gz: 0f282d13ab730c8a061ae5f14a748e2c9232a7fc
3
+ metadata.gz: 7c6c3d2f3e3f782d3c576ed544599fb743e8cf12
4
+ data.tar.gz: dc13fc9f17377d35a9b9fdec26ab00064d4e47da
5
5
  SHA512:
6
- metadata.gz: d40cf6b525e4afc651f97f868c120241c8cb507b194192e9a80c55e387a18416c81f79933ce290906d4ee4f86839fbf64e36131e9f5a74fcfae9486b9fb423bc
7
- data.tar.gz: ae7882681347d4da3d8c82fc4c7947226ddfc0d23b995e858cbfe6e10030d46964771a3782db4600514c34399b5fcca2c8cab42553f3463cf5e26f8e4cbdb44d
6
+ metadata.gz: c4bff9e47683edfad5bf7ea6005ccf4ce694c6bf53b36ef3ac821b398cf5714851967eb56b400d463329f70f6eda4bd81c8e94ba2572ccb8bf559377101700a3
7
+ data.tar.gz: bda7eb33bb87c80152fc9f195359de73ec106866948264bbe960d183e1771200c0e6be6fea157be5dde5b85d21a0627ab8cf397b665d38f20f027dd74b0d2ee3
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ # 1.2.0
4
+
5
+ - Support `tracer:` keyword to `.parse` (supports GraphQL::Tracing) #27
6
+
3
7
  # 1.1.0
4
8
 
5
9
  - Support `null`
@@ -6,40 +6,42 @@ require_relative '../graphql_libgraphqlparser_ext'
6
6
 
7
7
  module GraphQL
8
8
  module Libgraphqlparser
9
- def self.parse(string)
10
- begin
11
- builder = builder_parse(string)
12
- builder.document
13
- rescue ArgumentError
14
- if index = string.index("\x00")
15
- string_before_null = string.slice(0, index)
16
- line = string_before_null.count("\n") + 1
17
- col = index - (string_before_null.rindex("\n") || 0)
18
- raise GraphQL::ParseError.new("Invalid null byte in query", line, col, string)
19
- end
20
- raise
21
- rescue ParseError => e
22
- error_message = e.message.match(/(\d+)\.(\d+): (.*)/)
23
- if error_message
24
- line = error_message[1].to_i
25
- col = error_message[2].to_i
26
- raise GraphQL::ParseError.new(error_message[3], line, col, string)
27
- else
28
- raise GraphQL::ParseError.new(e.message, nil, nil, string)
9
+ def self.parse(string, tracer: GraphQL::Tracing::NullTracer)
10
+ tracer.trace("parse", { query_string: string }) do
11
+ begin
12
+ builder = builder_parse(string)
13
+ builder.document
14
+ rescue ArgumentError
15
+ if index = string.index("\x00")
16
+ string_before_null = string.slice(0, index)
17
+ line = string_before_null.count("\n") + 1
18
+ col = index - (string_before_null.rindex("\n") || 0)
19
+ raise GraphQL::ParseError.new("Invalid null byte in query", line, col, string)
20
+ end
21
+ raise
22
+ rescue ParseError => e
23
+ error_message = e.message.match(/(\d+)\.(\d+): (.*)/)
24
+ if error_message
25
+ line = error_message[1].to_i
26
+ col = error_message[2].to_i
27
+ raise GraphQL::ParseError.new(error_message[3], line, col, string)
28
+ else
29
+ raise GraphQL::ParseError.new(e.message, nil, nil, string)
30
+ end
29
31
  end
30
32
  end
31
33
  end
32
34
  end
33
35
 
34
36
  class << self
35
- def parse_with_libgraphqlparser(string)
36
- Libgraphqlparser.parse(string)
37
+ def parse_with_libgraphqlparser(*args)
38
+ Libgraphqlparser.parse(*args)
37
39
  end
38
40
 
39
41
  alias :parse_without_libgraphqlparser :parse
40
42
 
41
- def parse(string, as: nil)
42
- parse_with_libgraphqlparser(string)
43
+ def parse(*args)
44
+ parse_with_libgraphqlparser(*args)
43
45
  end
44
46
  end
45
47
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Libgraphqlparser
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -159,7 +159,7 @@ describe GraphQL::Libgraphqlparser do
159
159
  let(:query_string) { 'query { ... @skip(if: false) { field } }' }
160
160
  let(:inline_fragment) { query.selections[0] }
161
161
  it "gets directives and nil type" do
162
- assert_equal nil, inline_fragment.type
162
+ assert_nil inline_fragment.type
163
163
  assert_equal 1, inline_fragment.directives.length
164
164
  end
165
165
  end
@@ -227,7 +227,7 @@ describe GraphQL::Libgraphqlparser do
227
227
  it "parses unnamed queries" do
228
228
  assert_equal 1, document.definitions.length
229
229
  assert_equal "query", operation.operation_type
230
- assert_equal nil, operation.name
230
+ assert_nil operation.name
231
231
  assert_equal 3, operation.selections.length
232
232
  end
233
233
  end
@@ -264,4 +264,20 @@ describe GraphQL::Libgraphqlparser do
264
264
  assert_equal 28, err.col
265
265
  end
266
266
  end
267
+
268
+ describe "Compatibility" do
269
+ TestQuery = GraphQL::ObjectType.define do
270
+ name "Query"
271
+ field :int, !types.Int, resolve: ->(*a) { 1 }
272
+ end
273
+
274
+ TestSchema = GraphQL::Schema.define do
275
+ query(TestQuery)
276
+ end
277
+
278
+ it "works with a schema" do
279
+ res = TestSchema.execute("{ int }")
280
+ assert_equal 1, res["data"]["int"]
281
+ end
282
+ end
267
283
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-libgraphqlparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Mosolgo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  requirements: []
215
215
  rubyforge_project:
216
- rubygems_version: 2.5.2
216
+ rubygems_version: 2.6.13
217
217
  signing_key:
218
218
  specification_version: 4
219
219
  summary: Use Libgraphqlparser to parse queries for the GraphQL gem