Posts

apollo graphql subscription basic setup and tutorial

 The documentation for setting apollo graphql is all over the place and hard to get it to work.  The best place is to get sample code from their example repo here or you can try out my repo here.

graphql apollo how to enable express middileware

 You can follow the guide here: https://www.apollographql.com/docs/apollo-server/api/express-middleware/

express - proper way to import into es

The correct and ideal way to import would be this (remain compatibility in terms of coding)   import express from "express" ; const app = express ()

apollo graphql subscriptions - check if server is up and running

We can use the following to check if the server is up and running: npx diagnose-endpoint@1.1.0 --endpoint=ws://localhost:4002/  

graphql mutation getting started

  Defining the mutation  type Mutation { addBook(title: String, author: String): Book } Mutation graphql execution For executing the graphql as a clien you can use this. And the expected response is title, author's name as shown below mutation CreateBook { addBook(title: "Fox in Socks", author: "Dr. Seuss") { title author { name } } } Defining interface interface MutationResponse { code: String! success: Boolean! message: String! book: Book } Sample code can be found here. https://github.com/mitzenjeremywoo/graphql-review-ts

docker how to authenticate to azure container registry (acr)

  az login az acr login --name acr-name-in-azure Then try to use docker to pull those images

webpack Failed to load 'webpack.config.js' config

Image
  Getting this error while doing my local build  [webpack-cli] Failed to load 'webpack.config.js' config [webpack-cli] ReferenceError: require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a '.js' file extension and 'package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. And the reason is that i configure my package.json to type: module - which webpack doesn't like. To resolve this (careful as you might end up breaking your code), i remove it as i intended to use webpack to do hardwork of bundling application for me. Having type = module in package.json mean you can use import  to reference external libraries as oppose to using required (Commonjs). https://nodejs.org/docs/latest-v21.x/api/esm.html#esm_enabling Apparently webpack don't like it.

webpack - webpack.config.js - import path from "path"; ^^^^^^ SyntaxError: Cannot use import statement outside a module

 I was trying different ways to exclude node_modules / external libraries from being include / packaged together in my dist folder. So i tried out this settings  webpack.config.js  import path from "path" ; import { Configuration } from "webpack" ; const config : Configuration = {   entry : "./src/index.ts" , To resolve this error, I had to go back to the good old webpack.config.js that look something like this const path = require ( 'path' ); var nodeExternals = require ( 'webpack-node-externals' ); module . exports = {   entry : './src/index.ts' ,   target : 'node' , // use require() & use NodeJs CommonJS style   externals : [ nodeExternals ()], // in order to ignore all modules in node_modules folder   externalsPresets : {       node : true // in order to ignore built-in modules like path, fs, etc.   },   module : {     rules : [       {         test : / \. tsx ? $ / ,         use : 't

webpack - typescript emit no output

Image
  While working my code, bump into this error and webpack was complaining typescript emit no error And i found that there's a setting in my tsconfig.json that says this -> noEmit: true.  {     "compilerOptions" : {         "outDir" : "./dist/" ,       "noImplicitAny" : true ,       "target" : "ESNext" ,       "module" : "ESNext" ,       "noEmit" : true ,       "esModuleInterop" : true ,       "moduleResolution" : "node" ,       "allowJs" : true ,       "allowSyntheticDefaultImports" : true ,     },     "exclude" : [ "node_modules" ],     "include" : [ "src/**/*" ],   } After removing that, webpack was able to work well.

typescript: Cannot find module 'undici-types'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to ad aliases to the 'paths' option?

  Bump into this error when i compile my code using typscript - tsc in the command line. And the indici type is totally irrelevant to what i was doing As stated in the error, all i need to set my moduleResolution in tsconfig.json {     "compilerOptions" : {       "outDir" : "./dist/" ,       "noImplicitAny" : true ,       "module" : "ESNext" ,       "target" : "ESNext" ,       "jsx" : "react" ,       "allowJs" : true ,       "moduleResolution" : "node" , // <----- here       "allowSyntheticDefaultImports" : true ,       "esModuleInterop" : true ,     },     "include" : [ "src/**/*" ],     "exclude" : [ "node_modules" ]   }

git error with permission denied 403

 Run into this issue and then all I have to do is goto Windows Credential Manager and remove the default user for my git repository check in.   Permission to mitzenjeremywoo/webpack-product.git denied to mitzen. fatal: unable to access 'https://github.com/mitzenjeremywoo/webpack-product.git/': The requested URL returned error: 403

Bicep - use and learn

 You can find some good resources here about bicep. https://learn.microsoft.com/en-us/shows/learn-live/iac-and-bicep/

k8s - liveness probe failure threshold

While troubleshooting production deployment, was ask how many times does k8s hit pod before it gives up. So k8s has a failureThreshold set to 3. So, if a request to probe health 4th times then it will get timeout and deployment fails.  For an pod that is already running but then fail liveness problem, then it falls back to the configure RestartPolicy. As documented here. https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#probe-v1-core

tls host certificate with no subject

Image
  Using openssl to hit a host with certificate that has no subject name will display certificate has expired. For example,  openssl s_client -showcerts -connect no-subject.badssl.com:443 As you can see here, the subject is missing. So you need to scroll down the certificate chain to determine actual issue.

tls - verify error:num=21:unable to verify the first certificate - validating tls certificate for a target host

Image
This command would do    openssl s_client -showcerts -connect incomplete-chain.badssl.com:443 Then you will be able to see there's some issue with the certificate chain Then you get error like:  verify error:num=20:unable to get local issuer certificate verify error:num=21:unable to verify the first certificate --------------------- Sometimes when trying to debug the issue, you need to hit the exact endpoint to get the error, for example if you're using curl  curl -k https://www.myhost.com/api/v1/healthz vs  curl -k https://www.myhost.com The error might come out for endpoint /api/v1/healthz and not the root host.  Rip this command from Stackoverflow and really useful echo "" | openssl s_client -connect www.google.com:443 -prexit 2>/dev/null | sed -n -e '/BEGIN\ CERTIFICATE/,/END\ CERTIFICATE/ p' And i get a chain of certificates as shown below To validate this certificate, goto https://www.geocerts.com/certificate-decoder and then select "Certificate

sonarcode - devops extension source code

 This is the link to the sonarqube azure devops extension source code. https://github.com/SonarSource/sonar-scanner-vsts/tree/master Also worth noting, I found a repository for training there as well https://github.com/SonarSource/sonar-training-examples

rust debugging with gdb

Image
Started playing and debugging one of my sample app, I install gdb and then if you've created a debug version of your app, the you would be able to use the following command  gdb --tui ./nwt www.google.com Then you will see the following screen and the use gdb command to set break point at main.

rust build with release and non-release

 After doing a release build and looking at the size of my application, the following command was able to go from 80M to 13M - which is quite a significant drop. :)   cargo build --release