<?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: Mateo Díaz López</title>
    <description>The latest articles on DEV Community by Mateo Díaz López (@mateodiaz).</description>
    <link>https://dev.to/mateodiaz</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3713163%2Faf27f3ab-cef7-4638-bc67-1cccbd8b41ba.jpg</url>
      <title>DEV Community: Mateo Díaz López</title>
      <link>https://dev.to/mateodiaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mateodiaz"/>
    <language>en</language>
    <item>
      <title>Introducing graphql-safe-guards: predictable GraphQL query safety</title>
      <dc:creator>Mateo Díaz López</dc:creator>
      <pubDate>Tue, 20 Jan 2026 19:26:30 +0000</pubDate>
      <link>https://dev.to/mateodiaz/introducing-graphql-safe-guards-predictable-graphql-query-safety-3438</link>
      <guid>https://dev.to/mateodiaz/introducing-graphql-safe-guards-predictable-graphql-query-safety-3438</guid>
      <description>&lt;p&gt;I just released graphql-safe-guards, a tiny open-source utility that helps protect GraphQL APIs from expensive queries.&lt;/p&gt;

&lt;p&gt;It combines two essential protections:&lt;/p&gt;

&lt;p&gt;Query depth limiting&lt;/p&gt;

&lt;p&gt;Query complexity validation&lt;/p&gt;

&lt;p&gt;Unlike directive-based or runtime plugins, it relies on native GraphQL validation rules, making it:&lt;/p&gt;

&lt;p&gt;Framework-agnostic&lt;/p&gt;

&lt;p&gt;Predictable&lt;/p&gt;

&lt;p&gt;Zero runtime overhead&lt;/p&gt;

&lt;p&gt;If you’re running GraphQL in production and want simple, portable query safety, this might help.&lt;/p&gt;

&lt;p&gt;For those interested, here’s the npm package and source code 👇&lt;br&gt;
npm: &lt;a href="https://www.npmjs.com/package/graphql-safe-guards" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/graphql-safe-guards&lt;/a&gt;&lt;br&gt;
GitHub: &lt;a href="https://github.com/Mateodiaz401/graphql-safe-guards" rel="noopener noreferrer"&gt;https://github.com/Mateodiaz401/graphql-safe-guards&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>javascript</category>
      <category>security</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Introducing graphql-complexity-validation</title>
      <dc:creator>Mateo Díaz López</dc:creator>
      <pubDate>Mon, 19 Jan 2026 18:39:56 +0000</pubDate>
      <link>https://dev.to/mateodiaz/introducing-graphql-complexity-validation-5d6d</link>
      <guid>https://dev.to/mateodiaz/introducing-graphql-complexity-validation-5d6d</guid>
      <description>&lt;p&gt;GraphQL is powerful, but without limits, complex queries can easily overwhelm your server.&lt;/p&gt;

&lt;p&gt;That’s why I built &lt;strong&gt;graphql-complexity-validation&lt;/strong&gt;:&lt;br&gt;
a lightweight, framework-agnostic GraphQL validation rule that limits query complexity using native GraphQL validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✨ Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Zero runtime dependencies&lt;/li&gt;
&lt;li&gt;Fully typed (TypeScript)&lt;/li&gt;
&lt;li&gt;Supports fragments &amp;amp; inline fragments&lt;/li&gt;
&lt;li&gt;Introspection ignored by default&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Works with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apollo Server&lt;/li&gt;
&lt;li&gt;GraphQL Yoga&lt;/li&gt;
&lt;li&gt;Envelop&lt;/li&gt;
&lt;li&gt;NestJS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  📦 Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;graphql-complexity-validation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🧠 How it works
&lt;/h2&gt;

&lt;p&gt;Each field has a cost (default: 1).&lt;br&gt;
Nested fields accumulate cost recursively.&lt;br&gt;
If the total exceeds the configured maximum, validation fails.&lt;/p&gt;

