<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Francesco Venica on Medium]]></title>
        <description><![CDATA[Stories by Francesco Venica on Medium]]></description>
        <link>https://medium.com/@FrancescoVenica?source=rss-170c6e08d181------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*04bCI9BnKJCfHYeT.jpg</url>
            <title>Stories by Francesco Venica on Medium</title>
            <link>https://medium.com/@FrancescoVenica?source=rss-170c6e08d181------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:13:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@FrancescoVenica/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An easy way to build frontend]]></title>
            <link>https://medium.com/@FrancescoVenica/an-easy-way-to-build-frontend-a7801466f029?source=rss-170c6e08d181------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7801466f029</guid>
            <category><![CDATA[css-modules]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Francesco Venica]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 15:25:14 GMT</pubDate>
            <atom:updated>2025-06-29T19:19:53.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aMojrnffnmKolQokxmMVXg.png" /></figure><p>In my experience as full-stack developer I worked with multiple frontend styles: a single css/scss file, css/scss module, css libraries similar to Tailwind and styled-component (both at build time &amp; run time), I spent ages converting projects from one style to the other without finding anything that I really liked.</p><p>I wanted to go back writing simple scss so that I can use whatever framework I want, but I also wanted to have the possibility to create React components that accept responsive properties to make my life easier, reuse components and keep the css as slim as possible while keeping also the build time as fast as possible. The solution I’ve found is to go back to scss module, but with a small utility that helps me creating reusable component.</p><p>You can find this utility here:<br><a href="https://www.npmjs.com/package/@vfcoding/css-module-classname">https://www.npmjs.com/package/@vfcoding/css-module-classname</a></p><p>Here is how the utility works, let’s create a simple component with these props:</p><pre>import { ResponsiveProp } from &quot;@vfcoding/module-css-classes&quot;;<br><br>interface BaseProps {<br>  children: React.ReactNode | React.ReactNode[];<br>  className?: string;<br>  visibility?: ResponsiveProp&lt;&quot;visibility&quot;&gt;;<br>  display?: ResponsiveProp&lt;&quot;display&quot;&gt;;<br>  padding?: ResponsiveProp&lt;&quot;padding&quot;&gt;;<br>  margin?: ResponsiveProp&lt;&quot;margin&quot;&gt;;<br>  style?: CSSProperties;<br>}</pre><p>where <strong>ResponsiveProp</strong> is something like this:</p><pre>export type Breakpoints = &quot;xs&quot; | &quot;sm&quot; | &quot;md&quot; | &quot;lg&quot; | &quot;xl&quot;;<br><br>export type ResponsiveProp&lt;K extends keyof CSSProperties&gt; =<br>  | CSSProperties[K]<br>  | Partial&lt;Record&lt;Breakpoints, CSSProperties[K]&gt;&gt;;</pre><p>this is our component:</p><pre>import { buildClassName } from &quot;@vfcoding/module-css-classes&quot;;<br>import styles from &quot;./styles.module.scss&quot;;<br><br>export function Base(props: BaseProps) {<br>  const { children, className, style } = props;<br><br>  const { classes, vars } = buildClassName(<br>    styles,<br>    { display: props.display, visibility: props.visibility },<br>    { padding: props.padding, margin: props.margin },<br>  );<br><br>  return (<br>    &lt;div className={classNames(styles.base, ...classes, className)} style={{ ...vars, ...style }}&gt;<br>      {children}<br>    &lt;/div&gt;<br>  );<br>}</pre><p>and this is our <strong>styles.module.scss</strong>:</p><pre>.base {<br>  @each $size, $breakpoint in mixins.$breakpoints {<br>    @media (min-width: #{$breakpoint}) {<br>      &amp;.margin-#{$size} {<br>        margin: var(--margin-#{$size}, 0);<br>      }<br><br>      &amp;.padding-#{$size} {<br>        padding: var(--padding-#{$size}, 0);<br>      }<br><br>      .display-block-#{$size} {<br>        display: block;<br>      }<br><br>      .display-flex-#{$size} {<br>        display: flex;<br>      }<br><br>      .display-inline-#{$size}-block {<br>        display: inline-block;<br>      }<br>    }<br>  }<br><br>  &amp;.visibility-hidden {<br>    visibility: hidden;<br>  }<br><br>  &amp;.visibility-visible {<br>    visibility: visible;<br>  }<br>}</pre><p>You can now use the component like any other react component:</p><pre>&lt;Base<br>    visibility=&quot;visible&quot;<br>    display={{ xs: &quot;flex&quot;, md: &quot;block&quot; }}<br>    padding={{ xs: &quot;0.5rem&quot;, md: &quot;1rem&quot; }}<br>    margin={{ xs: &quot;0.5rem&quot;, md: &quot;1rem&quot; }}<br>&gt;<br>...<br>&lt;/Base&gt;</pre><h3><strong>The buildClassName</strong></h3><p>How does the <strong>buildClassName</strong> works? It is very simple, the first argument is the css module file, the second argument are the static properties while the last argument are the dynamic variables.</p><p>When you pass a static variable like:</p><pre>{ visibility: props.visibility}</pre><p>where <strong>props.visibility</strong> can be <strong>hidden | visible | etc…,</strong> you must create a class for each property in the scss file with this format:</p><pre>.visibility-hidden { visibility: hidden; }<br>.visibility-visible { visibility: visible; }</pre><p>the <strong>buildClassName</strong> uses this format <strong>{prop-name}-{prop-value}</strong> to find the class in the <strong>styles</strong> object, for example <strong>styles[“.visibility-{visible|hidden}”]</strong>, a similar approach is required for a responsive props, with the only difference that the <strong>buildClassName</strong> will append the breakpoint as well in the key <strong>{prop-name}-{prop-value}-{breakpoint}</strong>, so the scss should have this format:</p><pre>@each $size, $breakpoint in mixins.$breakpoints {<br>    @media (min-width: #{$breakpoint}) {<br>      .visibility-hidden-#{$size} {<br>        visibility: hidden;<br>      }<br><br>      .visibility-visible-#{$size} {<br>        visibility: visible;<br>      }<br>    }<br>  }</pre><p>The exact same approach works for the dynamic variables as well, so if you pass this object to the third argument of <strong>buildClassName</strong>:</p><pre>{ margin: props.margin }</pre><p>you need a css like this:</p><pre>  @each $size, $breakpoint in mixins.$breakpoints {<br>    @media (min-width: #{$breakpoint}) {<br>      &amp;.margin-#{$size} {<br>        margin: var(--margin-#{$size}, 0);<br>      }<br>    }<br>  }</pre><p>the <strong>buildClassName</strong> will find the right class <strong>.margin-{breakpoint}</strong> and it will return the right css variable <strong>— margin-{breakpoint}: {props.margin}</strong>. If the class is not found it will try to find it without the breakpoint.</p><p>You can then use these classes/vars returned by <strong>buildClassName</strong> in the component:</p><pre>className={classNames(classes)}<br>style={vars}</pre><h3><strong>Performance</strong></h3><p>I didn’t do any particular test on the performance, but what I did is to create a page with more the 1000 component that uses multiple static classes &amp; multiple dynamic variables and the result in lighthouse was between 98 &amp; 100 with the only warning on the high number of elements. There is a small computation work to build the classes but it shouldn’t be too expensive, or at least less work then library like emotion/styled-component.</p><p>I hope you find this article useful, this is not rocket science but I couldn’t find anything similar online and I think it is something nice to have.</p><p>The next step in my mind is to find a way to build the classes at build time to remove the runtime work, but this is something for the future!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7801466f029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Federation Schema With Postgraphile and “graphql-tools”]]></title>
            <link>https://medium.com/better-programming/lets-create-a-federation-schema-with-postgraphile-and-graphql-tools-3071fdae8141?source=rss-170c6e08d181------2</link>
            <guid isPermaLink="false">https://medium.com/p/3071fdae8141</guid>
            <category><![CDATA[graphql-federation]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Francesco Venica]]></dc:creator>
            <pubDate>Wed, 01 Feb 2023 19:45:43 GMT</pubDate>
            <atom:updated>2023-02-05T11:06:58.359Z</atom:updated>
            <content:encoded><![CDATA[<h4>A federation gateway</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5_MqPhxTjvOHsqv1pV1UaA.png" /></figure><p>A couple of years ago, I discovered <a href="https://www.graphile.org/postgraphile/">PostGraphile</a> and fell in love with it. This fantastic library allows you to create a GraphQL server based on a specific Postgres schema with just a few lines of code. It generates all the necessary resolvers for all CRUD operations for each table. You can also wrap any resolver if you need to add custom code, or extend the schema if you need something not driven by the database.</p><p>The only drawback I found with this library was the lack of support for Apollo Federation. However, while searching for an alternative, I discovered <a href="https://the-guild.dev/graphql/stitching/docs">this</a>.</p><p>With some boilerplate code, it is possible to create a single GraphQL schema by merging different schemas from different services. This is called schema-stitching. Let’s see how it works!</p><p>For this tutorial, we will use PostGraphile with an Express application. I’ll assume you are familiar with both of these libraries. If you are not familiar with PostGraphile, I suggest you take a look at their <a href="https://www.graphile.org/postgraphile/">documentation</a>.</p><p>We will create two different databases with two different schemas. The first schema will be used in the Account service:</p><pre>CREATE TABLE &quot;public&quot;.&quot;account&quot; (<br>    &quot;id&quot; int4 NOT NULL,<br>    &quot;name&quot; text NOT NULL,<br>    &quot;company_id&quot; int4,<br>    PRIMARY KEY (&quot;id&quot;)<br>);</pre><p>While the second schema will be used in the Company service:</p><pre>CREATE TABLE &quot;public&quot;.&quot;company&quot; (<br>    &quot;id&quot; int4 NOT NULL,<br>    &quot;name&quot; text NOT NULL,<br>    &quot;account_id&quot; int4,<br>    PRIMARY KEY (&quot;id&quot;)<br>);<br>CREATE TABLE &quot;public&quot;.&quot;project&quot; (<br>    &quot;id&quot; int4 NOT NULL DEFAULT nextval(&#39;project_id_seq&#39;::regclass),<br>    &quot;company_id&quot; int4,<br>    &quot;name&quot; text,<br>    PRIMARY KEY (&quot;id&quot;)<br>);<br>ALTER TABLE &quot;public&quot;.&quot;project&quot; ADD FOREIGN KEY (&quot;company_id&quot;) REFERENCES &quot;public&quot;.&quot;company&quot;(&quot;id&quot;);</pre><p>In this example, I will use one application to serve the two PostGraphile servers and another application to serve the gateway. In a real-world scenario, you would have three separate applications and implement roles/RLS to secure the database, but to keep things simple, I will just use two applications without any roles/RLS.</p><p>Once we have the databases up and running, we need to initialize the library:</p><pre>import { postgraphile } from &quot;postgraphile&quot;;<br>export const companyPostgraphile = postgraphile(companyPool, &quot;public&quot;, {<br>  ...config,<br>  graphiqlRoute: &quot;/graphiql-account&quot;,<br>  graphqlRoute: &quot;/account&quot;,<br>  appendPlugins: [],<br>});<br><br>export const accountPostgraphile = postgraphile(accountPool, &quot;public&quot;, {<br>  ...config,<br>  graphiqlRoute: &quot;/graphiql-company&quot;,<br>  graphqlRoute: &quot;/company&quot;,<br>  appendPlugins: [],<br>});</pre><p>Next, we need to use the library in our application.</p><pre>import express, { Request, Response, NextFunction } from &quot;express&quot;;<br>import { HttpError } from &quot;http-errors&quot;;<br>import bodyParser from &quot;body-parser&quot;;<br><br>import { companyPostgraphile, accountPostgraphile } from &quot;./postgraphile&quot;;<br><br>const app = express();<br><br>...<br><br>app.use(companyPostgraphile);<br>app.use(accountPostgraphile);<br><br>...<br><br>export default app;</pre><p>If you open the following links in the browser you are going to see a playground where you can create/update/delete/select entities in both services.</p><p>http://localhost:{THE_PORT_YOU_DEFIEND}/graphiql-company<br>http://localhost:{THE_PORT_YOU_DEFIEND}/graphiql-account</p><p>If you create a new company with a few projects, you can run a query like the following and get all the requested data without writing a single SQL query. Simple, right?</p><pre>query MyQuery {<br>  allCompanies {<br>    nodes {<br>      id<br>      name<br>      projectsByCompanyId {<br>        nodes {<br>          id<br>          name<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>We now have two services with two different schemas fully functional. The next step is to create the gateway that will serve these two schemas in a single endpoint. We will use graphql-yoga to create the server and @graphql-tools to stitch the schema and merge the types. Let’s create the GraphQL server:</p><pre>import waitOn from &quot;wait-on&quot;;<br>import { buildSchema, parse } from &quot;graphql&quot;;<br>import { stitchSchemas } from &quot;@graphql-tools/stitch&quot;;<br>import { createYoga, isAsyncIterable } from &quot;graphql-yoga&quot;;<br>import { buildHTTPExecutor } from &quot;@graphql-tools/executor-http&quot;;<br>import {<br>  federationToStitchingSDL,<br>  stitchingDirectives,<br>} from &quot;@graphql-tools/stitching-directives&quot;;<br>import { Executor } from &quot;@graphql-tools/utils&quot;;<br><br>const SDL_QUERY = parse(`<br>  query _service {<br>    _service {<br>      sdl<br>    }<br>  }<br>`);<br><br>async function fetchFederationSubschema(executor: Executor) {<br>  const result = await executor({ document: SDL_QUERY });<br>  if (isAsyncIterable(result)) {<br>    throw new Error(<br>      &quot;Executor returned an AsyncIterable, which is not supported&quot;<br>    );<br>  }<br><br>  const sdl = federationToStitchingSDL(result.data._service.sdl);<br>  return {<br>    schema: buildSchema(sdl, {<br>      assumeValidSDL: true,<br>      assumeValid: true,<br>    }),<br>    executor,<br>  };<br>}<br><br>async function makeFederationGatewaySchema() {<br>  await waitOn({ resources: [4001].map((p) =&gt; `tcp:${p}`) });<br>  const { stitchingDirectivesTransformer } = stitchingDirectives();<br><br>  const companyService = await fetchFederationSubschema(<br>    buildHTTPExecutor({ endpoint: &quot;http://localhost:4001/company&quot; })<br>  );<br>  const accountService = await fetchFederationSubschema(<br>    buildHTTPExecutor({ endpoint: &quot;http://localhost:4001/account&quot; })<br>  );<br><br>  return stitchSchemas({<br>    mergeTypes: true,<br>    subschemaConfigTransforms: [stitchingDirectivesTransformer],<br>    subschemas: [<br>      {<br>        schema: companyService.schema,<br>        executor: companyService.executor,<br>      },<br>      {<br>        schema: accountService.schema,<br>        executor: accountService.executor,<br>      },<br>    ],<br>  });<br>}<br><br>export const gatewayApp = createYoga({<br>  schema: makeFederationGatewaySchema(),<br>  maskedErrors: false,<br>  graphiql: {<br>    title: &quot;Schema title&quot;,<br>  },<br>});</pre><p>We can now initialize and start it:</p><pre>import { createServer } from &quot;http&quot;;<br>import { gatewayApp } from &quot;./gateway&quot;;<br><br>const server = createServer(gatewayApp);<br>server.listen(4000, () =&gt;<br>  console.log(&quot;gateway running at http://localhost:4000/graphql&quot;)<br>);</pre><p>If you open <a href="http://localhost:4000/graphql">http://localhost:4000/graphql</a>, you will see a playground and will be able to run a query against both GraphQL schemas. However, if you examine all the available queries in the explorer, you will see that you cannot link an account to a company. Instead, you can only query both services with two different queries.</p><p>In a real-world scenario, you would like to query both services in a single query, like we did for the company and the projects. To achieve this, we need to add some code in our GraphQL gateway. Let’s take a look:</p><pre><br>async function makeFederationGatewaySchema() {<br>  await waitOn({ resources: [4001].map((p) =&gt; `tcp:${p}`) });<br>  const { stitchingDirectivesTransformer } = stitchingDirectives();<br><br>  const companyService = await fetchFederationSubschema(<br>    buildHTTPExecutor({ endpoint: &quot;http://localhost:4001/company&quot; })<br>  );<br>  const accountService = await fetchFederationSubschema(<br>    buildHTTPExecutor({ endpoint: &quot;http://localhost:4001/account&quot; })<br>  );<br><br>  return stitchSchemas({<br>    mergeTypes: true,<br>    subschemaConfigTransforms: [stitchingDirectivesTransformer],<br>    subschemas: [<br>      {<br>        schema: companyService.schema,<br>        executor: companyService.executor,<br>      },<br>      {<br>        schema: accountService.schema,<br>        executor: accountService.executor,<br>      },<br>    ],<br>    typeDefs: `<br>      extend type Company {<br>        account: Account<br>      }<br>      extend type Account {<br>        company: Company<br>      }<br>    `,<br>    resolvers: {<br>      Account: {<br>        company: {<br>          selectionSet: `{ id }`,<br>          resolve(account, args, context, info) {<br>            console.log(&quot;account&quot;, account);<br>            return delegateToSchema({<br>              schema: companyService,<br>              operation: &quot;query&quot;,<br>              fieldName: &quot;companyAccountId&quot;,<br>              args: { _id: account.id },<br>              context,<br>              info,<br>            });<br>          },<br>        },<br>      },<br>      Company: {<br>        account: {<br>          selectionSet: `{ accountId }`,<br>          resolve(company, args, context, info) {<br>            console.log(&quot;company&quot;, company);<br>            return delegateToSchema({<br>              schema: accountService,<br>              operation: &quot;query&quot;,<br>              fieldName: &quot;accountById&quot;,<br>              args: { id: company.accountId },<br>              context,<br>              info,<br>            });<br>          },<br>        },<br>      },<br>    },<br>  });<br>}</pre><p>What are we doing here?</p><p>We are extending two types by adding an account field of type Account to the Company entity and a company field of type Company to the Account entity. Then we create the resolvers for these two new fields and use the delegateToSchema helper to fetch data from the correct schema. Let’s take a look at the resolver:</p><pre>Company: {<br>  account: {<br>    selectionSet: `{ accountId }`,<br>    resolve(company, args, context, info) {<br>    return delegateToSchema({<br>      schema: accountService,<br>      operation: &quot;query&quot;,<br>      fieldName: &quot;accountById&quot;,<br>      args: { id: company.accountId },<br>      context,<br>      info,<br>    });<br>  },<br>}</pre><ul><li>the selectionSet is the field necessary to query the object against its service. In this case, we are using the accountId stored in the company table</li><li>the schema is the service you are going to send the request to get the data about this particular entity (in this case the account service)</li><li>the operation is one of query/mutation/subscription</li><li>the fieldName is the query you are going to use to fetch the entity</li><li>the args are the argument you are passing to the query</li></ul><p>If you save all and open the gateway http://localhost:4000/graphql you will be able to run this query and get the account data while fetching the company data:</p><pre>allCompanies {<br>  nodes {<br>    id<br>    name<br>    accountId<br>    account {<br>      id<br>      name<br>    }<br>  }<br>}</pre><p>Isn’t this amazing?</p><p>Let’s focus on the other resolver. In this resolver, we will fetch the company by the account ID. To do this, we need to add a small custom query in the company service:</p><pre>CREATE OR REPLACE FUNCTION company_by_account_id (_id integer)<br>  RETURNS company<br>  AS $$<br>    SELECT * FROM company WHERE account_id = _id<br>$$<br>LANGUAGE &#39;sql&#39;<br>IMMUTABLE;</pre><p>We created this function for simplicity. We could have accomplished this using the allCompanies query with a condition, but to keep things simple, we will use this custom query. Let’s take a look at the resolver:</p><pre>Account: {<br>  company: {<br>    selectionSet: `{ id }`,<br>    resolve(account, args, context, info) {<br>      return delegateToSchema({<br>        schema: companyService,<br>        operation: &quot;query&quot;,<br>        fieldName: &quot;companyByAccountId&quot;,<br>        args: { _id: account.id },<br>        context,<br>        info,<br>      });<br>    },<br>  },<br>},</pre><ul><li>the selectionSet is the account id</li><li>the schema is the company service</li><li>the operation is a query</li><li>the fieldName is companyByAccountId</li><li>the arg that we will need to send is the account id</li></ul><p>If you try to run this query, you will see all the data from the account service and from the company service.</p><pre>  allAccounts {<br>    nodes {<br>      id<br>      name<br>      companyId<br>      company {<br>        id<br>        name<br>        projectsByCompanyId {<br>          nodes {<br>            id<br>            name<br>          }<br>        }<br>      }<br>    }<br>  }</pre><p>That’s it, we have now a federation gateway!</p><p>Let me know what you think about this solution. So far, I haven’t found any working solution to create a federated schema using PostGraphile, but this is the first working solution I’ve found.</p><p>I can’t guarantee that it covers all cases, and I haven’t tested its performance in production. However, it can be a starting point.</p><p>Please conduct your own tests if you decide to use this code.</p><h3>References</h3><p><a href="https://the-guild.dev/graphql/stitching/docs">The Guild</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3071fdae8141" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/lets-create-a-federation-schema-with-postgraphile-and-graphql-tools-3071fdae8141">Create a Federation Schema With Postgraphile and “graphql-tools”</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>