<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nguyễn Minh Đức</title>
    <description>The latest articles on DEV Community by Nguyễn Minh Đức (@ducit247).</description>
    <link>https://dev.to/ducit247</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4062140%2Fb9dbd64a-c3d7-4f41-9656-b796f8caf1bf.jpg</url>
      <title>DEV Community: Nguyễn Minh Đức</title>
      <link>https://dev.to/ducit247</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ducit247"/>
    <language>en</language>
    <item>
      <title>FieldCount vs ResolverCount: a small but important distinction for GraphQL query cost in gqlgen</title>
      <dc:creator>Nguyễn Minh Đức</dc:creator>
      <pubDate>Tue, 04 Aug 2026 09:22:09 +0000</pubDate>
      <link>https://dev.to/ducit247/fieldcount-vs-resolvercount-a-small-but-important-distinction-for-graphql-query-cost-in-gqlgen-25pm</link>
      <guid>https://dev.to/ducit247/fieldcount-vs-resolvercount-a-small-but-important-distinction-for-graphql-query-cost-in-gqlgen-25pm</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;gqlgen has &lt;code&gt;extension.ComplexityLimit&lt;/code&gt; and there's a third-party depth-limit extension too, but&lt;br&gt;
both only reject — they abort the request once a threshold is crossed. That's useful, but it&lt;br&gt;
gives you zero visibility into what your traffic actually looks like before you pick those&lt;br&gt;
limits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three numbers, no rejecting
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;gqlgen-query-analyzer&lt;/code&gt; is a small gqlgen extension that looks at the shape of each incoming&lt;br&gt;
query and reports three numbers, without ever blocking the request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Depth&lt;/strong&gt; — how deeply nested the query is&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FieldCount&lt;/strong&gt; — total number of fields selected&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ResolverCount&lt;/strong&gt; — only the fields that actually trigger a separate backend call&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The last one is the interesting part. Take a query like &lt;code&gt;orders { id total salesman { fullname } }&lt;/code&gt;.&lt;br&gt;
That's 5 fields total, nested 3 levels deep — but only 2 real resolver calls: &lt;code&gt;orders&lt;/code&gt; and&lt;br&gt;
&lt;code&gt;salesman&lt;/code&gt;. &lt;code&gt;fullname&lt;/code&gt; is just reading a property off the &lt;code&gt;salesman&lt;/code&gt; object that's already been&lt;br&gt;
fetched, not a new DB/gRPC/DataLoader call. FieldCount treats all 5 the same; ResolverCount tells&lt;br&gt;
you it's really only 2 backend calls.&lt;/p&gt;

&lt;p&gt;It's purely static — just looking at the query text, no runtime data — so it doesn't know about&lt;br&gt;
pagination (&lt;code&gt;first&lt;/code&gt;/&lt;code&gt;last&lt;/code&gt; args) or how many items a list actually returns.&lt;/p&gt;

&lt;h2&gt;
  
  
  It reports, it doesn't block
&lt;/h2&gt;

&lt;p&gt;Everything goes out via Prometheus metrics, OpenTelemetry span attributes, and optionally the&lt;br&gt;
response's &lt;code&gt;extensions&lt;/code&gt; field. Even past every configured threshold, the request still runs and&lt;br&gt;
returns real data — the goal is to see your traffic shape first, then decide where to draw hard&lt;br&gt;
limits with something like &lt;code&gt;ComplexityLimit&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it in
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;srv&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewDefaultServer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;es&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;srv&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryanalysis&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;New&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queryanalysis&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Config&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;MaxDepth&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;         &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;MaxFieldCount&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;    &lt;span class="m"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;MaxResolverCount&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ExposeInResponse&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One &lt;code&gt;Server.Use(...)&lt;/code&gt; call, nothing else changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Repo: &lt;a href="https://github.com/duc2407/gqlgen-query-analyzer" rel="noopener noreferrer"&gt;https://github.com/duc2407/gqlgen-query-analyzer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://pkg.go.dev/github.com/duc2407/gqlgen-query-analyzer" rel="noopener noreferrer"&gt;https://pkg.go.dev/github.com/duc2407/gqlgen-query-analyzer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MIT licensed, Go 1.23+, 95% test coverage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just shipped v1.0.0 — feedback welcome.&lt;/p&gt;

</description>
      <category>go</category>
      <category>graphql</category>
      <category>opensource</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
