graphiti 1.0.beta.21 → 1.0.beta.22

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
  SHA1:
3
- metadata.gz: 50f78e16b388d5c025b539286778286b8bf0f811
4
- data.tar.gz: 3d1a9f2ca018295e04e23397f5c896f0a41402cb
3
+ metadata.gz: 8e5cc04af9bfdafe229a379fd1c5b3016cfc2e2f
4
+ data.tar.gz: b45b8a34cd3e066c0861fb9bdf1dfb0cdb1d8a05
5
5
  SHA512:
6
- metadata.gz: 49f849661b7552e18876f3e1e424c4dc9d7b645e42c9de6550532ade53315605354db3aba07153083e611235566fa3616e847f670d93609b30279929a18e0c2b
7
- data.tar.gz: b1924964f374bd0c404a1a948220d6fc4b0af9380ab9fcf412a7e5791f7530ec224622454771043b987d1580aee0aaf54ea9dda4de9e05447bba24d8500a1039
6
+ metadata.gz: 80ea382d0120b44c2d59ec559a17c98274bcad560a5f5863a5b62e33a813e36f247b9949f55a0b46c464bba31f67e4d079e69a33d7e69ee1eb74eca00dc8e91d
7
+ data.tar.gz: fbfff29b988d97ba4b874cfa983e0d056dc9cd3a05209326665e35722b4f435470866316c6e844d9119373c154d92a10b5935d688c3b8d548aa1712a82f6a925
@@ -31,27 +31,27 @@ module Graphiti
31
31
 
32
32
  def generate_api_specs
33
33
  if actions?('index')
34
- to = "spec/api/v1/#{dir}/index_spec.rb"
34
+ to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "index_spec.rb")
35
35
  template('index_request_spec.rb.erb', to)
36
36
  end
37
37
 
38
38
  if actions?('show')
39
- to = "spec/api/v1/#{dir}/show_spec.rb"
39
+ to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "show_spec.rb")
40
40
  template('show_request_spec.rb.erb', to)
41
41
  end
42
42
 
43
43
  if actions?('create')
44
- to = "spec/api/v1/#{dir}/create_spec.rb"
44
+ to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "create_spec.rb")
45
45
  template('create_request_spec.rb.erb', to)
46
46
  end
47
47
 
48
48
  if actions?('update')
49
- to = "spec/api/v1/#{dir}/update_spec.rb"
49
+ to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "update_spec.rb")
50
50
  template('update_request_spec.rb.erb', to)
51
51
  end
52
52
 
53
53
  if actions?('destroy')
54
- to = "spec/api/v1/#{dir}/destroy_spec.rb"
54
+ to = File.join("spec", ApplicationResource.endpoint_namespace, dir, "destroy_spec.rb")
55
55
  template('destroy_request_spec.rb.erb', to)
56
56
  end
57
57
  end
@@ -27,10 +27,19 @@ module Graphiti
27
27
  end
28
28
 
29
29
  inject_into_file 'config/application.rb', after: "Rails::Application\n" do
30
- <<-'TXT'
31
- argv_options = Rails::Server::Options.new.parse!(ARGV)
32
- routes.default_url_options[:host] = ENV.fetch('HOST', "http://#{argv_options[:Host]}:#{argv_options[:Port]}")
33
- TXT
30
+ <<-'RUBY'
31
+ # In order for Graphiti to generate links, you need to set the routes host.
32
+ # When not explicitly set, via the HOST env var, this will fall back to
33
+ # the rails server settings.
34
+ # Rails::Server is not defined in console or rake tasks, so this will only
35
+ # use those defaults when they are available.
36
+ routes.default_url_options[:host] = ENV.fetch('HOST') do
37
+ if defined?(Rails::Server)
38
+ argv_options = Rails::Server::Options.new.parse!(ARGV)
39
+ "http://#{argv_options[:Host]}:#{argv_options[:Port]}"
40
+ end
41
+ end
42
+ RUBY
34
43
  end
35
44
 
36
45
  inject_into_file 'spec/rails_helper.rb', after: /RSpec.configure.+^end$/m do
@@ -21,6 +21,7 @@ module Graphiti
21
21
  _find(params, base_scope)
22
22
  end
23
23
 
24
+ # @api private
24
25
  def _find(params = {}, base_scope = nil)
25
26
  id = params[:data].try(:[], :id) || params.delete(:id)
