pggraphql 0.0.4 → 0.0.5
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 +4 -4
- data/lib/pggraphql/version.rb +1 -1
- data/lib/pggraphql.rb +13 -6
- data/test/test_pggraphql.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3ae8e16af5b6972f61cacef41f24d9b19f8672
|
4
|
+
data.tar.gz: bec017114b149de19a7cdca9a4f5e9d0663e7086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa31bbf4d066e4d2265f410e00436dcf773488c5723cacf339b8c13221e948736398d96647c869e0605e03091de3047537d4b30a8bb394de2a0de8559f56cc0
|
7
|
+
data.tar.gz: 448db0dd34a71332eec63993039d423ea752df5b2f05521f35b9065c82644da8f4d852939f84e3450f2febf2ff32584b0b4db127b084096e62c877b2992b2049
|
data/lib/pggraphql/version.rb
CHANGED
data/lib/pggraphql.rb
CHANGED
@@ -54,11 +54,7 @@ module PgGraphQl
|
|
54
54
|
wheres = []
|
55
55
|
|
56
56
|
if ids && ids.to_s != "id"
|
57
|
-
if
|
58
|
-
wheres << "id in (#{ids.join(',')})" unless ids.empty?
|
59
|
-
else
|
60
|
-
wheres << "id = #{ids}"
|
61
|
-
end
|
57
|
+
wheres << type.pk.call(ids) if type.pk.call(ids)
|
62
58
|
end
|
63
59
|
|
64
60
|
wheres << ("(" + type.filter + ")") if type.filter
|
@@ -102,7 +98,7 @@ module PgGraphQl
|
|
102
98
|
end
|
103
99
|
|
104
100
|
class Type
|
105
|
-
attr_accessor :name, :table, :filter, :links, :order_by, :fields, :subtypes
|
101
|
+
attr_accessor :name, :table, :filter, :links, :order_by, :fields, :subtypes, :pk
|
106
102
|
attr_reader :schema, :mappings
|
107
103
|
def initialize(schema, name)
|
108
104
|
@schema = schema
|
@@ -114,6 +110,17 @@ module PgGraphQl
|
|
114
110
|
@links = {}
|
115
111
|
@subtypes = {}
|
116
112
|
@mappings = {}
|
113
|
+
@pk = ->(ids) do
|
114
|
+
if ids.is_a?(Array)
|
115
|
+
if ids.empty?
|
116
|
+
nil
|
117
|
+
else
|
118
|
+
"id in (#{ids.join(',')})"
|
119
|
+
end
|
120
|
+
else
|
121
|
+
"id = #{ids}"
|
122
|
+
end
|
123
|
+
end
|
117
124
|
end
|
118
125
|
def map(field, column_expr)
|
119
126
|
@mappings[field] = column_expr
|
data/test/test_pggraphql.rb
CHANGED
@@ -53,6 +53,22 @@ module PgGraphQl
|
|
53
53
|
), token(res)
|
54
54
|
end
|
55
55
|
|
56
|
+
def test_simple_pk_custom
|
57
|
+
res = to_sql({user: {id: "1", email: "email"}}) do |s|
|
58
|
+
s.root :user
|
59
|
+
s.type :user, fields: [:id, :email], pk: ->(id){ "access_token = '#{id}'" }
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_equal token(<<-SQL
|
63
|
+
select 'user'::text as key,
|
64
|
+
(select to_json(x.*)
|
65
|
+
from (select id,
|
66
|
+
email
|
67
|
+
from users where access_token = '1' limit 1) x) as value
|
68
|
+
SQL
|
69
|
+
), token(res)
|
70
|
+
end
|
71
|
+
|
56
72
|
def test_simple_pk_array_one
|
57
73
|
res = to_sql({user: {id: [1], email: "email"}}) do |s|
|
58
74
|
s.root :user
|