<?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: Ivan Grekhov</title>
    <description>The latest articles on DEV Community by Ivan Grekhov (@iagrekhovfronted).</description>
    <link>https://dev.to/iagrekhovfronted</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%2F3328216%2F10e3b7e2-3930-4523-ae28-1e7c02dff23e.png</url>
      <title>DEV Community: Ivan Grekhov</title>
      <link>https://dev.to/iagrekhovfronted</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iagrekhovfronted"/>
    <language>en</language>
    <item>
      <title>What Happens Before the Event Loop. Part 1</title>
      <dc:creator>Ivan Grekhov</dc:creator>
      <pubDate>Thu, 08 Jan 2026 20:13:13 +0000</pubDate>
      <link>https://dev.to/iagrekhovfronted/what-happens-before-the-event-loop-5egj</link>
      <guid>https://dev.to/iagrekhovfronted/what-happens-before-the-event-loop-5egj</guid>
      <description>&lt;p&gt;JavaScript code is not executed natively by an engine at the moment a task appears in the call stack. Most articles focus on how the Event Loop works, leaving out the path that developer-written instructions take before reaching that point. As a result, concepts such as scope, closures, the Temporal Dead Zone, and other execution details are often memorized as a kind of “technomagic”.&lt;/p&gt;

&lt;p&gt;In this short series of posts, I want to break down these aspects by tracing the path from source code input to actual execution. To avoid diving too deeply into the implementation details of specific engines (V8, SpiderMonkey, JavaScriptCore, etc.), the discussion will stay at the abstraction level defined by the ECMAScript 262 specification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Execution Stages
&lt;/h2&gt;

&lt;p&gt;The specification intentionally does not describe JavaScript execution as a linear sequence of steps—implementation details are left to engine authors. Nevertheless, the spec (along with practical knowledge of engine implementations) allows us to identify four conditional stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Determination of the execution environment: Host, Agent, Real&lt;/li&gt;
&lt;li&gt;Parsing of the source code&lt;/li&gt;
&lt;li&gt;Creation of meta-objects: Module Record / Script Record&lt;/li&gt;
&lt;li&gt;Program execution
4.1. Execution Preparation Phase
4.2. Instruction Execution Phase&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkawnaslnid2ybrucj9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftkawnaslnid2ybrucj9k.png" alt=" " width="730" height="996"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Stage 1. Determination of the Execution Environment
&lt;/h2&gt;

&lt;p&gt;Developer instructions (source text) cannot be executed in a vacuum. The specification defines three key layers of the execution environment:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Host — the external program in which JavaScript code is executed: browsers, Node.js, Deno, etc.&lt;/li&gt;
&lt;li&gt;Agent — an isolated part of the execution environment (independent from other Agents) that has its own Execution Context Stack and Running Execution Context. Examples of agents include a browser tab, a Web Worker, or an iframe.&lt;/li&gt;
&lt;li&gt;Realm — a logical entity that defines the global object, global methods, and global variables, and is responsible for creating the Global Execution Context. In the V8 engine implementation, this corresponds to the v8::Context class (in C++).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Understanding the structure of the execution environment and its isolation model explains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the absence of race conditions between tabs in the same browser;&lt;/li&gt;
&lt;li&gt;why a Worker has no access to the global object and variables of the main application;&lt;/li&gt;
&lt;li&gt;the isolation of overridden global JavaScript methods within a single Host.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://262.ecma-international.org/#sec-hosts-and-implementations" rel="noopener noreferrer"&gt;Host&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://262.ecma-international.org/#agent" rel="noopener noreferrer"&gt;Agent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://262.ecma-international.org/#sec-code-realms" rel="noopener noreferrer"&gt;Realm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://v8.github.io/api/head/classv8_1_1Context.html" rel="noopener noreferrer"&gt;V8::Context&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ecmascript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>From Chaos to Order in the Frontend</title>
      <dc:creator>Ivan Grekhov</dc:creator>
      <pubDate>Tue, 23 Dec 2025 14:43:43 +0000</pubDate>
      <link>https://dev.to/iagrekhovfronted/from-chaos-to-order-in-the-frontend-31np</link>
      <guid>https://dev.to/iagrekhovfronted/from-chaos-to-order-in-the-frontend-31np</guid>
      <description>&lt;p&gt;On large projects, a frontend without a single source of truth for data types quickly turns into a nightmare. Especially when the product isn’t in production yet and the backend and analytics evolve faster than button colors.&lt;/p&gt;

