Building a blog with standalone Angular v17 and Hashnode GraphQL APIs

Building a blog with standalone Angular v17 and Hashnode GraphQL APIs

cleancodecraft's photo
·

3 min read

Let's set the record straight from the beginning. If you come across the old Angular logo:

or encounter someone using 'AngularJS' without recognizing the difference between Angular and AngularJS, it's crucial to reconsider relying on them for accurate and up-to-date information about Angular. While it's not to say that you can't gain any insights, chances are what you'll learn might be outdated and possibly no longer relevant.


In this blog post, we will explore the process of integrating an Angular frontend into your Hashnode blogs. Before diving in, it's essential to highlight that there are multiple approaches to achieve this, and failing to acknowledge this variety and implying a singular method would be misleading. We aim to outline several options, empowering you to choose the one that aligns best with your preferences.

Option 1: save time by using AnguHashBlog

AnguHashBlog is an open-source project that Esther White{{ MonaCodeLisa }} started, and she announced it publicly on Feb 10th, 2024, in a YouTube video. At this point she had an already built project, hosted in her local repo which was named 'Angular-Headless-Hashnode'. She successfully established a fully operational integration with Hashnode Blogs. Esther, a full-stack web developer with diverse experience, has focused strongly on Angular for the past four years, showcasing her strong commitment and proficiency in this framework. Esther says:

"I am not selective when it comes to backend, but on the front-end it has to be Angular, then I have the motivation to make the app work with pretty much any backend."

AnguHashBlog, now housed in a GitHub Organization, brings three key advantages to the table.

  • First, opting for AnguHashBlog provides access to a pre-built app and the ability to test live demos by seamlessly switching to your own Hashnode Blog URL. Test the DEMO

  • Second, being open-source, it offers an opportunity to kickstart your journey into open-source contributions.

  • Lastly, the app, while offering a strong foundation, is designed for easy customization by developers experienced in Angular, allowing for tailored adjustments to meet specific needs.

Option 2: use Apollo Angular

Apollo Angular, a GraphQL client for Angular, simplifies the execution of GraphQL queries. AnguHashBlog leverages Apollo Angular, and you can delve into the code and implementation details by visiting the following link: HERE.

Basic usage:

import { APOLLO_OPTIONS, ApolloModule } from 'apollo-angular';
import { HttpLink } from 'apollo-angular/http';
import { HttpClientModule } from '@angular/common/http';
import { InMemoryCache } from '@apollo/client/core';

@NgModule({
  imports: [BrowserModule, ApolloModule, HttpClientModule],
  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory(httpLink: HttpLink) {
        return {
          cache: new InMemoryCache(),
          link: httpLink.create({
            uri: 'https://48p1r2roz4.sse.codesandbox.io',
          }),
        };
      },
      deps: [HttpLink],
    },
  ],
})
export class AppModule {}

this code snipped is from Apollo Angular's website and it has not been updated to the latest Angular versions. AnguHashBlog features and implementation of Apollo Angular for standalone applications.

Option 3: Implementation Suggested by Hashnode.

Hashnode, historically less interested in Angular, recently published a concise guide outlining one potential integration. Their recommended approach emphasizes the use of Angular's HttpClient over Apollo Angular. While functional, the guide exhibits a blend of practices and doesn't cover exploration of various scenarios. Despite the potency of the Angular's HttpClient, it might not be the ideal solution, particularly for real life applications that usually go beyond a simple component or two. After Esther tested the implementation suggested by Hashnode, she has now included a repository for you to have a closer look at this implementation. Explore the README.md for additional insights and considerations if you choose to adopt this approach.

The dynamic integration of Angular with Headless Hashnode blogs, exemplified by AnguHashBlog, opens up a realm of possibilities for developers seeking a robust and customizable solution. This fusion not only enhances the overall user experience but also showcases the versatility and adaptability of Angular in addressing the evolving needs of modern web development.