<?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 Premkumar M on Medium]]></title>
        <description><![CDATA[Stories by Premkumar M on Medium]]></description>
        <link>https://medium.com/@premsuryamj?source=rss-3396c1b7211a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*u23Qug65ekQvTDKmDiSBpA.jpeg</url>
            <title>Stories by Premkumar M on Medium</title>
            <link>https://medium.com/@premsuryamj?source=rss-3396c1b7211a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:49:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@premsuryamj/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[Intro to IAC]]></title>
            <link>https://medium.com/@premsuryamj/intro-to-iac-2f9556dfa119?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f9556dfa119</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[iac]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Sun, 06 Nov 2022 12:48:57 GMT</pubDate>
            <atom:updated>2022-11-06T12:48:57.495Z</atom:updated>
            <content:encoded><![CDATA[<p>Infrastructure is one of the Core tenants in software development. Whatever we develop we need one of the services provided by cloud platforms to deploy and share with our end user.</p><p>In the Agile Practice, we used to work with multiple environments like DEV, QA, Staging and Production in the development cycle.</p><p>Let’s say we have a NodeJS application and need to deploy it to the Cloud, which gives the user the URL to access. Forming the cloud setup is a tedious task for each environment. To make the task more interesting, we can setup up the infrastructure by writing the code that’s the IAC (Infrastructure As Code)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2VmIk-sK2EFyiXaw.png" /></figure><p><strong>How IAC works?</strong></p><p>IAC can be configured with the different kinds of tools and platforms available in the market and executed as part of a CI/CD pipeline. Cloud platforms provide their own APIs for the available services and IAC uses their API to set up the infrastructure as we configured in the code.</p><p><strong>IAC Platforms:</strong></p><p>There are plenty of IAC platforms available in the market. Here are the most commonly used IAC platforms</p><ul><li>Terraform</li><li>AWS CloudFormation</li><li>Pulumi</li><li>Chef/Puppet</li></ul><p>Each platform has its own pros and cons. We are not digging into it to see which one to use when and why.</p><p>Let’s see a basic example of IAC using Terraform.</p><pre>locals {</pre><pre>    aws_region = &quot;ap-south-1&quot;</pre><pre>}</pre><pre>terraform {</pre><pre>     required_providers {</pre><pre>           aws = {</pre><pre>               source = &quot;hashicorp/aws&quot;<br>               #version = &quot;~&gt; 3.21&quot; # Optional but recommended in          production</pre><pre>           }</pre><pre>      }</pre><pre>}</pre><pre># Provider Block</pre><pre>provider &quot;aws&quot; {</pre><pre>     profile = &quot;default&quot; # AWS Credentials Profile configured on your local desktop terminal  $HOME/.aws/credentials</pre><pre>    region  = local.aws_region</pre><pre>}</pre><p>Thanks for reading out this blog. I planned to write a series of writings in <strong>IAC</strong> using terraform. If you like the blog please do applause and follow me to get immediate notifications of my upcoming blogs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f9556dfa119" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Talisman with Husky]]></title>
            <link>https://medium.com/@premsuryamj/talisman-with-husky-2ca0ce867894?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ca0ce867894</guid>
            <category><![CDATA[pre-commit]]></category>
            <category><![CDATA[husky]]></category>
            <category><![CDATA[security-check]]></category>
            <category><![CDATA[talisman]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 09:11:25 GMT</pubDate>
            <atom:updated>2022-10-24T09:11:25.098Z</atom:updated>
            <content:encoded><![CDATA[<p>Happy to see you.🙂 In our last <a href="https://medium.com/@premsuryamj/pre-commit-hook-with-husky-3fd897dc06c2">blog</a>, we saw how to configure the pre-commit hook in git using Husky. If you are not well-known in husky please read out my <a href="https://medium.com/@premsuryamj/pre-commit-hook-with-husky-3fd897dc06c2">blog</a>.</p><p>Here we will see what Talisman is and how to configure it in the pre-commit hook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*-zGXnQfNMaOS40co.png" /></figure><p>Why we are waiting, Let’s jump into the topic</p><p><strong>Talisman</strong></p><p>Talisman is a tool that configures in the pre-commit to ensure that sensitive information like secrets, API keys, and tokens are not committed to git in the developer’s local environment.</p><p><strong>How does it work?</strong></p><p>Talisman could be installed as CLI in the local environment and updated to the path variable.</p><p>On commit, Talisman will scan the repo and generates the errors categorized by their severity(low, medium and high).</p><p><strong>Installation:</strong></p><p>Talisman works in macOS, Windows and Linux systems. Here we will see how to configure it in the macOS as a pre-commit hook.</p><pre>bash -c &quot;$(curl --silent <a href="https://thoughtworks.github.io/talisman/scripts/install.bash">https://thoughtworks.github.io/talisman/scripts/install.bash</a>)&quot;</pre><p>It installs a talisman in the directory <em>$HOME/.talisman/bin</em></p><p>Restart your terminal/source the zshrc file.</p><p>Now we can add the blow line to our husky’s pre-commit file.</p><pre>$TALISMAN_HOME/talisman_hook_script pre-commit</pre><p>We are all set with the configuration and it is ready to go.</p><p>We saw how to configure Talisman as a pre-commit hook in husky. To know more about the talisman please reach out to the Talisman <a href="https://github.com/thoughtworks/talisman">repository</a>.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ca0ce867894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CircleCI with Cypress E2E test]]></title>
            <link>https://medium.com/@premsuryamj/circleci-with-cypress-e2e-test-33a2bfb8696e?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/33a2bfb8696e</guid>
            <category><![CDATA[circleci-orbs]]></category>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 11:15:36 GMT</pubDate>
            <atom:updated>2022-09-20T11:15:36.822Z</atom:updated>
            <content:encoded><![CDATA[<p>Cypress is a frontend testing tool that helps to write faster, more accessible and more reliable test cases. It works on top of JQuery to find the elements in DOM and validates the tests.</p><figure><img alt="CircleCI with Cypress" src="https://cdn-images-1.medium.com/max/320/0*CltMoEoIdaT0mlaK" /></figure><p>Cypress provides various types of tests</p><ul><li>End-to-End test</li><li>Integration test</li><li>Component test</li></ul><p>CircleCI is a modernized continuous integration and continuous delivery (CI/CD) platform having its own registry to make the test faster.</p><p>Today we are going to see how to connect the Cypress E2E test with CircleCI using different browsers. I’m going to use yarn as the package manager. You can also use npm as an alternative.</p><p>Install Cypress as the dev dependency:</p><blockquote>yarn add cypress -D</blockquote><blockquote>yarn add @testing-library/cypress -D</blockquote><p>Add the cypress start command in the package.json’s scripts</p><blockquote>“cypress:open”: “cypress open”</blockquote><p>Cypress installation is a success. Let’s configure it</p><p>Open the terminal, Change your PWD directory to the applications root directory and run the following command</p><blockquote>yarn cypress:open</blockquote><p>It’ll open the welcome page to configure the test case</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VEuBYIiuLMQ7ZOBe" /></figure><p>Select <em>E2E testing</em> to configure and it will show the configuration files to be created (It’ll create files automatically at the end). Click <em>Continue</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4cyuVD9TxnqUtcqj" /></figure><p>Choose your preferred browser and click Start, This will redirect to the spec file creation page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*clSuuxlIWh2dMBdt" /></figure><p>This will create all the configuration files and the sample test file under the folder cypress in the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GIEz-1mYfEfFSevb" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*HBakbQdLqHrX3jy4" /></figure><p>In the Cypress Window, you will see all test files. Open and it’ll run all test cases in the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wbZmwlmTcVhWbR7Y" /></figure><p><strong>Integrate the written test cases with CircleCI</strong></p><p>Create the config.yml under the folder .circle/config.yml. The file will be read by the CircleCI on every push to the repo.</p><p>Follow the steps to configure the CircleCI</p><p>Add the orbs followed by the version in the <em>config.yml</em> file. Orbs is a package registry in the CircleCI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*Mt7d1mOYbc13bGXYptX7bQ.png" /></figure><p>Configure your executors, to run the test cases in the browser docker image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*0dT4An_3Fgnu2OnrxZV4fQ.png" /></figure><p>Add your workflow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*-WhOLGI89oxGgCuPDKAygg.png" /></figure><p>Commit and push your code. Follow the repo in CircleCI and see the magic. This will start in the chrome browser and runs in the background. The test results are shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j3FBJ8Y3G91RX--X" /></figure><p>We came to end, We saw the simple way to configure Cypress E2E test case with the CircleCI. If you like the blog please do applause it’ll motivate me to come up with more writings.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33a2bfb8696e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pre Commit Hook with Husky]]></title>
            <link>https://medium.com/@premsuryamj/pre-commit-hook-with-husky-3fd897dc06c2?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fd897dc06c2</guid>
            <category><![CDATA[pre-commit]]></category>
            <category><![CDATA[husky]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 07:32:25 GMT</pubDate>
            <atom:updated>2022-09-14T07:32:25.627Z</atom:updated>
            <content:encoded><![CDATA[<p>Can the third person enter the room if the Husk is in front of the door? Obviously no, We can’t enter until it gives the way. Similar to Husk we have the <em>Husky</em>, which runs before the commit happens in our local repo to do pre-checks like type-check, lint fix and unit test cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/0*dvoffCxj828TRARM" /><figcaption>Husky behind the commit</figcaption></figure><p>The pre-checks are used to do the type checks in our typescript application help to avoid build errors on running in CI. And as well we can able to configure the husky with Prettier which helps in maintaining the codebase with the standard even if we have a large number of developers.</p><p><strong>Configure Husky in the typescript application:</strong></p><p>It can be configured with a few simple steps</p><p><strong>1. Installation</strong></p><blockquote>npx husky-init &amp;&amp; yarn</blockquote><p>The command will generate the `<em>.husky</em>` folder with the pre-commit file and installs the `<em>husky</em>` module as the dev dependency.</p><p><strong>2. Configuration</strong></p><p>The pre-commit file will be generated with the default check to run the test cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pm2036rooz7Xkwad" /><figcaption>Pre-commit with the default check</figcaption></figure><p>We can change line number 4 with `<em>yarn typecheck` </em>which does the typecheck<em>.</em> Just make sure we configured the type check in package.json and included the files to check in tsconfig.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*Xy8Qx3Znq9pn20uI" /><figcaption>package.json</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*VLO86LgzMusxziYEagjGqw.png" /><figcaption>tsconfig.json</figcaption></figure><p><strong>3. Testing</strong></p><p>Stage and commit the code you would get the typecheck errors if exists.</p><p>We do have the command to skip the pre-commit hook on commit.</p><blockquote>git commit -m ‘Message’ — no-verify</blockquote><p>We saw in simple terms how to configure the typecheck in the typescript application. Please reach out to me in the comments if you have any queries.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fd897dc06c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Admin With Hasura GraphQL APIs]]></title>
            <link>https://medium.com/@premsuryamj/react-admin-with-hasura-graphql-apis-20424660bc9d?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/20424660bc9d</guid>
            <category><![CDATA[hasuragraphql]]></category>
            <category><![CDATA[react-admin]]></category>
            <category><![CDATA[reduce-development-cost]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Fri, 02 Sep 2022 12:38:33 GMT</pubDate>
            <atom:updated>2022-09-02T12:38:33.461Z</atom:updated>
            <content:encoded><![CDATA[<p>I was in a discussion with my friend on how to reduce the development cost of the React Application. We found out React Admin can help in this. React Admin is a framework built top on ReactJs helps to develop faster by providing the inbuilt hooks and UI.</p><p>We may work in the GraphQL APIs with React using Apollo Client. Where you need to write your customised GraphQL query to get the data.</p><p>Here we will see step by step guide to integrating the Hasura GraphQL APIs in React Admin and how it achieves the development faster. Why we are waiting let’s jump to the context.</p><p>We are using <strong>ra-data-hasura </strong>as the data provider to connect the Hasura GraphQL endpoints using <strong>GraphQL introspection</strong>.</p><p><strong>Introspection</strong> is a term where it learns the GraphQL schema and decides the fields to be used for the query.</p><p>Using 9 different hooks available in React Admin, we can query/mutate the data</p><ul><li>useGetOne</li><li>useGetList</li><li>useGetMany</li><li>useGetManyReference</li><li>useCreate</li><li>useUpdate</li><li>useUpdateMany</li><li>useDelete</li><li>useDeleteMany</li></ul><p>Here are the steps to connect the Hasura API and to use the hooks in components.</p><p>Build your data provider and connect with the APP.tsx as per the example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fade6da6443d6ba73c8844fac1502ec2/href">https://medium.com/media/fade6da6443d6ba73c8844fac1502ec2/href</a></iframe><p>We successfully connected the Hasura GraphQL API using React Admin. Now we going to see how to use hooks in code.</p><p>React admin hooks will execute on the component mounts.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ac3f69ab405814d12365654031a4d31/href">https://medium.com/media/5ac3f69ab405814d12365654031a4d31/href</a></iframe><p>Using a similar approach we can use the other hooks by importing them from the <strong>react-admin</strong>.</p><p>We saw how to connect React Admin with the Hasura GraphQL API and how to use React Admin hooks. Hope everyone understood. Please reach out to me in the comments if you have any queries.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20424660bc9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of Single Spa]]></title>
            <link>https://medium.com/@premsuryamj/overview-of-single-spa-1b6945c919a8?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b6945c919a8</guid>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[single-spa]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Thu, 28 Jul 2022 05:27:47 GMT</pubDate>
            <atom:updated>2022-07-29T10:31:00.367Z</atom:updated>
            <content:encoded><![CDATA[<p>We may work or hear about the Microservices where you can split the monolithic application into micro applications. The same rule can be applied to frontends where you can break the monolithic frontend applications into micro frontends.</p><p>In this blog, we will see the primary use of the Micro front end and how to achieve it with single-spa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xP-pu-B__Woceglx" /><figcaption>Micro frontends using Single Spa</figcaption></figure><p>The primary use of micro front end</p><ul><li>Scaling into teams</li><li>Tech stacks</li><li>Development and Deployment faster</li></ul><p><strong>Overview of Single Spa:</strong></p><p>Single-spa is a framework where you can bring multiple Javascript frontend applications into a single-page application. Here you can merge different tech stack micro frontends. We can break single-spa into two categories.</p><h4><strong>Root Config</strong></h4><blockquote>It helps to register the micro front ends and controls the mount and demount of the applications.</blockquote><p><strong>Applications</strong></p><blockquote>This will be split into modules and shared the module between others as micro-frontends.</blockquote><blockquote>You may have a question, How to control the shared modules between the micro front ends? Single spa performs the job by listening to the route events and mounts / demounts the module to/from DOM as per the specified event.</blockquote><p>Single Spa offers three different types based on the place’s needs.</p><ul><li>Single-Spa applications</li><li>Single-Spa Parcel</li><li>Utility modules</li></ul><p><strong>Single Spa Applications:</strong></p><p>Single Spa Applications contains many registered SPA applications with their own tech stacks. It renders its own HTML pages in full freedom irrespective of the micro frontend. Single Spa mounts / demounts the micro front ends based on the module registration and activation in the root config.</p><p><strong>Single Spa Parcel:</strong></p><p>Single Spa Parcel mounts only the required SPA application on the DOM without any blocks and performs its own feature independently. It imports the micro front end irrespective of routes and can be added it any place similar way of adding child components.</p><p><strong>Utility Module:</strong></p><p>As we saw above Single Spa Applications and Parcels are used to mount and demount the Micro front ends. We didn’t think about how to communicate between the micro front ends?</p><p>But Single Spa is providing us with a way to communicate between the micro front ends.</p><p>The utility module will be imported to the root config and shared between the registered micro front ends.</p><p>Thanks for reading! We saw the overview of the micro front end, single spa and its types. In our upcoming blogs, we will see how to set up single spa applications with their different types. Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b6945c919a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cypress: Mock GraphQL and Rest APIs]]></title>
            <link>https://medium.com/@premsuryamj/cypress-mock-graphql-and-rest-apis-6afadeb51e7a?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6afadeb51e7a</guid>
            <category><![CDATA[react-admin]]></category>
            <category><![CDATA[integration-test]]></category>
            <category><![CDATA[mock-graphql-apis]]></category>
            <category><![CDATA[cypress]]></category>
            <category><![CDATA[mock-rest-apis]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 12:18:03 GMT</pubDate>
            <atom:updated>2022-07-04T12:18:03.370Z</atom:updated>
            <content:encoded><![CDATA[<p>A question raises in my mind while I’m writing the integration tests for my React application. Why do we need the backend service needs to be up and the front end should call the API to get the data on running the tests?</p><p>After exploring blogs and Cypress documentation, we found we can mock the API calls. Different documentation is given different approaches. I was using the React-admin framework on top of React and faced many issues with mocking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*XN53H-YCXbUy9Z_E.png" /><figcaption>Copyright to dev.to</figcaption></figure><p>Here I’m going to give step by step guide to mocking the GraphQL and Rest API using cypress.</p><p>The tech stacks I’m using</p><ul><li>React with react admin for front-end</li><li>GraphQL with Hasura</li><li>Cypress for integration testing.</li></ul><p>As you all know, React admin is a framework with its own data provider to get data either using GraphQL or Rest APIs.</p><p>Let’s get started to mock the API</p><p>Make sure you have the following folder structure under the cypress directory to test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/0*Hr0NcwzRc5CBxtIY" /><figcaption>Cypress Folder structure</figcaption></figure><p><strong>Fixtures:</strong></p><p>Fixtures are used to store the hard-coded mock data files. Let’s create a couple of files with mock data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d11ebd13a004920272d91f71ea97e03d/href">https://medium.com/media/d11ebd13a004920272d91f71ea97e03d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1beb541fc67b0939a39bbe98719bc4a/href">https://medium.com/media/b1beb541fc67b0939a39bbe98719bc4a/href</a></iframe><p>introspection-query.ts</p><p>Get the Introspection data from the GraphQL API with the operation name <strong>IntrospectionQuery</strong> under your browser’s Network tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4S3T762Hgn6ZsYdA" /></figure><p>Paste the response in the introspection query file in the following format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/0*Mh7BBQsbGet0nbG8" /></figure><p><strong>Integrations:</strong></p><p>The integrations directory will have all our test files.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8db76d582e1c0f0e916bcb1a491e6778/href">https://medium.com/media/8db76d582e1c0f0e916bcb1a491e6778/href</a></iframe><p><strong>Support/Command.ts</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88d8902fb06223faf8fc2e06d32f72f5/href">https://medium.com/media/88d8902fb06223faf8fc2e06d32f72f5/href</a></iframe><p><strong>Utils</strong></p><p>Create a file called<strong> cypress-mock-helper.ts </strong>under utils and paste the following file in it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb6bdd37b8e5854734018504157ec781/href">https://medium.com/media/bb6bdd37b8e5854734018504157ec781/href</a></iframe><p>Start the cypress and you can see the magic of mocking all GraphQL and RestAPIs.</p><p><strong>Conclusion:</strong></p><p>We have seen how to mock GraphQL and Rest APIs using cypress. Happy Coding!</p><p><strong>Reference:</strong></p><p><a href="https://medium.com/revel-systems/cypress-mocking-graphql-requests-fc1afda4654">https://medium.com/revel-systems/cypress-mocking-graphql-requests-fc1afda4654</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6afadeb51e7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of CRUD operations using Hasura GraphQL and Node JS]]></title>
            <link>https://medium.com/@premsuryamj/overview-of-crud-operations-using-hasura-graphql-and-node-js-98e567030c95?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/98e567030c95</guid>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[hasura]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Wed, 18 May 2022 12:36:36 GMT</pubDate>
            <atom:updated>2022-05-18T12:36:36.191Z</atom:updated>
            <content:encoded><![CDATA[<p>In our previous article, we learned about the configuration setup of GraphQL with NodeJs. If you haven’t read the <a href="https://medium.com/@premsuryamj/how-to-setup-a-graphql-with-apollo-server-and-express-in-nodejs-d28bfc231163">article</a>, please look at it before reading this.</p><p>Today we will see how to do the CRUD operation in NodeJS using GraphQL, Postgres and Hasura.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZgQ3xn8xOYS31eB8.png" /><figcaption>Copyright by Hasura</figcaption></figure><p><strong>How does GraphQL perform CRUD?</strong></p><p>Is GraphQL using a different endpoint to perform the actions?</p><p>No, As we have seen before GraphQL uses a single end-point for all operations.</p><p>Now a question arises in your mind. How is it possible?</p><p>GraphQL plays this magic with the help of <strong>Queries and Mutations</strong>. Queries don’t affect the state in DB and will return only the requested data. Mutations will affect the DB state by performing create, updating and deleting values.</p><p><strong>What is Hasura?</strong></p><p>Hasura is a lightweight GraphQL engine that gives real-time GraphQL APIs to the configured database. Please use the <a href="https://hasura.io/docs/latest/graphql/core/index/">link</a> to learn more about Hasura.</p><p><strong>GraphQL Query:</strong></p><p>The query is a technique where one gets the data from the server similar to the requested format.</p><p>Let’s start by looking with a very simple query</p><blockquote>Query to get all data from the table</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bZcZGra2Zxp4okVX" /></figure><blockquote>Query to get data by primary field</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fp7NjnfsFPzC1dEb" /></figure><p><strong>GraphQL Mutations:</strong></p><p>Our discussions on GraphQL focused on data fetching but the data platform needs to provide an option to update the values in the database. Mutation comes in place to update the data on the server.</p><blockquote>Mutation to insert data</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HypKipLPxwRC1NrR" /></figure><blockquote>Mutation to update data</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uE7ibRDaYy4TvKSR" /></figure><blockquote>Mutation to delete data</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sigjGo_h9ItaTD7M" /></figure><p><strong>Summary:</strong></p><p>We have seen an overview of GraphQL Query and Mutations with Hasura. In our next blog, we will see Hasura and the configuration with the Postgres database.</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98e567030c95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup a GraphQL with Apollo Server and Express in NodeJs]]></title>
            <link>https://medium.com/@premsuryamj/how-to-setup-a-graphql-with-apollo-server-and-express-in-nodejs-d28bfc231163?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d28bfc231163</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Sat, 16 Apr 2022 14:02:12 GMT</pubDate>
            <atom:updated>2022-04-16T14:02:12.380Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is GraphQL?</strong></p><p><strong>GraphQL</strong> is a query language that acts as a middleware in the Express app. It allows the user to have a single endpoint and provides access to the client to specify what data it needs from the server.</p><p><strong>What is Apollo Server?</strong></p><p><strong>Apollo Server </strong>is an open-source GraphQL server that is built to work in all HTTP server frameworks. It can also run with its built-in Express server. To explore more about the apollo server please <a href="https://www.apollographql.com/docs/apollo-server/">click here</a></p><p><strong>Let’s get started with GraphQL</strong></p><p>Install <a href="https://nodejs.org/en/download/">NodeJs</a> to your local machine if it is not installed and initialize the npm package to the project.</p><p>Install the following npm dependencies</p><blockquote>npm install express apollo-server-express graphql fs path</blockquote><blockquote>npm install nodemon — save-dev</blockquote><p>Setup the project structure as per the below-attached image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*ybSf9WRscF9Uw41B" /></figure><p>Let’s dive in deep to understand the usage of files in the above image</p><blockquote>graphql &gt; typedefs &gt; index.graphql</blockquote><p>It defines the shape of the data and the hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which queries and mutations are available for clients to execute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oBvARZ2arKNyMLz-I2lM-w.png" /></figure><blockquote>graphql &gt; resolvers &gt; index.js</blockquote><p>It is a function that queries the requested data from the appropriate data source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4g_gDt31fAscVw9hDa_bg.png" /></figure><blockquote>index.js</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TRvOhWrLqMb0_78Nlml7wA.png" /></figure><p>The last final step add this script to the package.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_wxe0_NmUP3Ag8dx2q7aA.png" /></figure><p>We are done with the initial setup of the project. Now let’s start the project by using the script added in package.json</p><blockquote>npm start</blockquote><p>You can see the following output in the terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*f51QnTBfmeLMEKJY" /></figure><p>Now type the URL <a href="http://localhost:9000/graphql">http://localhost:9000/graphql</a> in your favourite browser. The sandbox to test your endpoint will be opened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rhpFWFn5Nz-v7xi9" /></figure><p>Click the query your server button, You’ll be taken to the following page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RGDMzLiXeoYWrRtZ" /></figure><p>Now we can give our query in the operations field and hit-run</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2eXqEfx0AhrHQJdYAY5xA.png" /></figure><p>I attached the image for your reference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1l_jWUNXPbNqr7v9" /></figure><p><strong>Summary</strong></p><p>We have seen how to set up an initial GraphQL project and write your first GraphQL query. I’m planning to provide a series of articles to help you master GraphQL. Stay tuned!</p><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d28bfc231163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Routing Guards]]></title>
            <link>https://medium.com/@premsuryamj/angular-routing-guards-8e31518d1036?source=rss-3396c1b7211a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e31518d1036</guid>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[angular-7]]></category>
            <category><![CDATA[routing-guards]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Premkumar M]]></dc:creator>
            <pubDate>Sat, 10 Aug 2019 14:44:40 GMT</pubDate>
            <atom:updated>2019-08-10T14:44:40.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TDDodA2s3onaOCN_" /></figure><p>Security is an inevitable topic in every field. We have security guards guarding us against a variety of hazards. Likewise, every asset that you own should be treated with the utmost care and security. Think about sites that you owned/developed has an attack and all your data has been corrupted. So Let’s go ahead and get some knowledge on how can we protect our sites/apps that are built using Angular. <strong>Angular Routing Guards </strong>provides security to check whether one can route to a particular URL or not.</p><p><strong>Guards in Angular:</strong></p><p>We have five different types of guards in angular 7 and each of them has its own characteristics.</p><p>The guards are:</p><ul><li>CanActivate</li><li>CanDeactivate</li><li>CanLoad</li><li>CanActivateChild</li><li>Resolve</li></ul><p><strong>Note:</strong></p><p>The URL gets activated depending upon the value returned by the class that can either be true or false which depends on the implementation done by the Guard Interface.</p><p><em>The guards mentioned above can be either synchronous or asynchronous. The guards are synchronous if the class returns a boolean value or asynchronous if it returns a Promise&lt;boolean&gt; or Observable&lt;boolean&gt;.</em></p><p><strong>CanActivate:</strong></p><p>CanActivate will examine whether the URL is allowed to be entered or not, by returning the value true or false from the class which implements the canActivate interface.</p><p>For better understanding, let us consider the following example.</p><p>The user can access the dashboard page only if he/she is logged in. This will get protected by using the canActivate Guard.</p><p>That is, Guard will do its process when the URL is trying to hit.</p><p><strong>Example:</strong></p><p>Let add the below code to the <strong>app-routing.module.ts</strong></p><pre>import { AuthGuard } from ‘../guards/Auth-guard.service’;<br>const routes: Routes = [<br>      {<br>          {<br>             path: &#39;dashboard,<br>             component: Dashboard,<br>             canActivate: [AuthGuard],<br>          },<br>       }<br>]    </pre><p><strong>Auth-guard.service.ts</strong></p><pre>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from &#39;@angular/router&#39;;</pre><pre>import { Observable } from &#39;rxjs&#39;;</pre><pre>export class AuthGuard implements CanActivate {</pre><pre>isLoggedIn() {<br>      /*Add your logic here. */<br>      return true;<br>}</pre><pre>constructor(private myRoute: Router) { }</pre><pre>canActivate( next: ActivatedRouteSnapshot,</pre><pre>       state: RouterStateSnapshot): Observable&lt;boolean&gt; |       Promise&lt;boolean&gt; | Boolean {</pre><pre>     if (this.isLoggednIn()) {<br>         return true;<br>      } else {<br>           this.myRoute.navigate([&#39;login&#39;]);<br>           return false;<br>     }</pre><pre> }</pre><pre>}</pre><p>Import the service guard in providers of the app-module.ts</p><pre>providers: [ AuthGuard ]</pre><p>Now the route gets activated by returning the value <strong><em>true</em></strong>. The <strong><em>ActivatedRouteSnapshot</em></strong> contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also be used to traverse the router state tree and <strong><em>RouterStateSnapshot, </em></strong>that<strong><em> </em></strong>represents the state of the router at a moment in time.</p><p><strong>CanDeactivate:</strong></p><p>The canDeactive interface examines whether the component can be deactivated or not, by returning the value true or false. It will get executed when the component URL is trying to deactivate.</p><p>Let us consider a simple example for deactivating the URL with the user confirmation message.</p><p>In order to deactivate the URL, change the canActivate property to canDeactivate in <strong>app-routing.module.ts</strong></p><p><strong>Example:</strong></p><pre>{<br>  path: &#39;dashboard,<br>  component: Dashboard,<br>  canDeactivate: [DeactivateGuard],<br>}</pre><p>The DeactivateGuard class implements the canDeactivate interface which will return true or false.</p><p><strong>Example:</strong></p><pre>import { ActivatedRouteSnapshot, RouterStateSnapshot, CanDeactivate } from &#39;@angular/router&#39;;</pre><pre>import { Observable } from &#39;rxjs&#39;;</pre><pre>export interface CanComponentDeactivate {</pre><pre>canDeactivate: () =&gt; Observable&lt;boolean&gt; | Promise&lt;boolean&gt; | boolean;<br>}</pre><pre>@Injectable()</pre><pre>export class ConfirmationGuard implements CanDeactivate&lt;CanComponentDeactivate&gt; {</pre><pre>cost = {};</pre><pre>constructor( private toasterService: ToasterService ) { }</pre><pre>canDeactivate(<br>   component: CanComponentDeactivate,<br>   next: ActivatedRouteSnapshot,<br>   state: RouterStateSnapshot) {<br>      this.cost = this.toasterService.get();<br>      if (this.cost[next.routeConfig.path]) {<br>          this.toasterService.setRoutingCost(next.routeConfig.path);<br>          return true;<br>      }<br>      if (confirm(&#39;Are you sure ? &#39;)) {<br>          return true;<br>      } else {<br>        return false;<br>      }<br>   }</pre><pre>}</pre><p><strong>Conclusion:</strong></p><p>I hope that everyone could understand the routing guards in angular7. In the upcoming blog will speak about the canActivatechild and canLoad. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e31518d1036" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>