&lt;p&gt;One architectural decision significantly simplified the team’s workflow and reduced errors and manual debugging: &lt;strong&gt;type generation&lt;/strong&gt; using &lt;code&gt;graphql-codegen&lt;/code&gt; combined with a strict backend deployment workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it worked
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Backend updates GraphQL schemas for microservices.&lt;/li&gt;
&lt;li&gt;Frontend pulls the latest schemas, created query/mutation and regenerates types.&lt;/li&gt;
&lt;li&gt;Any breaking changes are caught before the frontend build.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach allowed us to detect all mismatches between backend queries and responses at &lt;strong&gt;frontend build time&lt;/strong&gt;, long before they reached runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it created
&lt;/h2&gt;

&lt;p&gt;To integrate type generation, you need to add the following dependencies to your project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;graphql-codegen/cli&lt;/li&gt;
&lt;li&gt;graphql-codegen/typescript&lt;/li&gt;
&lt;li&gt;graphql-codegen/typescript-document-nodes&lt;/li&gt;
&lt;li&gt;graphql-codegen/typescript-operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Type generation and updates are configured via a YAML file for GraphQL Code Generator.&lt;br&gt;
A typical setup for generating types from a local schema looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Should existing files be overwritten after generation&lt;/span&gt;
&lt;span class="na"&gt;overwrite&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;generates&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Path to the generated output&lt;/span&gt;
  &lt;span class="na"&gt;src/generated/schema.graphql.ts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Path to the GraphQL schema&lt;/span&gt;
    &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./graphql-schema/schema.graphql&lt;/span&gt;
    &lt;span class="c1"&gt;# GraphQL documents (queries/mutations) to parse in the project&lt;/span&gt;
    &lt;span class="na"&gt;documents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;src/**/*.graphql&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript-operations&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript-document-nodes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For generating types based on introspection queries, the setup is very similar. You just need to provide the URL of the GraphQL endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;overwrite&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;generates&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;src/generated/introspection.graphql.ts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# GraphQL endpoint URL&lt;/span&gt;
    &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://localhost:4000/graphql"&lt;/span&gt;
    &lt;span class="na"&gt;documents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;src/**/*.graphql"&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript-operations&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;typescript-document-nodes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running the Generation
&lt;/h2&gt;

&lt;p&gt;For convenience, you can define scripts in package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"codegen:schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npx graphql-codegen --config codegen-schema.yml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"codegen:introspection"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npx graphql-codegen --config codegen-introspection.yml"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When writing queries or mutations in code, it’s convenient to define the request body as a variable and type it using the generated types. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="c"&gt;# GraphQL Query&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GetOpportunities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;GetOpportunitiesRequestInput&lt;/span&gt;&lt;span class="p"&gt;!)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;opportunities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;statusCode&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;contractNumber&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;creationDate&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Type-safe variables&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GetOpportunitiesThemesQueryVariables&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;providerId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;test1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;keycloakUserId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;test2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Query using your Apollo service (example from my project)&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apollo&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;watchQueryWithService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GetOpportunitiesThemesQuery&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accreditationService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GetOpportunitiesThemes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;variables&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;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using GraphQL Codegen and a strict backend deployment workflow allows frontend teams to stay in sync with backend changes, catch mismatches at build time, and significantly reduce manual debugging.&lt;/p&gt;

&lt;p&gt;This approach is applicable for both GraphQL SDL and introspection-based workflows, and it scales well for projects with multiple microservices.&lt;/p&gt;

&lt;p&gt;Happy to hear your thoughts or discuss alternative approaches — feel free to try the setup in your own project!&lt;/p&gt;

&lt;h2&gt;
  
  
  Github
&lt;/h2&gt;

&lt;p&gt;I’ve prepared a repository where you can spin up a backend and experiment with automatic type generation using &lt;strong&gt;GraphQL introspection&lt;/strong&gt; and &lt;strong&gt;GraphQL SDL&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/IAGrekhovFronted/Type-Safe-Angular-Graphql" rel="noopener noreferrer"&gt;https://github.com/IAGrekhovFronted/Type-Safe-Angular-Graphql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also check a similar approach for &lt;strong&gt;client and type generation over REST&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
The stack is different (&lt;strong&gt;.NET + Next.js&lt;/strong&gt;), but the core idea is very similar:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/IAGrekhovFronted/Healt-Nutrition-Test-Project" rel="noopener noreferrer"&gt;https://github.com/IAGrekhovFronted/Healt-Nutrition-Test-Project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hope this approach or the examples will be useful — happy to hear your thoughts or discuss alternatives.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>graphql</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
