pggraphql 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0b33e3078467161a88af120f37b4de4fc10e127
4
- data.tar.gz: eb9f61d5aa769cab705f3d1194227278fbbe585f
3
+ metadata.gz: 60ab99d71efd2955788a1616ec4c8a3ebcbe971a
4
+ data.tar.gz: ec9403901a2fa867d64e08954ff2a69a181df330
5
5
  SHA512:
6
- metadata.gz: bf40ede2fc8a855cf762dfe9052ba58565696cdbf539a446ad7554c2517389feb1292b089aca5bba7454b6c8eec4fec05e8cb15a2ead57fc69751e2692c55bc7
7
- data.tar.gz: d970827a05f6af6e537390062ea00fe5443f4e64cf5ce802e2fd06106a5a0227836cb3fe50e4dde05602b7d91d8e5ebd1fe10cf8caa37350cf54de97c0d51fc4
6
+ metadata.gz: 79b377023aa0b3df1297fce755f8a7139ea41055f053099f2d30e1949789e8b7ea34f62fcb68a2b540d63d547d92baef62e8830134ece865f47863f08793c7f2
7
+ data.tar.gz: 07f8413aaf1fc7ea03c7f82db48330d7bd18f561c41f7e1f8985e2f373a4b13d8526064045967245b2c4cc9854db20684766744f70f5aaef19265bf02d050dae
@@ -1,3 +1,3 @@
1
1
  module Pggraphql
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/pggraphql.rb CHANGED
@@ -37,7 +37,11 @@ module PgGraphQl
37
37
  raise "#{type.name.inspect} is not a root type" if level == 1 && !@roots.include?(type)
38
38
  raise "missing :fk on link #{link.name.inspect}" if link && !link.fk
39
39
 
40
- columns = {id: nil}.merge(e[1]).map do |f|
40
+ requested_fields = {id: nil} # always add :id field
41
+ requested_fields = requested_fields.merge(type: nil) unless type.subtypes.empty? # always add :subtype
42
+ requested_fields = requested_fields.merge(e[1])
43
+
44
+ columns = requested_fields.map do |f|
41
45
  nested_link_name = f[0]
42
46
  field_name = f[0]
43
47
 
@@ -108,7 +112,7 @@ module PgGraphQl
108
112
  @schema = schema
109
113
  @name = name
110
114
  @table = name.to_s.pluralize.to_sym
111
- @fields = [:id]
115
+ @fields = []
112
116
  @filter = nil
113
117
  @order_by = nil
114
118
  @links = {}
@@ -125,7 +129,10 @@ module PgGraphQl
125
129
  end
126
130
  end
127
131
  def fields=(fields)
128
- @fields = (fields + [:id]).uniq
132
+ @fields = fields
133
+ end
134
+ def fields
135
+ @fields + [:id] + (@subtypes.empty? ? [] : [:type])
129
136
  end
130
137
  def map(field, column_expr)
131
138
  @mappings[field] = column_expr
@@ -314,7 +314,7 @@ module PgGraphQl
314
314
  }
315
315
  }) do |s|
316
316
  s.root :product
317
- s.type :product, null_pk: :array, fields: [:type, :clickout__destination_url, :download__download_url] do |t|
317
+ s.type :product, null_pk: :array, fields: [:clickout__destination_url, :download__download_url] do |t|
318
318
  t.map :id, "products.id"
319
319
  t.subtype :clickout, table: :product_clickouts, fk: "clickout.id = products.id and products.type = 'clickout'"
320
320
  end
@@ -323,7 +323,7 @@ module PgGraphQl
323
323
  assert_equal token(<<-SQL
324
324
  select 'products'::text as key,
325
325
  (select to_json(x.*)
326
- from (select products.id as id,
326
+ from (select products.id as id, type,
327
327
  clickout.destination_url as clickout__destination_url
328
328
  from products
329
329
  left join product_clickouts as clickout on (clickout.id = products.id
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pggraphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json