Skip to content

Commit c213790

Browse files
author
github-actions
committed
Documentation update
1 parent 07cfacf commit c213790

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

docs/guides/dataloader/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</script></head><body><div id="___gatsby"><div style="outline:none" tabindex="-1" id="gatsby-focus-wrapper"><nav class="header"><ul><li><a href="/">GraphQL.NET</a></li><li><a href="/docs/getting-started/introduction/">Docs</a></li><li><a href="https://github.com/graphql-dotnet/graphql-dotnet" rel="noopener noreferrer" target="_blank">GitHub</a></li></ul></nav><div class="page-body"><div class="content"><article class="content-body"><h1 id="dataloader" style="position:relative;"><a href="#dataloader" aria-label="dataloader permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>DataLoader</h1>
5252
<p>GraphQL.NET includes an implementation of Facebook's <a href="https://github.com/facebook/dataloader">DataLoader</a> within the
5353
<a href="https://www.nuget.org/packages/GraphQL.DataLoader"><code class="language-text">GraphQL.DataLoader</code></a> NuGet package.</p>
54+
<p>Sample projects demonstrating both default data loaders (as described below on this page) and <a href="#di-based-data-loaders">DI-based data loaders</a> are available in the <a href="https://github.com/graphql-dotnet/graphql-dotnet/samples">GraphQL.NET source repository</a>. These projects cover examples of data loaders accessed via <code class="language-text">IDataLoaderContextAccessor</code> as well as those implemented using dependency injection (DI).</p>
5455
<p>Consider a GraphQL query like this:</p>
5556
<div class="gatsby-highlight" data-language="graphql"><pre class="language-graphql"><code class="language-graphql"><span class="token punctuation">{</span>
5657
<span class="token property-query">orders</span><span class="token punctuation">(</span><span class="token attr-name">date</span><span class="token punctuation">:</span> <span class="token string">"2017-01-01"</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
@@ -72,12 +73,13 @@
7273
<p>In the example above, a using a DataLoader will allow us to batch together all of the requests for the users. So there would be 1 request to retrieve the list of orders and 1 request to load all users associated with those orders. This would always be a total of 2 requests rather than N+1.</p>
7374
<h2 id="setup" style="position:relative;"><a href="#setup" aria-label="setup permalink" class="anchor before"><svg aria-hidden="true" focusable="false" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Setup</h2>
7475
<ol>
75-
<li>Register <code class="language-text">IDataLoaderContextAccessor</code> in your IoC container.</li>
76-
<li>Register <code class="language-text">DataLoaderDocumentListener</code> in your IoC container.</li>
76+
<li>Register the DataLoader services</li>
7777
</ol>
78-
<div class="gatsby-highlight" data-language="csharp"><pre class="language-csharp"><code class="language-csharp">services<span class="token punctuation">.</span><span class="token generic-method"><span class="token function">AddSingleton</span><span class="token generic class-name"><span class="token punctuation">&lt;</span>IDataLoaderContextAccessor<span class="token punctuation">,</span> DataLoaderContextAccessor<span class="token punctuation">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
79-
services<span class="token punctuation">.</span><span class="token generic-method"><span class="token function">AddSingleton</span><span class="token generic class-name"><span class="token punctuation">&lt;</span>DataLoaderDocumentListener<span class="token punctuation">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
80-
<ol start="3">
78+
<div class="gatsby-highlight" data-language="csharp"><pre class="language-csharp"><code class="language-csharp">services<span class="token punctuation">.</span><span class="token function">AddGraphQL</span><span class="token punctuation">(</span>b <span class="token operator">=></span> b
79+
<span class="token punctuation">.</span><span class="token function">AddDataLoader</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
80+
<span class="token comment">// other configurations</span>
81+
<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
82+
<ol start="2">
8183
<li>Hook up your GraphQL schema to your IoC container.</li>
8284
</ol>
8385
<div class="gatsby-highlight" data-language="csharp"><pre class="language-csharp"><code class="language-csharp"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MySchema</span> <span class="token punctuation">:</span> <span class="token type-list"><span class="token class-name">Schema</span></span>
@@ -87,7 +89,7 @@ <h2 id="setup" style="position:relative;"><a href="#setup" aria-label="setup per
8789
<span class="token punctuation">}</span>
8890
<span class="token punctuation">}</span></code></pre></div>
8991
<div class="gatsby-highlight" data-language="csharp"><pre class="language-csharp"><code class="language-csharp">services<span class="token punctuation">.</span><span class="token generic-method"><span class="token function">AddSingleton</span><span class="token generic class-name"><span class="token punctuation">&lt;</span>MySchema<span class="token punctuation">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre></div>
90-
<ol start="4">
92+
<ol start="3">
9193
<li>Add the <code class="language-text">DataLoaderDocumentListener</code> to the <code class="language-text">DocumentExecuter</code>.</li>
9294
</ol>
9395
<div class="gatsby-highlight" data-language="csharp"><pre class="language-csharp"><code class="language-csharp"><span class="token class-name"><span class="token keyword">var</span></span> listener <span class="token operator">=</span> Services<span class="token punctuation">.</span><span class="token generic-method"><span class="token function">GetRequiredService</span><span class="token generic class-name"><span class="token punctuation">&lt;</span>DataLoaderDocumentListener<span class="token punctuation">></span></span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

page-data/docs/guides/dataloader/page-data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)