graphiti 1.2.11 → 1.2.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea78d309ce3a7faf7b9d775c9e79e4df2d3b93533653ebeaecdd91e28abb7433
4
- data.tar.gz: 40a140a265f9d7a3123f9dc6a06c2fe55264a67e15271e80b32ed64300db3ae2
3
+ metadata.gz: 345a2d39445d433019a8c0055cf337b4b8fdf21e9d59e5785b923a5ee1a8c9fb
4
+ data.tar.gz: 0ec15af245b2c7bb9530e9b771839eb6b4487d3ca87cadb9b41788ce8cc63326
5
5
  SHA512:
6
- metadata.gz: d825856d877cde9035fa381ab9e9b65f0ab63f49e027de7ffd91bece79eb63e2050c00d6fce35dc416cccd33ad8a50124bbdf5bd9c407381f24827f63d154f72
7
- data.tar.gz: 71b3422a5e049497c860be945b2449ddaadb8f88419b6146f6aa3b8f91ab5fe65ac4570b500d6a8ffd96b6a09c8a232c878d614b8efb65dc10ade84d295019ab
6
+ metadata.gz: 25dffc875c9f781f29467940e320888ba53fc974964c6267018d49eb9bc7cc274819fb46209f31a13bd1747b7cffcbd87542fb675e624c3491196a9dd255292d
7
+ data.tar.gz: 656c3ba8365f422d119b8df8d1ac6a2f4a23a2f57b460d1e18356b6bdfac938059397082df5665ee8b890dcc61868173e328976955204a7bd511bd3b410a2844
data/README.md CHANGED
@@ -12,7 +12,7 @@ Stylish Graph APIs.
12
12
 
13
13
  [Website](https://www.graphiti.dev/guides/)
14
14
 
15
- [Join the Slack Channel](https://join.slack.com/t/graphiti-api/shared_invite/enQtMjkyMTA3MDgxNTQzLWVkMDM3NTlmNTIwODY2YWFkMGNiNzUzZGMzOTY3YmNmZjBhYzIyZWZlZTk4YmI1YTI0Y2M0OTZmZGYwN2QxZjg)
15
+ [Join the Slack Channel](https://join.slack.com/t/graphiti-api/shared_invite/enQtMjkyMTA3MDgxNTQzLTU5MDI4MDllNTEzOTE1Nzk0ZGJlNTcxZDYzMGY2ZTczMDY2OWZhM2RmNTU0YWNiOWZhZDhkMmU4MzQ5NzIyNWM)
16
16
 
17
17
  Direct Contact: richmolj@gmail.com
18
18
 
@@ -75,6 +75,20 @@ module Graphiti
75
75
  end
76
76
  end
77
77
 
78
+ def polymorphic_has_one(name, opts = {}, &blk)
79
+ as = opts.delete(:as)
80
+ opts[:foreign_key] ||= :"#{as}_id"
81
+ opts[:polymorphic_as] ||= as
82
+ model_ref = model
83
+ has_one name, opts do
84
+ params do |hash|
85
+ hash[:filter][:"#{as}_type"] = model_ref.name
86
+ end
87
+
88
+ instance_eval(&blk) if block_given?
89
+ end
90
+ end
91
+
78
92
  def sideload(name)
79
93
  sideloads[name]
80
94
  end
@@ -110,6 +110,10 @@ module Graphiti
110
110
  !!@single
111
111
  end
112
112
 
113
+ def polymorphic_has_one?
114
+ !!@polymorphic_as
115
+ end
116
+
113
117
  def polymorphic_has_many?
114
118
  !!@polymorphic_as
115
119
  end
@@ -83,13 +83,13 @@ class Graphiti::Util::Persistence
83
83
  return if x[:sideload].type == :many_to_many
84
84
 
85
85
  if [:destroy, :disassociate].include?(x[:meta][:method])
86
- if x[:sideload].polymorphic_has_many?
86
+ if x[:sideload].polymorphic_has_one? || x[:sideload].polymorphic_has_many?
87
87
  attrs[:"#{x[:sideload].polymorphic_as}_type"] = nil
88
88
  end
89
89
  attrs[x[:foreign_key]] = nil
90
90
  update_foreign_type(attrs, x, null: true) if x[:is_polymorphic]
91
91
  else
92
- if x[:sideload].polymorphic_has_many?
92
+ if x[:sideload].polymorphic_has_one? || x[:sideload].polymorphic_has_many?
93
93
  attrs[:"#{x[:sideload].polymorphic_as}_type"] = parent_object.class.name
94
94
  end
95
95
  attrs[x[:foreign_key]] = parent_object.send(x[:primary_key])
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.11"
2
+ VERSION = "1.2.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.11
4
+ version: 1.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2019-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable