Friday, July 16, 2021

Lessons Learnt From Package Consolidation

Things I learnt from frontend consolidation work:

  • Checking for nil in Go using a pointer, sending back only certain key value pairs in proto response from RPC, PR
  • ! makes field mandatory in GraphQL schema
  • @gomodel directive like this
type PackagePriceRange @goModel(model: "github.com/99designs/sdk/go/create.PriceRange")

the PriceRange part in the model string will link up with whatever is defined in backend models, you'll actually be able to find the definition in SDK

  • If query field needs custom resolver which can happen automatically from gqlgen or based on @goField(forceResolver: true) you click through where the error is looking at the return of the resolver definition, you should find a method signature that needs to be implemented in a file like this as a method receiver
  • When digging deep into nested object and checking for truthy
if (packages.packagesByKeys[index].view.priceRange) {}

TypeScript complains, it prefers you to define a variable

const priceRange = packages.packagesByKeys[index].view.priceRange;

and then check for truthy

if (priceRange) {}