26
27
  params[:filter] ||= {}
@@ -91,6 +91,16 @@ module Graphiti
91
91
  @payload.relationships
92
92
  end
93
93
  @data, success = validator.to_a
94
+
95
+ if success
96
+ # If the context namespace is `update` or `create`, certain
97
+ # adapters will cause N+1 validation calls, so lets explicitly
98
+ # switch to a lookup context.
99
+ Graphiti.with_context(Graphiti.context[:object], :show) do
100
+ @scope.resolve_sideloads([@data])
101
+ end
102
+ end
103
+
94
104
  success
95
105
  end
96
106
 
@@ -113,7 +123,10 @@ module Graphiti
113
123
  end
114
124
 
115
125
  def include_hash
116
- @payload ? @payload.include_hash : @query.include_hash
126
+ @include_hash ||= begin
127
+ base = @payload ? @payload.include_hash : {}
128
+ base.deep_merge(@query.include_hash)
129
+ end
117
130
  end
118
131
 
119
132
  def fields
@@ -27,34 +27,12 @@ module Graphiti
27
27
  if @opts[:after_resolve]
28
28
  @opts[:after_resolve].call(resolved)
29
29
  end
30
- sideload(resolved) unless @query.sideloads.empty?
30
+ resolve_sideloads(resolved) unless @query.sideloads.empty?
31
31
  resolved
32
32
  end
33
33
  end
34
34
 
35
- private
36
-
37
- def broadcast_data
38
- opts = {
39
- resource: @resource,
40
- params: @opts[:params],
41
- sideload: @opts[:sideload],
42
- parent: @opts[:parent]
43
- }
44
- Graphiti.broadcast("data", opts) do |payload|
45
- yield payload
46
- end
47
- end
48
-
49
- # Used to ensure the resource's serializer is used
50
- # Not one derived through the usual jsonapi-rb logic
51
- def assign_serializer(records)
52
- records.each do |r|
53
- @resource.decorate_record(r)
54
- end
55
- end
56
-
57
- def sideload(results)
35
+ def resolve_sideloads(results)
58
36
  return if results == []
59
37
 
60
38
  concurrent = Graphiti.config.concurrency
@@ -92,6 +70,28 @@ module Graphiti
92
70
  end
93
71
  end
94
72
 
73
+ private
74
+
75
+ def broadcast_data
76
+ opts = {
77
+ resource: @resource,
78
+ params: @opts[:params],
79
+ sideload: @opts[:sideload],
80
+ parent: @opts[:parent]
81
+ }
82
+ Graphiti.broadcast("data", opts) do |payload|
83
+ yield payload
84
+ end
85
+ end
86
+
87
+ # Used to ensure the resource's serializer is used
88
+ # Not one derived through the usual jsonapi-rb logic
89
+ def assign_serializer(records)
90
+ records.each do |r|
91
+ @resource.decorate_record(r)
92
+ end
93
+ end
94
+
95
95
  def apply_scoping(scope, opts)
96
96
  @object = scope
97
97
  opts[:default_paginate] = false unless @query.paginate?
@@ -7,7 +7,11 @@ module Graphiti
7
7
 
8
8
  WriteDateTime = create(::DateTime) do |input|
9
9
  if input.is_a?(::Date) || input.is_a?(::Time)
10
- input = ::DateTime.parse(input.to_s)
10
+ input = if input.respond_to?(:to_datetime)
11
+ input.to_datetime
12
+ else
13
+ ::DateTime.parse(input.to_s)
14
+ end
11
15
  end
12
16
  input = Dry::Types['json.date_time'][input]
13
17
  Dry::Types['strict.date_time'][input] if input
@@ -15,7 +19,11 @@ module Graphiti
15
19
 
16
20
  ReadDateTime = create(::DateTime) do |input|
17
21
  if input.is_a?(::Date) || input.is_a?(::Time)
18
- input = ::DateTime.parse(input.to_s)
22
+ input = if input.respond_to?(:to_datetime)
23
+ input.to_datetime
24
+ else
25
+ ::DateTime.parse(input.to_s)
26
+ end
19
27
  end
20
28
  input = Dry::Types['json.date_time'][input]
21
29
  Dry::Types['strict.date_time'][input].iso8601 if input
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.beta.21"
2
+ VERSION = "1.0.beta.22"
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.0.beta.21
4
+ version: 1.0.beta.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-18 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable