<?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: Joel Marinho</title>
    <description>The latest articles on DEV Community by Joel Marinho (@joel2011140).</description>
    <link>https://dev.to/joel2011140</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%2F777600%2F160f5274-8c95-4156-9284-3b3337b3fdfa.jpeg</url>
      <title>DEV Community: Joel Marinho</title>
      <link>https://dev.to/joel2011140</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joel2011140"/>
    <language>en</language>
    <item>
      <title>How to Handle GraphQL with React Query: Adding Security Headers</title>
      <dc:creator>Joel Marinho</dc:creator>
      <pubDate>Thu, 13 Nov 2025 05:23:22 +0000</pubDate>
      <link>https://dev.to/joel2011140/how-to-handle-graphql-with-react-query-adding-security-headers-4gei</link>
      <guid>https://dev.to/joel2011140/how-to-handle-graphql-with-react-query-adding-security-headers-4gei</guid>
      <description>&lt;p&gt;Hey there! Welcome back! Hopefully, you’ve had a chance to read my previous article on handling GraphQL with React Query. If not, don’t worry! Here’s the link to catch up (&lt;a href="https://medium.com/@joeldeveloper2011140/how-to-integrate-react-query-with-graphql-for-efficient-caching-part-2-529744130836" rel="noopener noreferrer"&gt;https://medium.com/@joeldeveloper2011140/how-to-integrate-react-query-with-graphql-for-efficient-caching-part-2-529744130836&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;But wait, I realized I missed something important in that post. In real-world projects, security is everything. Whenever we interact with an API, we often need to provide authentication tokens or API keys in the headers, or maybe even add custom headers for specific actions. 😅&lt;/p&gt;

&lt;p&gt;So, to make sure you’re covered, here's how you can integrate security headers with graphql-request and react-query if you’re following along from the article: &lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Headers with graphql-request and React Query
&lt;/h2&gt;

&lt;p&gt;If you’ve already read my previous article, this will feel like a quick refresher. If not, no worries, let’s dive right in!&lt;/p&gt;

&lt;p&gt;First, let’s use the graphql-request library with react-query and inject headers such as an API key. Here’s a sample implementation for your useApiGetUsers hook:&lt;/p&gt;

&lt;p&gt;`import request from "graphql-request";&lt;br&gt;
import { useQuery } from "@tanstack/react-query";&lt;br&gt;
import { GRAPHQL_API_URL } from "../../../constants";&lt;br&gt;
import { GetUserSchema } from "./users.schema";&lt;/p&gt;

&lt;p&gt;interface IUseApiGetUsersParams {&lt;br&gt;
  search: string;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;interface IUseApiGetUserResponse {&lt;br&gt;
  User: {&lt;br&gt;
    about: string;&lt;br&gt;
    name: string;&lt;br&gt;
    id: number;&lt;br&gt;
    avatar: {&lt;br&gt;
      large: string;&lt;br&gt;
    };&lt;br&gt;
    siteUrl: string;&lt;br&gt;
  };&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export const useApiGetUsers = (searchItem: string = "") =&amp;gt; {&lt;br&gt;
  const { data: user, isLoading: isGettingUser } = useQuery({&lt;br&gt;
    queryKey: ["user", searchItem],&lt;br&gt;
    queryFn: async () =&amp;gt; {&lt;br&gt;
      const response = await request&amp;lt;&lt;br&gt;
        IUseApiGetUserResponse,&lt;br&gt;
        IUseApiGetUsersParams&lt;br&gt;
      &amp;gt;(&lt;br&gt;
        GRAPHQL_API_URL,&lt;br&gt;
        GetUserSchema,&lt;br&gt;
        { search: searchItem },&lt;br&gt;
        { "api-key": "bla bla bla bla" }  // Here's the key!&lt;br&gt;
      );&lt;br&gt;
      return response?.User;&lt;br&gt;
    },&lt;br&gt;
  });&lt;/p&gt;

&lt;p&gt;return {&lt;br&gt;
    user,&lt;br&gt;
    isGettingUser,&lt;br&gt;
  };&lt;br&gt;
}; `&lt;/p&gt;

&lt;p&gt;Now, you can send custom headers (like your api-key) to your GraphQL API when making requests. Boom—just like that, you've added security to your GraphQL calls. 🚀&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduce Duplication with a GraphQL Client
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about reducing code duplication. If you’re working on a larger project, you might want to create a GraphQL client that you can reuse across your app. This will prevent you from having to manually add headers every time you make a request.&lt;/p&gt;

&lt;p&gt;I could have gone the extra mile and created a reusable GraphQLClient in this demo, but I kept it simple for now. But hey, if you want to keep your code neat and DRY (Don’t Repeat Yourself, folks), here’s how you can set up a GraphQL client:&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
import { GraphQLClient } from "graphql-request";&lt;/p&gt;

&lt;p&gt;const graphQlClient = new GraphQLClient(GRAPHQL_API_URL, {&lt;br&gt;
  headers: {&lt;br&gt;
    "api-key": "bla bla bla", // Put your API key here&lt;br&gt;
  },&lt;br&gt;
}); &lt;br&gt;
`&lt;br&gt;
Now, instead of adding headers manually to each graphql-request, you can reuse the graphQlClient throughout your project. Just call it wherever you need a request, and boom, no more repeating code! 🙌&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping It Up
&lt;/h2&gt;

&lt;p&gt;Alright, folks, that’s all for today! You've learned how to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add custom headers like api-key to your GraphQL requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep things DRY by using a reusable GraphQLClient.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before I sign off, I want to leave you with a quick tip: Always check out the GraphQLClient itself for more options and parameters—it’s like the Swiss Army knife of GraphQL requests! 🔪✨&lt;/p&gt;

&lt;p&gt;Thanks for reading, and happy coding! Now go and make your GraphQL queries secure and efficient—because who needs security flaws in their app, right? 😜&lt;/p&gt;

&lt;p&gt;That’s all folks! 🎉&lt;/p&gt;

</description>
      <category>react</category>
      <category>graphql</category>
    </item>
    <item>
      <title>🚀 Exploring Microfrontends with Webpack Module Federation</title>
      <dc:creator>Joel Marinho</dc:creator>
      <pubDate>Thu, 13 Nov 2025 05:17:50 +0000</pubDate>
      <link>https://dev.to/joel2011140/exploring-microfrontends-with-webpack-module-federation-1g63</link>
      <guid>https://dev.to/joel2011140/exploring-microfrontends-with-webpack-module-federation-1g63</guid>
      <description>&lt;p&gt;Recently, I built a small project using Webpack Module Federation — a host app dynamically loading a remote React component (profile) — to better understand how microfrontends actually work in practice.&lt;/p&gt;

&lt;p&gt;🧩 What Are Microfrontends?&lt;/p&gt;

&lt;p&gt;Microfrontends bring the microservices mindset to the frontend.&lt;br&gt;
Each part of the UI is an independent application — owned by separate teams, deployed separately, and composed into one seamless experience.&lt;/p&gt;

&lt;p&gt;This architecture enables scalability, autonomy, and faster releases, especially in large organizations.&lt;/p&gt;

&lt;p&gt;⚙️ Common Approaches&lt;/p&gt;

&lt;p&gt;Module Federation (Webpack 5+)&lt;br&gt;
→ Dynamically loads remote modules at runtime, sharing dependencies like React — no rebuilds or iframes.&lt;/p&gt;

&lt;p&gt;Multi-Zone Architecture (Next.js)&lt;br&gt;
→ Multiple Next.js apps stitched together through routing, ideal for domain-based segmentation.&lt;/p&gt;

&lt;p&gt;Internal NPM Packages&lt;br&gt;
→ Each microfrontend is versioned and shared as a private package — great control, but tighter coupling.&lt;/p&gt;

&lt;p&gt;Iframes (the classic)&lt;br&gt;
→ Offers full isolation and security, though with limited inter-app communication and styling flexibility.&lt;/p&gt;

&lt;p&gt;🧠 How Remotes Work&lt;/p&gt;

&lt;p&gt;A remote app exposes modules like this (for example the profile):&lt;/p&gt;

&lt;p&gt;new ModuleFederationPlugin({&lt;br&gt;
 name: "profile",&lt;br&gt;
 filename: "remoteEntry.js",&lt;br&gt;
 exposes: { "./Profile": "./src/Profile.tsx" },&lt;br&gt;
});&lt;/p&gt;

&lt;p&gt;And the host dynamically loads it:&lt;/p&gt;

&lt;p&gt;new ModuleFederationPlugin({&lt;br&gt;
 name: "container",&lt;br&gt;
 remotes: {&lt;br&gt;
 profile: "profile@&lt;a href="http://localhost:3001/remoteEntry.js" rel="noopener noreferrer"&gt;http://localhost:3001/remoteEntry.js&lt;/a&gt;",&lt;br&gt;
 },&lt;br&gt;
})&lt;br&gt;
const Profile = React.lazy(() =&amp;gt; import("profile/Profile"));&lt;/p&gt;

&lt;p&gt;Webpack fetches remoteEntry.js, shares the React instance, and mounts the component — all at runtime.&lt;/p&gt;

&lt;p&gt;⚖️ Trade-Offs to Consider&lt;/p&gt;

&lt;p&gt;Deployment orchestration: independent deploys give flexibility, but require careful version control and CI/CD coordination.&lt;/p&gt;

&lt;p&gt;Shared session state: managing auth and context across apps often needs shared cookies, tokens, or an API gateway.&lt;/p&gt;

&lt;p&gt;Performance: multiple bundles add overhead — smart caching and lazy loading help keep things fast.&lt;/p&gt;

&lt;p&gt;Consistency: design systems and routing conventions must be aligned across teams to avoid fragmentation.&lt;/p&gt;

&lt;p&gt;Microfrontends aren’t a silver bullet — but they’re powerful when autonomy, scale, and parallel development matter.&lt;/p&gt;

&lt;p&gt;If you’d like to see it in action, here’s the repos :&lt;br&gt;
🔗 Host (Container): &lt;a href="https://github.com/joel2011140/mfe-container" rel="noopener noreferrer"&gt;https://github.com/joel2011140/mfe-container&lt;/a&gt;&lt;br&gt;
🔗 Remote (Profile): &lt;a href="https://github.com/joel2011140/mfe-profile" rel="noopener noreferrer"&gt;https://github.com/joel2011140/mfe-profile&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’d love your feedback — how are you handling deployment, communication, or shared state in your microfrontend setups?&lt;/p&gt;

&lt;h1&gt;
  
  
  frontend #microfrontends #reactjs #webdevelopment #javascript #modulefederation #webpack #softwarearchitecture #scalability #techcommunity #developerexperience #webapps
&lt;/h1&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>react</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
