You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The <codeclass="highlighter-rouge">schema</code> flag is not affected by <codeclass="highlighter-rouge">only/except</code> options.
220
+
<p>The <codeclass="highlighter-rouge">schema</code> flag is not affected by <codeclass="highlighter-rouge">only/except</code> options.
220
221
This option determines if the attribute is exported to the schema.json.</p>
221
222
222
223
<p>You might want to allow behavior only if a certain condition is met.
@@ -771,7 +772,7 @@ <h5>
771
772
<p>If a filter is marked <codeclass="highlighter-rouge">single: true</code>, we’ll avoid any array parsing and
772
773
escape the value for you, filtering on the string as given.</p>
773
774
774
-
<p>By default a value that comes in as <codeclass="highlighter-rouge">null</code> is treated as a string <codeclass="highlighter-rouge">"null"</code>.
775
+
<p>By default a value that comes in as <codeclass="highlighter-rouge">null</code> is treated as a string <codeclass="highlighter-rouge">"null"</code>.
775
776
To coerce <codeclass="highlighter-rouge">null</code> to a Ruby <codeclass="highlighter-rouge">nil</code> mark the filter with <codeclass="highlighter-rouge">allow_nil: true</code>.
776
777
This can be changed for all attributes by setting <codeclass="highlighter-rouge">filters_accept_nil_by_default</code></p>
<p>By default when using Rails, Graphiti will turn on concurrency when <codeclass="highlighter-rouge">::Rails.application.config.cache_classes</code> is <codeclass="highlighter-rouge">true</code> (the default for staging and production environments). This will cause sibling sideloads to load concurrently. If a <codeclass="highlighter-rouge">Post</code> is sideloading <codeclass="highlighter-rouge">Comments</code> and <codeclass="highlighter-rouge">Author</code>, we’ll load both of those at the same time.</p>
1967
+
1968
+
<p>You can turn on/off this behavior explicitly:</p>
<p><strong>NOTE</strong>: Since this kicks off a new Thread, thread locals will be dropped. So if your code refers to <codeclass="highlighter-rouge">Thread.current[:foo]</code> you should set and get that on <codeclass="highlighter-rouge">Graphiti.context</code>:</p>
<spanclass="no">Thread</span><spanclass="p">.</span><spanclass="nf">current</span><spanclass="p">[</span><spanclass="ss">:foo</span><spanclass="p">]</span><spanclass="c1"># => will be nil when sideloading!</span>
<spanclass="no">Graphiti</span><spanclass="p">.</span><spanclass="nf">context</span><spanclass="p">[</span><spanclass="ss">:foo</span><spanclass="p">]</span><spanclass="c1"># => "bar", even when sideloading</span></code></pre></figure>
Copy file name to clipboardExpand all lines: guides/concepts/resources.md
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,8 @@ Resources
50
50
*[Expanded Example](#expanded-example)
51
51
*[Validation Errors](#validation-errors)
52
52
* 8 [Context](#context)
53
-
* 9 [Adapters](#adapters)
53
+
* 9 [Concurrency](#concurrency)
54
+
* 10 [Adapters](#adapters)
54
55
</div>
55
56
56
57
<divmarkdown="1"class="col-md-8">
@@ -1783,7 +1784,32 @@ Graphiti.with_context(ctx) do
1783
1784
end
1784
1785
{% endhighlight %}
1785
1786
1786
-
{% include h.html tag="h2" text="9 Adapters" a="adapters" %}
1787
+
{% include h.html tag="h2" text="9 Concurrency" a="concurrency" %}
1788
+
1789
+
By default when using Rails, Graphiti will turn on concurrency when `::Rails.application.config.cache_classes` is `true` (the default for staging and production environments). This will cause sibling sideloads to load concurrently. If a `Post` is sideloading `Comments` and `Author`, we'll load both of those at the same time.
1790
+
1791
+
You can turn on/off this behavior explicitly:
1792
+
1793
+
{% highlight ruby %}
1794
+
# config/intializers/graphiti.rb
1795
+
Graphiti.configure do |c|
1796
+
c.concurrency = false
1797
+
end
1798
+
{% endhighlight %}
1799
+
1800
+
**NOTE**: Since this kicks off a new Thread, thread locals will be dropped. So if your code refers to `Thread.current[:foo]` you should set and get that on `Graphiti.context`:
1801
+
1802
+
{% highlight ruby %}
1803
+
# BAD:
1804
+
Thread.current[:foo] = "bar"
1805
+
Thread.current[:foo] # => will be nil when sideloading!
1806
+
1807
+
# GOOD:
1808
+
Graphiti.context[:foo] = "bar"
1809
+
Graphiti.context[:foo] # => "bar", even when sideloading
1810
+
{% endhighlight %}
1811
+
1812
+
{% include h.html tag="h2" text="10 Adapters" a="adapters" %}
1787
1813
1788
1814
Common resource overrides can be packaged into an Adapter for code
1789
1815
re-use. The most common example is using a different client/datastore
0 commit comments