&lt;p&gt;No directives.&lt;br&gt;
No schema traversal.&lt;br&gt;
No framework lock-in.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧪 Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;createComplexityLimitRule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;maxComplexity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fieldCosts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&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;h2&gt;
  
  
  🔗 Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;npm: &lt;a href="https://www.npmjs.com/package/graphql-complexity-validation" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/graphql-complexity-validation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/Mateodiaz401/graphql-complexity-validation" rel="noopener noreferrer"&gt;https://github.com/Mateodiaz401/graphql-complexity-validation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feedback, issues, and contributions are welcome 🙌&lt;br&gt;
If you find it useful, please consider starring the repo ⭐&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>showdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Limiting GraphQL Query Depth the Right Way</title>
      <dc:creator>Mateo Díaz López</dc:creator>
      <pubDate>Thu, 15 Jan 2026 19:20:07 +0000</pubDate>
      <link>https://dev.to/mateodiaz/limiting-graphql-query-depth-the-right-way-1h65</link>
      <guid>https://dev.to/mateodiaz/limiting-graphql-query-depth-the-right-way-1h65</guid>
      <description>&lt;p&gt;Introducing graphql-safe-depth&lt;/p&gt;

&lt;p&gt;GraphQL is powerful, flexible, and expressive — but that flexibility can also become a liability if queries are not properly constrained.&lt;/p&gt;

&lt;p&gt;One common attack vector (or accidental performance issue) is overly deep queries that cause excessive resolver execution, memory usage, or even denial-of-service scenarios.&lt;/p&gt;

