gql 0.0.6 → 0.0.7

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.
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
- root
5
- : variables node variables { result = Root.new(val[1], val[0].merge(val[2])) }
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
- node
10
- : call { result = Node.new(val[0], nil ) }
11
- | fields { result = Node.new(nil, val[0].presence) }
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 Root < Struct.new(:node, :variables)
135
- end
136
-
137
- class Node < Struct.new(:call, :fields)
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 }
@@ -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
- array :parameters, :item_class => Parameter do
8
- target.method.parameters
9
- end
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
@@ -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 :type do
8
- target.name
9
- end
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
@@ -1,17 +1,9 @@
1
1
  module GQL
2
2
  module Schema
3
3
  class Node < GQL::Node
4
- string :type do
5
- target.name
6
- end
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
@@ -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 do
7
- target[1].to_s
8
- end
6
+ string :id, -> { target[1].to_s }
9
7
 
10
- string :mode do
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
- end
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, -> { target.upcase }
5
- call :downcase, -> { target.downcase }
6
- call :length, Number, -> { target.size }
4
+ call :upcase
5
+ call :downcase
6
+ call :length, returns: Number
7
7
  end
8
8
  end
data/lib/gql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GQL
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
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.6
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-05 00:00:00.000000000 Z
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: An attempted Ruby implementation of Facebook's yet-to-be-released GraphQL
161
- specification.
160
+ summary: A Ruby implementation of Facebook's yet-to-be-released GraphQL specification.
162
161
  test_files: []