graphql-parser 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ParserTest < Minitest::Test
4
+
5
+ # example fragments borrowed from https://github.com/graphql/libgraphqlparser/blob/master/test/ParserTests.cpp
6
+
7
+ def test_that_parsing_returns_an_ast
8
+ expect_parse_success('{ field }')
9
+ expect_parse_success('{ field(complex: { a: { b: [ $var ] } }) }')
10
+ end
11
+
12
+ def test_parse_error
13
+ expect_parse_error('{')
14
+ expect_parse_error('query myquery on type { field }')
15
+ expect_parse_error('query myquery { field };')
16
+ expect_parse_error("{ ...MissingOn }\nfragment MissingOn Type")
17
+ expect_parse_error('{ field: {} }')
18
+ expect_parse_error('notanoperation Foo { field }')
19
+ expect_parse_error('...')
20
+ expect_parse_error('query Foo($x: Complex = {a:{b:[ $var ] } }) { field }')
21
+ expect_parse_error('fragment on on on { on }')
22
+ expect_parse_error('{ ...on }')
23
+ expect_parse_error('{ fieldWithNullableStringInput(input: null) }')
24
+ end
25
+
26
+ private
27
+
28
+ def expect_parse_error(input)
29
+ assert_raises(GraphQL::ParseError) do
30
+ GraphQL::Parser.parse(input)
31
+ end
32
+ end
33
+
34
+ def expect_parse_success(input)
35
+ assert_equal GraphQL::AST, GraphQL::Parser.parse(input).class
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ gem 'minitest'
2
+ require 'minitest/autorun'
3
+
4
+ require 'graphql/parser'
@@ -0,0 +1,86 @@
1
+ require_relative 'test_helper'
2
+
3
+ class VisitorTest < Minitest::Test
4
+ class NameVisitor < GraphQL::Visitor
5
+ attr_accessor :nodes
6
+
7
+ def initialize
8
+ @nodes = []
9
+ end
10
+
11
+ def method_missing(name, node)
12
+ @nodes << name
13
+ end
14
+ end
15
+
16
+ def test_visiting_basic_query
17
+ v = NameVisitor.new
18
+ v.accept(GraphQL::Parser.parse('{ field }'))
19
+ assert_equal [
20
+ :visit_document,
21
+ :visit_operation_definition,
22
+ :visit_selection_set,
23
+ :visit_field,
24
+ :visit_name,
25
+ :end_visit_name,
26
+ :end_visit_field,
27
+ :end_visit_selection_set,
28
+ :end_visit_operation_definition,
29
+ :end_visit_document
30
+ ], v.nodes
31
+ end
32
+
33
+ class SkipChildrenVisitor < GraphQL::Visitor
34
+ def visit_document(node)
35
+ @nodes << :visit_document
36
+ GraphQL::SKIP_CHILDREN
37
+ end
38
+ end
39
+
40
+ def test_skip_children
41
+ v = SkipChildrenVisitor.new
42
+ v.accept(GraphQL::Parser.parse('{ field }'))
43
+ assert_equal [
44
+ :visit_document,
45
+ :end_visit_document
46
+ ], v.nodes
47
+ end
48
+
49
+ class NodeVisitor < GraphQL::Visitor
50
+ attr_accessor :nodes
51
+
52
+ def initialize
53
+ @nodes = []
54
+ end
55
+
56
+ def method_missing(name, node)
57
+ @nodes << node
58
+ end
59
+ end
60
+
61
+ def test_skip_children
62
+ v = NodeVisitor.new
63
+ v.accept(GraphQL::Parser.parse('{ field }'))
64
+
65
+ assert_equal GraphQL::Document, v.nodes[0].class
66
+ assert_equal 1, v.nodes[0].definitions_size
67
+
68
+ assert_equal GraphQL::OperationDefinition, v.nodes[1].class
69
+ assert_equal 'query', v.nodes[1].operation
70
+ assert_nil v.nodes[1].name
71
+ assert_equal GraphQL::SelectionSet, v.nodes[1].selection_set.class
72
+ assert_equal 0, v.nodes[1].variable_definitions_size
73
+ assert_equal 0, v.nodes[1].directives_size
74
+
75
+ assert_equal GraphQL::SelectionSet, v.nodes[2].class
76
+ assert_equal 1, v.nodes[2].selections_size
77
+
78
+ assert_equal GraphQL::Field, v.nodes[3].class
79
+ assert_nil v.nodes[3].alias
80
+ assert_equal GraphQL::Name, v.nodes[3].name.class
81
+ assert_equal 'field', v.nodes[3].name.value
82
+
83
+ assert_equal GraphQL::Name, v.nodes[4].class
84
+ assert_equal 'field', v.nodes[4].value
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphql-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Evan Huus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.8'
69
+ description:
70
+ email:
71
+ - evan.huus@shopify.com
72
+ executables: []
73
+ extensions:
74
+ - ext/graphql_parser/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".gitmodules"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - ext/graphql_parser/extconf.rb
84
+ - ext/graphql_parser/graphql_parser.c
85
+ - ext/graphql_parser/graphql_ruby.c
86
+ - ext/graphql_parser/graphql_ruby.h
87
+ - graphql-parser.gemspec
88
+ - lib/graphql/parser.rb
89
+ - lib/graphql/parser/version.rb
90
+ - lib/graphql/visitor.rb
91
+ - script/generate
92
+ - script/ruby_header_gen.py
93
+ - script/ruby_impl_gen.py
94
+ - test/parser_test.rb
95
+ - test/test_helper.rb
96
+ - test/visitor_test.rb
97
+ homepage: https://github.com/Shopify/graphql-parser
98
+ licenses:
99
+ - BSD-3-Clause
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Ruby bindings for Facebook's libgraphqlparser.
121
+ test_files:
122
+ - test/parser_test.rb
123
+ - test/test_helper.rb
124
+ - test/visitor_test.rb