&lt;p&gt;In this post, I’ll explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why deep GraphQL queries are a real problem&lt;/li&gt;
&lt;li&gt;Why many existing depth-limit solutions fall short&lt;/li&gt;
&lt;li&gt;How graphql-safe-depth approaches the problem differently&lt;/li&gt;
&lt;li&gt;How to use it in Apollo Server and NestJS&lt;/li&gt;
&lt;li&gt;When and how to combine it with other security measures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚨 &lt;strong&gt;The problem: Deep GraphQL queries&lt;/strong&gt;&lt;br&gt;
Consider the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  user {
    posts {
      comments {
        author {
          profile {
            avatar {
              url
            }
          }
        }
      }
    }
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this looks harmless.&lt;br&gt;
But under the hood, this can:&lt;br&gt;
Trigger many resolver executions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cause N+1 query explosions&lt;/li&gt;
&lt;li&gt;Consume significant CPU and memory&lt;/li&gt;
&lt;li&gt;Become a DoS vector, intentionally or not&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GraphQL does not impose any default depth or complexity limits.&lt;br&gt;
That responsibility belongs to the server.&lt;/p&gt;

&lt;p&gt;🤔 &lt;strong&gt;Why existing solutions fall short&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are existing GraphQL depth-limit libraries, but many of them have issues such as:&lt;/p&gt;

&lt;p&gt;❌&lt;strong&gt;Counting fields instead of execution depth&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some libraries count the total number of fields rather than the deepest execution path, which leads to false positives or confusing behavior.&lt;/p&gt;

&lt;p&gt;❌ &lt;strong&gt;Breaking introspection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GraphQL introspection queries (__schema, __type, __typename) are often deep by nature.&lt;br&gt;
Blocking or miscounting them breaks tools like GraphQL Playground or Apollo Studio.&lt;/p&gt;

&lt;p&gt;❌ &lt;strong&gt;Hard to reason about&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some implementations are difficult to customize, debug, or explain to a team.&lt;br&gt;
I wanted something simpler, predictable, and easy to trust.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;The approach: graphql-safe-depth&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;graphql-safe-depth is a lightweight GraphQL validation rule focused on one thing:&lt;br&gt;
Limiting real execution depth — not field count.&lt;br&gt;
Design goals&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 Measure the deepest resolver path&lt;/li&gt;
&lt;li&gt;🔍 Ignore introspection fields by default&lt;/li&gt;
&lt;li&gt;🧩 Fully support fragments&lt;/li&gt;
&lt;li&gt;⚡ Zero runtime dependencies&lt;/li&gt;
&lt;li&gt;🛠 TypeScript-first, JavaScript-friendly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🔧 How graphql-safe-depth works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At a high level:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The library hooks into GraphQL’s validation phase&lt;/li&gt;
&lt;li&gt;It traverses the query AST&lt;/li&gt;
&lt;li&gt;It calculates depth based on nested field selections&lt;/li&gt;
&lt;li&gt;It tracks the maximum execution depth&lt;/li&gt;
&lt;li&gt;If the depth exceeds maxDepth, the query is rejected before execution&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Depth calculation example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ Valid query (depth = 3)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  user {
    profile {
      name
    }
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;❌ Invalid query (depth = 4)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  user {
    profile {
      address {
        city
      }
    }
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the deepest execution path matters — not the total number of fields.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚀 Usage examples&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apollo Server (Node.js)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ApolloServer } from "apollo-server";
import { createDepthLimitRule } from "graphql-safe-depth";

const server = new ApolloServer({
  typeDefs,
  resolvers,
  validationRules: [
    createDepthLimitRule({ maxDepth: 3 }),
  ],
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apollo Server (NestJS)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createDepthLimitRule } from "graphql-safe-depth";

GraphQLModule.forRoot({
  autoSchemaFile: true,
  validationRules: [
    createDepthLimitRule({ maxDepth: 3 }),
  ],
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;⚙️ Configuration options&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createDepthLimitRule({
  maxDepth: number;
  ignoreIntrospection?: boolean;
  message?: (depth: number, maxDepth: number) =&amp;gt; string;
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;maxDepth (required)&lt;/p&gt;

&lt;p&gt;The maximum allowed execution depth.&lt;br&gt;
&lt;code&gt;reateDepthLimitRule({ maxDepth: 3 });&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;ignoreIntrospection (default: true)&lt;/p&gt;

&lt;p&gt;Safely ignores GraphQL introspection fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createDepthLimitRule({
  maxDepth: 3,
  ignoreIntrospection: false,
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;message (optional)&lt;/p&gt;

&lt;p&gt;Customize the validation error message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createDepthLimitRule({
  maxDepth: 3,
  message: (depth, max) =&amp;gt;
    `Query depth ${depth} exceeds the allowed maximum of ${max}`,
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔐 Security considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Depth limiting is not a silver bullet.&lt;br&gt;
For production GraphQL APIs, it should be combined with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Query complexity limits&lt;/li&gt;
&lt;li&gt;✅ Proper authentication &amp;amp; authorization&lt;/li&gt;
&lt;li&gt;✅ Rate limiting&lt;/li&gt;
&lt;li&gt;✅ Caching and batching (e.g. DataLoader)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;graphql-safe-depth focuses on doing one thing well — preventing dangerously deep queries in a predictable way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📦 Installation&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npm i graphql-safe-depth&lt;br&gt;
or&lt;br&gt;
yarn add graphql-safe-depth&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;🔗 Links&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GitHub repository&lt;br&gt;
👉 [&lt;a href="https://github.com/Mateodiaz401/graphql-safe-depth" rel="noopener noreferrer"&gt;https://github.com/Mateodiaz401/graphql-safe-depth&lt;/a&gt;]&lt;br&gt;
npm package&lt;br&gt;
👉 [&lt;a href="https://www.npmjs.com/package/graphql-safe-depth" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/graphql-safe-depth&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Final thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This library started as a learning exercise and evolved into a production-ready tool with a stable v1.0.0 release.&lt;/p&gt;

&lt;p&gt;If you’re running GraphQL in production and want a simple, predictable depth limit, I hope graphql-safe-depth helps.&lt;/p&gt;

&lt;p&gt;Feedback, issues, and contributions are very welcome 🙌&lt;/p&gt;

</description>
      <category>api</category>
      <category>javascript</category>
      <category>performance</category>
      <category>security</category>
    </item>
  </channel>
</rss>
