Skip to content
Author Micah Cambre

typescript, graphql and wordpress

I took a few days to reacquaint myself with GraphQL the last few days. It’s hugely popular with developers as a way to efficiently work with data, providing an efficient way to get a specific set of data to use in a code base. It’s compelling once you understand how to use it.

So I went ahead and installed WPGraphQL, on a WordPress instance I have, to put my feet on the pedals and begin riding. For a few months, I was contemplating creating a custom-built look to a website, and I also wanted to try out using Astro. This was a good opportunity.

It’s trivial to set Astro up, running:

npm create astro@latest

It asks if I want to use TypeScript, so sure, why not. I’m familiar with it, this’ll give me more experience to use it, all it’ll do is take up more time if it’s not easy to put together.

Okay, so then I begin setting up a very simple couple of template files in Astro.

+ src
  + data
    </> wordpress.ts # This is where I fetch the data
  + layouts
    </> default.ts # This is the baseline application wrapper
  + pages
    + blog
      </> [slug].astro # Blog post
    </> index.astro # Blog roll 

Getting to this point wasn’t too difficult, just following the steps and updating to my project. The head scratcher comes from the actual TypeScript that’s required.

Here’s the blog roll code.

---
import	Layout from '../layouts/default.astro';
import { wpquery } from '../data/wordpress';

const data = await wpquery({
	query: `
		query LoadAllPostsExcerpt {
			posts {
				nodes {
					title
					slug
					excerpt
				}
			}
		}
	`,
});
---

<layout title="Test">
	<h1>Posts</h1>

	{
		data.posts.nodes.map((post: any) => {
			return (
				<article class="post-preview">
					<h2>
						<a href={`/blog/${post.slug}`}>{post.title}</a>
					</h2>
					<fragment set:html={post.excerpt}></fragment>
					<a href={`/blog/${post.slug}`}>read post →</a>
				</article>
			)
		}
	)}
</layout>

