graphiti-activegraph 0.1.3 → 0.1.4
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/graphiti-activegraph.rb +2 -0
- data/lib/graphiti/active_graph/adapters/active_graph.rb +1 -1
- data/lib/graphiti/active_graph/util/relationship_payload.rb +33 -0
- data/lib/graphiti/active_graph/util/serializer_attribute.rb +17 -0
- data/lib/graphiti/active_graph/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 414cf4ca5fa4c6027a87a9af43c47041ffee42b746ab148b29ffc2dc452fcda9
|
4
|
+
data.tar.gz: 952da258c8b891c1165e26a13ac6c4c2a8377842a5c353d8a1d329d91b2f0c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50e809c41a2ccbdade72af95a4391102fb204ede9a0477149fa4810112c379d301f8807046d5a44362cc6a68c4b22c5932b2f1b45478b63a9f2e8afb1df66c16
|
7
|
+
data.tar.gz: 7bd4274635d96ccdd65fb2d041efb12a1df07042d8a207218af1d13c91c4e8beb067c2bffecc20c9f5e0ceeccc9cf965d14f30fa14e36eefbfc23a752947ab90
|
data/lib/graphiti-activegraph.rb
CHANGED
@@ -23,6 +23,8 @@ Graphiti::Resource::Persistence.prepend Graphiti::ActiveGraph::Resource::Persist
|
|
23
23
|
Graphiti::Scoping::Filter.prepend Graphiti::ActiveGraph::Scoping::Filter
|
24
24
|
Graphiti::Scoping::Filterable.prepend Graphiti::ActiveGraph::Scoping::Filterable
|
25
25
|
Graphiti::Util::SerializerRelationship.prepend Graphiti::ActiveGraph::Util::SerializerRelationship
|
26
|
+
Graphiti::Util::SerializerAttribute.prepend Graphiti::ActiveGraph::Util::SerializerAttribute
|
27
|
+
Graphiti::Util::RelationshipPayload.prepend Graphiti::ActiveGraph::Util::RelationshipPayload
|
26
28
|
Graphiti::Deserializer.prepend Graphiti::ActiveGraph::Deserializer
|
27
29
|
Graphiti::Query.prepend Graphiti::ActiveGraph::Query
|
28
30
|
Graphiti::Resource.prepend Graphiti::ActiveGraph::ResourceInstanceMethods
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Graphiti::ActiveGraph
|
2
|
+
module Util
|
3
|
+
module RelationshipPayload
|
4
|
+
def payload_for(sideload, relationship_payload)
|
5
|
+
type = relationship_payload[:meta][:jsonapi_type]&.to_sym
|
6
|
+
|
7
|
+
# For polymorphic *sideloads*, grab the correct child sideload
|
8
|
+
if sideload.resource.type != type && sideload.type == :polymorphic_belongs_to
|
9
|
+
sideload = sideload.child_for_type!(type)
|
10
|
+
end
|
11
|
+
|
12
|
+
# For polymorphic *resources*, grab the correct child resource
|
13
|
+
resource = sideload.resource
|
14
|
+
if resource.type != type && resource.polymorphic?
|
15
|
+
resource = resource.class.resource_for_type(type).new
|
16
|
+
end
|
17
|
+
|
18
|
+
relationship_payload[:meta][:method] ||= :update
|
19
|
+
|
20
|
+
{
|
21
|
+
resource: resource,
|
22
|
+
sideload: sideload,
|
23
|
+
is_polymorphic: sideload.polymorphic_child?,
|
24
|
+
primary_key: sideload.primary_key,
|
25
|
+
foreign_key: sideload.foreign_key,
|
26
|
+
attributes: relationship_payload[:attributes],
|
27
|
+
meta: relationship_payload[:meta],
|
28
|
+
relationships: relationship_payload[:relationships]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Graphiti::ActiveGraph
|
2
|
+
module Util
|
3
|
+
module SerializerAttribute
|
4
|
+
def wrap_proc(inner)
|
5
|
+
typecast_ref = typecast(Graphiti::Types[@attr[:type]][:read])
|
6
|
+
->(serializer_instance = nil) {
|
7
|
+
val = serializer_instance.instance_eval(&inner)
|
8
|
+
if Graphiti.config.typecast_reads && inner.nil?
|
9
|
+
typecast_ref.call(val)
|
10
|
+
else
|
11
|
+
val
|
12
|
+
end
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti-activegraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hardik Joshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphiti
|
@@ -188,6 +188,8 @@ files:
|
|
188
188
|
- lib/graphiti/active_graph/scoping/filter.rb
|
189
189
|
- lib/graphiti/active_graph/scoping/filterable.rb
|
190
190
|
- lib/graphiti/active_graph/sideload_resolve.rb
|
191
|
+
- lib/graphiti/active_graph/util/relationship_payload.rb
|
192
|
+
- lib/graphiti/active_graph/util/serializer_attribute.rb
|
191
193
|
- lib/graphiti/active_graph/util/serializer_relationship.rb
|
192
194
|
- lib/graphiti/active_graph/version.rb
|
193
195
|
homepage: https://github.com/mrhardikjoshi/graphiti-activegraph
|