gql 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/gql.gemspec +1 -1
- data/lib/gql.rb +2 -2
- data/lib/gql/array.rb +3 -11
- data/lib/gql/call.rb +16 -49
- data/lib/gql/config.rb +1 -1
- data/lib/gql/connection.rb +5 -20
- data/lib/gql/executor.rb +5 -5
- data/lib/gql/field.rb +3 -15
- data/lib/gql/node.rb +91 -32
- data/lib/gql/number.rb +1 -1
- data/lib/gql/object.rb +3 -9
- data/lib/gql/parser.rb +206 -193
- data/lib/gql/parser.y +31 -11
- data/lib/gql/schema/call.rb +4 -12
- data/lib/gql/schema/field.rb +4 -12
- data/lib/gql/schema/node.rb +3 -11
- data/lib/gql/schema/parameter.rb +4 -6
- data/lib/gql/string.rb +3 -3
- data/lib/gql/version.rb +1 -1
- metadata +3 -4
data/lib/gql/parser.y
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
class GQL::Parser
|
2
2
|
token STRING NUMBER TRUE FALSE NULL AS IDENT
|
3
3
|
rule
|
4
|
-
|
5
|
-
: variables
|
6
|
-
| variables { result = Root.new(Node.new(nil, nil), val[0] ) }
|
4
|
+
query
|
5
|
+
: variables root variables { result = Query.new(val[1], val[0].merge(val[2])) }
|
7
6
|
;
|
8
7
|
|
9
|
-
|
10
|
-
: call
|
11
|
-
|
|
8
|
+
root
|
9
|
+
: call { result = Field.new(nil, nil, val[0], nil ) }
|
10
|
+
| '{' field_list '}' { result = Field.new(nil, nil, nil, val[1]) }
|
12
11
|
;
|
13
12
|
|
14
13
|
call
|
@@ -126,21 +125,42 @@ end
|
|
126
125
|
|
127
126
|
---- header
|
128
127
|
|
129
|
-
require 'json'
|
128
|
+
require 'active_support/json'
|
130
129
|
require 'active_support/core_ext/object/blank'
|
130
|
+
require 'active_support/core_ext/object/try'
|
131
|
+
require 'active_support/core_ext/object/json'
|
131
132
|
|
132
133
|
---- inner
|
133
134
|
|
134
|
-
class
|
135
|
-
|
136
|
-
|
137
|
-
|
135
|
+
class Query < Struct.new(:root, :variables)
|
136
|
+
def as_json(*)
|
137
|
+
{
|
138
|
+
root: root.as_json,
|
139
|
+
variables: variables
|
140
|
+
}
|
141
|
+
end
|
138
142
|
end
|
139
143
|
|
140
144
|
class Field < Struct.new(:id, :alias_id, :call, :fields)
|
145
|
+
def as_json(*)
|
146
|
+
{
|
147
|
+
id: id,
|
148
|
+
alias_id: alias_id,
|
149
|
+
call: call.as_json,
|
150
|
+
fields: fields.as_json
|
151
|
+
}
|
152
|
+
end
|
141
153
|
end
|
142
154
|
|
143
155
|
class Call < Struct.new(:id, :arguments, :call, :fields)
|
156
|
+
def as_json(*)
|
157
|
+
{
|
158
|
+
id: id,
|
159
|
+
arguments: arguments,
|
160
|
+
call: call.as_json,
|
161
|
+
fields: fields.as_json
|
162
|
+
}
|
163
|
+
end
|
144
164
|
end
|
145
165
|
|
146
166
|
UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
|
data/lib/gql/schema/call.rb
CHANGED
@@ -2,19 +2,11 @@ module GQL
|
|
2
2
|
module Schema
|
3
3
|
class Call < GQL::Node
|
4
4
|
cursor :id
|
5
|
-
string :id
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
string :type do
|
12
|
-
target.name
|
13
|
-
end
|
14
|
-
|
15
|
-
object :result_class, :node_class => Node do
|
16
|
-
target.result_class || Placeholder
|
17
|
-
end
|
6
|
+
string :id
|
7
|
+
string :type, -> { target.name }
|
8
|
+
array :parameters, -> { target.method.parameters }, item_class: Parameter
|
9
|
+
object :result_class, -> { target.result_class || Placeholder }, node_class: Node
|
18
10
|
end
|
19
11
|
end
|
20
12
|
end
|
data/lib/gql/schema/field.rb
CHANGED
@@ -2,19 +2,11 @@ module GQL
|
|
2
2
|
module Schema
|
3
3
|
class Field < GQL::Node
|
4
4
|
cursor :id
|
5
|
-
string :id
|
6
5
|
|
7
|
-
string
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
connection :calls, :list_class => List, :item_class => Call do
|
12
|
-
target.calls.values
|
13
|
-
end
|
14
|
-
|
15
|
-
connection :fields, :list_class => List, :item_class => Field do
|
16
|
-
target.fields.values
|
17
|
-
end
|
6
|
+
string :id
|
7
|
+
string :type, -> { target.name }
|
8
|
+
connection :calls, -> { target.calls.values }, list_class: List, item_class: Call
|
9
|
+
connection :fields, -> { target.fields.values }, list_class: List, item_class: Field
|
18
10
|
end
|
19
11
|
end
|
20
12
|
end
|
data/lib/gql/schema/node.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
module GQL
|
2
2
|
module Schema
|
3
3
|
class Node < GQL::Node
|
4
|
-
string
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
connection :calls, :list_class => List, :item_class => Call do
|
9
|
-
target.calls.values
|
10
|
-
end
|
11
|
-
|
12
|
-
connection :fields, :list_class => List, :item_class => Field do
|
13
|
-
target.fields.values
|
14
|
-
end
|
4
|
+
string :type, -> { target.name }
|
5
|
+
connection :calls, -> { target.calls.values }, list_class: List, item_class: Call
|
6
|
+
connection :fields, -> { target.fields.values }, list_class: List, item_class: Field
|
15
7
|
end
|
16
8
|
end
|
17
9
|
end
|
data/lib/gql/schema/parameter.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module GQL
|
2
2
|
module Schema
|
3
3
|
class Parameter < GQL::Node
|
4
|
-
cursor { target[1].to_s }
|
4
|
+
cursor -> { target[1].to_s }
|
5
5
|
|
6
|
-
string :id
|
7
|
-
target[1].to_s
|
8
|
-
end
|
6
|
+
string :id, -> { target[1].to_s }
|
9
7
|
|
10
|
-
string :mode
|
8
|
+
string :mode, -> {
|
11
9
|
case target[0]
|
12
10
|
when :req
|
13
11
|
'required'
|
@@ -26,7 +24,7 @@ module GQL
|
|
26
24
|
else
|
27
25
|
target[0].to_s
|
28
26
|
end
|
29
|
-
|
27
|
+
}
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
data/lib/gql/string.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module GQL
|
2
2
|
class String < Simple
|
3
3
|
# These are just example calls. Monkeypatch class to add your own.
|
4
|
-
call :upcase
|
5
|
-
call :downcase
|
6
|
-
call :length, Number
|
4
|
+
call :upcase
|
5
|
+
call :downcase
|
6
|
+
call :length, returns: Number
|
7
7
|
end
|
8
8
|
end
|
data/lib/gql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Andert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,5 @@ rubyforge_project:
|
|
157
157
|
rubygems_version: 2.4.5
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
|
-
summary:
|
161
|
-
specification.
|
160
|
+
summary: A Ruby implementation of Facebook's yet-to-be-released GraphQL specification.
|
162
161
|
test_files: []
|