Here’s the focus of this code: data.posts.nodes.map((post: any) => {...}.

There’s nothing simple in WordPress about declaring a type on various data, like post: any. In my code, I’ve resorted to the data type any so many times it becomes pointless to continue using TypeScript.

So I have looked all over for a solution. It exists, of course, but from what I can see, it’d look something like post: Post after having to add another abstraction to define what is Post. Tedious and silly, if you ask me.

Already using TypeScript is an abstraction, one I’m finding to not be so useful.

With the above said, let me end this with a general headless WordPress confusion. The future of WordPress, clearly, is Gutenberg. However, according to the author of WPGraphQL,

“[…] much of WordPress was built with decoupling in mind, the WP REST API and Gutenberg were not.”

In fact, it’s worse than this for anyone using modern WordPress using Gutenberg.

“Gutenberg didn’t have a server-side registry for blocks. At this time, all blocks in Gutenberg were fully registered in JavaScript, which is not executed or understood by the WordPress server.

This means that unlike Post Types, Taxonomies, Meta, Sidebars, Settings, and other constructs that make up WordPress, Gutenberg blocks don’t adhere to any type of contract with the WordPress server.

This means that the WordPress server knows nothing about blocks. There are no agreements between Gutenberg blocks and other systems in WordPress, or systems trying to interact with WordPress via APIs.

Blocks were practically non-existent as far as the application layer of WordPress was concerned.”

So this means, if I have decided that Block Themes and Full-Site Editing is the future and I want to support it, and I also want to go headless, I’m in for a world of pain.

Are developers truly going to continue supporting or going with WordPress unless/until they fully get on board with Block Themes? I don’t think I can see myself continue with WordPress as it’s moving forward. With its forced use of React for Gutenberg, to the weird ways you have to set data, attributes, styles, or other options, this looks like a complete lock-in to a specific way of building websites. Maybe this is great for some, but I am having major doubts I’ll stick this out for much longer.

blockquote pizzazz

Trying to be more creative and updated my blockquotes to heavily stand out. It’s my freakin’ blog, I might as well try new crazy styles!

indiewebify this site

It’s fun to think I’m back here writing occasionally, but my personal interests to come back here are more broad. Getting back to a website where I control everything is empowering and the ultimate satisfaction. The kickstart to get this point was seeing the potential through a movement called Indieweb. Indieweb principles align with my personal interests as well as the reason I started writing online so many years ago. I’m also burnt out from the effect that social media has on privacy.

Here’s what I’ve already done to asuh.com.

  • A new look, simplified but intricate
  • New blog post formats called Kinds. They mimic what we know from other social media, such as Notes which are similar to Tweets, Articles which are standard blog posts, Reply posts which are the same as Replies anywhere, Photo posts which can be like Insta photos, Bookmarks, Quotes and more! You’ve probably seen multiple posts where I’m trying out the various kinds I’ve mentioned
  • When I make a new blog post here, I can check a box and it’ll create a new Tweet on Twitter. Not only that, but with various other methods, I can now see all the Twitter activity right here on each post. I could theoretically stop going to Twitter.com or Tweetdeck and use this website to participate in Twitter
  • What’s just as important is I have the ability to show other sites that use the same content I’ve posted here. I don’t want to write into the void of another app when I can write what I want here first and syndicate it where I want. Or I can go to Instagram, post a new photo and I can connect my site to grab everything I just posted on Instagram. In other words, I don’t need to just lose the things I’m posting into these other silos of social media
  • You know how you can check in to your location? You post on Facebook or Yelp or Foursquare and share where you are? I was never that interested in this feature but I have the same ability to inform of my location at time of post
  • For sites and apps that allow it, I can now use this site to log into those other sites or apps. The support for this feature is small at the time of writing but the potential is great
  • Performance optimization is an ongoing task, as I introduce more ways to load this site as quickly as possible. I have more work to do but my goal is for site loading to be better than the rest. In fact, I’ve got some pieces put together to make this site perform as good as apps on phones
  • If you look for a post that I’m talking about code, you’ll see that code is now highlighted with a specific color scheme so that it stands out. This will help me to write more technical posts and contribute back to the web community as I discover, learn and grow as a developer

There’s more to add above but I think that’s a good highlight. Now let’s see where I hope to be in the next year.

  • Add a little more color. This is as plain as it gets but I needed a baseline to build upon. This might be slower than I want but I hope to find ways to make the reading and interactive experience more visual
  • Turn asuh.com into what’s called a Progressive Web App. You know how you can download apps in a store? I’m positive you’ve downloaded more than one app, possibly lots of apps, that are sitting on your phone being unused since you downloaded it. Appstore apps are usually pointless now when you can get the same thing using the web, inside a browser. It’s an exciting area to go into
  • Ever since I started posting, I’ve had to come to terms with what I share online being public forever. However, I’m also not willing to share everything for everyone. I’m going to explore ways to share things here that will not be publicly accessible, meaning they’ll probably be encrypted and require some kind of key to access. I think this topic deserves its own post sometime because privacy has become as precious as fine metals like gold; it’s harder to keep things to myself if I decide to share them online
  • I might get my hands dirty enhancing other themes to help other WordPress users connect with a lot of the above features. Maybe I’ll branch out to one of the frameworks/libraries du jour like React.js/Gatsby and get something up there too
  • I’ll continue contributing back to the Indieweb community in whatever ways and time I can make. I think the community still lacks enough turnkey systems to quickly get people up and running in ways that you feel connected on social media and I can increasingly see a path for this in WordPress and other ecosystems. It’s a long journey but one that’s worthwhile
  • More writing! I’m going to find a balance between some technical writing and personal writing here. Maybe I’ll divide the site up more so that the sections are more distinguished from each other. There’s a lot going on for me, less personally but definitely professionally, and I can’t wait to share more

I hope I look back at this and see that I’ve done even more than I wrote above. However, I’ll still be content if I get to even half of this. There’s so much in store for the year and the potential is endless so I hope I can make 2019 an productive year for my personal growth and continue Indiewebifying as much as I can.

the web, my web, and an open web

Being back at asuh.com is satisfying. I’ve started new again, renewing a passion I once had, and I’m excited for things to come.

Before I knew it was probably my career, creating on the Internet (capital ‘I’ at the time) became a new puzzle I enjoyed solving. I spent the late 1990s and early 2000s learning to how to utilize all things digital. I was inspired by friends and industry professionals, seeing how websites gave people freedom and platforms of their own.

I was able to register this domain in 2002 after it was released by someone else who previously purchased it. This is my prized domain name since I feel a connection to the term “asuh” since the early 1990s. For the next few years, it was my digital home and where I expressed myself to broadcast to others, interested to keep up with even a small part of my life.

Things slowly changed in the MySpace days starting around 2007. I posted less here and more there, where the eyeballs and activity were focused. That participation moved over to Facebook in the late 2000s and has more or less stayed there since this year.

2012 was the year my website’s pulse stopped. One last post about my move and life change and I stopped writing. I didn’t have the desire or interest that I used to have since the online collective, all of us who go on the internet (lowercase ‘i’), was locked into social platforms. How could I find motivation to post here anymore when everyone had migrated into the various apps and sites?

Now at the end of 2018, I’m social-media-burnt-out. I’ve all but stopped posting on Facebook and Twitter except now when I post here first. I don’t enjoy the social media participation like I used to and don’t get the same feeling of enjoyment. I lost trust in most of these platforms.

For the last few years, as I’m listening to This Week in Google, I kept hearing of a movement called Indieweb about owning your data and content: taking back the control from the various “silos”. It was appealing, my ears perked up every time I heard it. So in 2017, I finally made an effort to learn more and participate. I finished a first phase of a website redesign on this site, updated existing content, added new pages and content, and now have renewed motivation.

Controlling what I do online is once again my priority. I hope to set an example here and elsewhere showing how to take back control of my online presence. By creating posts like this freely on my website, I once again give back to an open web, one which starts with me and isn’t controlled by other sites or apps.

Maybe this is just a rose-tinted view I get from my own digital bubble, but being back on here gives me an excitement I missed.

personal websites

Read We Should Replace Facebook With Personal Websites by Jason KoeblerJason Koebler

Personal websites and email can replace most of what people like about Facebook—namely the urge to post about their lives online.

I resonate with Jason’s article having been down a similar path. However, I also see another side to this: Facebook et al are simply the next iteration of communication, sharing content that is valuable to people for a moment in time. I know there are people who put a lot of heart into what they share, would love to revisit the things they said or did. I also know many who couldn’t care less to see what they did or thought 10 or 20 years ago.

The reason siloed social media sites are, and will continue to be, popular is because silos have always been effective as a way to connect, be it from newsgroups or AOL of many years ago. I would argue many, if not most, people are only looking for instant gratification and hits of dopamine in what they do as they participate in these sites and apps. Not all need or want the ability to own their own content or understand the value in it.

For those of us who do, our personal websites are the perfect means to control what is out there. I’ve found new motivation to help give those like me the means to take this control back.

Replied to

I intend to continue updating my site with an agenda to use what I’m doing as a basis for new web projects that are all-in-one products for sites to own their own content. It feels like a new frontier!

Returned to my roots of web design today, spending most of the working day on my site. It’s fun to recapture the joy of creating!

This is probably my first public technical writing post I’ve made. It’s not as in-depth as it could have been, but it was still a valuable experience. Enjoy! https://asuh.com/case-studies/asuh/

Taking back control takes time…

My kryptonite with writing front-end code is the need to do better. I’ve gotten carried away for four months making this custom WordPress theme perfect!