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
Copy file name to clipboardExpand all lines: docs/learn/index.html
+68Lines changed: 68 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3047,6 +3047,74 @@ <h3 id="determine-a-query-operation-type">Determine a Query Operation Type</h3>
3047
3047
3048
3048
<p>Sometimes it can be very useful to know the type of query operation. For example you need it if you want to return a different response for subscription queries. <codeclass="language-plaintext highlighter-rouge">ast.Document</code> exposes <codeclass="language-plaintext highlighter-rouge">operationType</code> and <codeclass="language-plaintext highlighter-rouge">operation</code> for this.</p>
3049
3049
3050
+
<h2id="performance-tips">Performance tips.</h2>
3051
+
3052
+
<p>Sangria is being used by several companies on production since several years and capable of handling a lot of traffic.</p>
3053
+
3054
+
<p>Sangria is indeed a fast library. If you want to take the maximum out of it, here are some guidelines and tips.</p>
3055
+
3056
+
<h3id="compute-the-schema-only-once">Compute the schema only once</h3>
3057
+
3058
+
<p>Make sure that you only compute the schema once. This easiest way is to use a singleton object to define the schema:</p>
<h3id="use-the-parasitic-executioncontext-expert">Use the <codeclass="language-plaintext highlighter-rouge">parasitic</code> ExecutionContext (expert)</h3>
3082
+
3083
+
<p>Sangria uses <codeclass="language-plaintext highlighter-rouge">Future</code> to handle asynchronous operations. When you execute a query, you need to pass an <codeclass="language-plaintext highlighter-rouge">ExecutionContext</code>.</p>
3084
+
3085
+
<p>One way to improve performances is to use the <codeclass="language-plaintext highlighter-rouge">scala.concurrent.ExecutionContext.parasitic</code> ExecutionContext.
3086
+
But be careful that this ExecutionContext will propagate everywhere, including in the <codeclass="language-plaintext highlighter-rouge">DeferredResolver</code> where it might not be the best option. You might be using the wrong thread pool for IO operations.</p>
3087
+
3088
+
<p>To avoid this, you can pack the ExecutionContext in your Context and use it in the <codeclass="language-plaintext highlighter-rouge">DeferredResolver</code>:</p>
0 commit comments