graphiti-activegraph 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: fcd7ae36f65b6298e255294c9c31eb7ec4aa94c7c4139879f11b67568ec8e5ed
4
- data.tar.gz: ce54de880a7ef2e6f29a2b96006fff80c9ae469d4a769b49338a639371985ca3
3
+ metadata.gz: 414cf4ca5fa4c6027a87a9af43c47041ffee42b746ab148b29ffc2dc452fcda9
4
+ data.tar.gz: 952da258c8b891c1165e26a13ac6c4c2a8377842a5c353d8a1d329d91b2f0c26
5
5
  SHA512:
6
- metadata.gz: df010adbf915733d9d243063b567113178728ced21c4c3a4172fdbb22b5fff89199b7a7a1c96dd1b2c28bb6a264bfed38743b5f1e6a4b7be43a0d4e24bf3593b
7
- data.tar.gz: 54669aa759b24c0582b44956c4a6ab0eb37bf0063db62836e983204133c13b1bba65602b1f95e19f129f2d571b289545a054a713dd7def1aeea6ed4a74c69f11
6
+ metadata.gz: 50e809c41a2ccbdade72af95a4391102fb204ede9a0477149fa4810112c379d301f8807046d5a44362cc6a68c4b22c5932b2f1b45478b63a9f2e8afb1df66c16
7
+ data.tar.gz: 7bd4274635d96ccdd65fb2d041efb12a1df07042d8a207218af1d13c91c4e8beb067c2bffecc20c9f5e0ceeccc9cf965d14f30fa14e36eefbfc23a752947ab90
@@ -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
@@ -9,7 +9,7 @@ module Graphiti::ActiveGraph
9
9
  end
10
10
 
11
11
  def base_scope(model)
12
- model.all
12
+ model
13
13
  end
14
14
 
15
15
  def assign_attributes(model_instance, attributes)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Graphiti
2
2
  module ActiveGraph
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  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.3
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-09-08 00:00:00.000000000 Z
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